kube

package
v1.226.0-test.7 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildClusterConfig

func BuildClusterConfig(info *ClusterInfo, alias string) *clientcmdapi.Config

BuildClusterConfig creates a kubeconfig api.Config for a single cluster. The exec-plugin command line (ExecArgs/ExecEnv) is supplied by the caller, which keeps this package cloud-agnostic.

func DefaultKubeconfigPath

func DefaultKubeconfigPath() (string, error)

DefaultKubeconfigPath returns the XDG-compliant default kubeconfig path. Returns ~/.config/atmos/kube/config.

Types

type ClusterInfo

type ClusterInfo struct {
	// Name is the cluster's short name.
	Name string

	// Endpoint is the cluster's API server URL.
	Endpoint string

	// CertificateAuthorityData is the base64-encoded CA certificate, as
	// returned by the cloud API. Decoded the same way for every cloud.
	CertificateAuthorityData string

	// ID uniquely identifies the cluster and is used as the kubeconfig
	// cluster map key and default context name: the ARN for EKS, the ARM
	// resource ID for AKS.
	ID string

	// Region disambiguates the generated exec-plugin username when the same
	// cluster name exists in more than one place: the AWS region for EKS,
	// the resource group for AKS.
	Region string

	// UserPrefix distinguishes the exec-plugin username by cloud, e.g. "eks"
	// or "aks", reproducing the existing "atmos-eks-<name>-<region>" scheme.
	UserPrefix string

	// AccountID further disambiguates the exec-plugin username for clouds
	// where Name+Region is not guaranteed unique: Azure resource groups are
	// scoped per-subscription, so the same cluster name and resource group
	// can exist in two subscriptions. Leave empty to keep the existing
	// "atmos-eks-<name>-<region>" AWS/EKS username format unchanged.
	AccountID string

	// ExecArgs are the fully-built kubectl exec-credential-plugin arguments,
	// e.g. [aws, eks, token, --cluster-name, X, --region, Y] or
	// [azure, aks, token, --cluster-name, X, --resource-group, Y]. Built by
	// the caller so this package stays cloud-agnostic.
	ExecArgs []string

	// ExecEnv are additional environment variables for the exec plugin, e.g.
	// ATMOS_IDENTITY.
	ExecEnv []clientcmdapi.ExecEnvVar
}

ClusterInfo is the cloud-agnostic cluster data needed to write a kubeconfig entry. Each cloud package (aws, azure) builds one of these from its own describe-cluster call before handing it to KubeconfigManager.

type KubeconfigManager

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

KubeconfigManager manages kubeconfig files for Kubernetes clusters (EKS, AKS).

func NewKubeconfigManager

func NewKubeconfigManager(customPath, modeStr string) (*KubeconfigManager, error)

NewKubeconfigManager creates a manager with the given path and permissions. If customPath is empty, uses XDG default (~/.config/atmos/kube/config). If modeStr is empty, defaults to "0600".

func (*KubeconfigManager) GetPath

func (m *KubeconfigManager) GetPath() string

GetPath returns the kubeconfig file path.

func (*KubeconfigManager) ListClusterIDs

func (m *KubeconfigManager) ListClusterIDs() ([]string, error)

ListClusterIDs returns all cluster ARN keys from the kubeconfig file. Returns nil if the file does not exist.

func (*KubeconfigManager) RemoveClusterConfig

func (m *KubeconfigManager) RemoveClusterConfig(clusterARN, contextName, userName string) error

RemoveClusterConfig removes a cluster, context, and user from the kubeconfig. Idempotent: returns nil if entries do not exist.

func (*KubeconfigManager) WriteClusterConfig

func (m *KubeconfigManager) WriteClusterConfig(info *ClusterInfo, alias, updateMode string) (bool, error)

WriteClusterConfig generates and writes kubeconfig for a cluster. Returns changed=true when the on-disk file was modified, and changed=false when the existing kubeconfig already matches the desired state (no write performed). Callers can use this to suppress noisy success messages on repeated invocations that produce identical output.

Jump to

Keyboard shortcuts

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