target

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package target resolves and represents the Kubernetes destination used by a Deployah invocation.

A Target owns Kubernetes context, namespace, and kubeconfig resolution. It does not load Deployah specs or platform files and does not construct Helm or Kubernetes clients.

Context precedence

  1. explicit context override (--context)
  2. platform environment context name supplied to Resolver.Resolve
  3. kubeconfig current-context

Target.Context is the effective context name. Target.ContextSource records which rule selected it. When Context is non-empty, Target.ClientConfig and Target.RESTConfig pin that name. Both use the snapshotted kubeconfig loading rules, pin Target.Namespace, and do not select in-cluster configuration.

Namespace precedence

  1. explicit namespace override
  2. namespace of the selected kubeconfig context
  3. "default"

Resolve pins context, source selection, and loading rules against later KUBECONFIG or HOME changes. Kubeconfig file contents stay live until configuration is loaded.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// KubeconfigPath is an explicit kubeconfig file. When set it takes
	// full precedence over extra paths and KUBECONFIG.
	KubeconfigPath string
	// ContextOverride is an explicit context name, typically --context.
	ContextOverride string
	// NamespaceOverride is an explicit namespace, typically --namespace.
	NamespaceOverride string
	// ExtraKubeconfigPaths are prepended to default kubeconfig precedence
	// when KubeconfigPath is empty. Missing files are tolerated.
	ExtraKubeconfigPaths []string
}

Config holds Kubernetes destination inputs for a Resolver. It describes kubeconfig and override selection only.

type ContextSource

type ContextSource uint8

ContextSource identifies which rule selected Target.Context.

const (
	// ContextSourceKubeconfig means the kubeconfig current-context was used.
	ContextSourceKubeconfig ContextSource = iota
	// ContextSourcePlatform means the caller supplied a platform context.
	ContextSourcePlatform
	// ContextSourceExplicit means an explicit context override was set.
	ContextSourceExplicit
)

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver owns immutable destination-resolution configuration.

func NewResolver

func NewResolver(config Config) *Resolver

NewResolver returns a Resolver that copies config so later mutation of ExtraKubeconfigPaths cannot change resolution.

func (*Resolver) Resolve

func (r *Resolver) Resolve(platformContext string) *Target

Resolve returns an immutable Target for platformContext.

platformContext is a Kubernetes context name already chosen by the caller. Resolve does not load Deployah platform or spec files. Kubeconfig read failures do not fail Resolve; Target.RESTConfig reports them when a connection config is required.

type Target

type Target struct {
	// contains filtered or unexported fields
}

Target is an immutable resolved Kubernetes destination.

After Resolver.Resolve, Context, ContextSource, Namespace, and the kubeconfig loading snapshot do not change. Concurrent calls to the getters, Target.ClientConfig, and Target.RESTConfig are safe.

func (*Target) ClientConfig

func (t *Target) ClientConfig() clientcmd.ClientConfig

ClientConfig returns a lazy Kubernetes client configuration for this destination.

The returned value does not read kubeconfig files until RawConfig or ClientConfig is called. Namespace returns the Target namespace without loading. When Context is non-empty, that context is pinned. Namespace is always pinned to Target.Namespace. Loading rules come from the Resolve snapshot. It does not use in-cluster configuration.

func (*Target) Context

func (t *Target) Context() string

Context returns the effective Kubernetes context name. An empty string means no context could be resolved.

func (*Target) ContextSource

func (t *Target) ContextSource() ContextSource

ContextSource returns which rule selected Target.Context.

func (*Target) Namespace

func (t *Target) Namespace() string

Namespace returns the effective namespace. Precedence is explicit override, then the selected kubeconfig context namespace, then "default".

func (*Target) RESTConfig

func (t *Target) RESTConfig() (*rest.Config, error)

RESTConfig returns a kubeconfig-based REST config for this destination.

It uses Target.ClientConfig. When Context is non-empty, the config pins that context. Namespace is pinned to Target.Namespace. Loading rules come from the snapshot taken at Resolve, not from the current process environment. It does not use in-cluster configuration. Load errors from the snapshotted rules are returned; kubeconfig file contents are read at call time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL