kubeconfig

package
v0.19.10 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const EnvName = "KUBECONFIG"

EnvName is the standard KubeConfig environment variable name. https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#set-the-kubeconfig-environment-variable

View Source
const FromClusterFormat = "%s-eks-a-cluster.kubeconfig"

FromClusterFormat defines the format of the kubeconfig of the.

Variables

This section is empty.

Functions

func FormatWorkloadClusterKubeconfigFilename added in v0.13.0

func FormatWorkloadClusterKubeconfigFilename(clusterName string) string

FormatWorkloadClusterKubeconfigFilename returns a filename for the Kubeconfig of workload clusters. The filename does not include a basepath.

func FromClusterName

func FromClusterName(clusterName string) string

FromClusterName formats an expected Kubeconfig path for EKS-A clusters. This includes a subdirecftory named after the cluster name. For example, if the clusterName is 'sandbox' the generated path would be sandbox/sandbox-eks-a-cluster.kubeconfig.

func FromEnvironment

func FromEnvironment() string

FromEnvironment returns the first kubeconfig file specified in the KUBECONFIG environment variable.

The environment variable can contain a list of files, much like how the PATH environment variable contains a list of directories.

func ResolveAndValidateFilename added in v0.12.0

func ResolveAndValidateFilename(flagValue, clusterName string) (string, error)

ResolveAndValidate composes ResolveFilename and ValidateFile.

Literally, that's all it does. They're frequently called together, so hopefully this is a helper.

func ResolveFilename added in v0.12.0

func ResolveFilename(flagValue, clusterName string) string

ResolveFilename returns a path to a kubeconfig file by priority.

The priority is:

  1. CLI flag (flagValue)
  2. A file created at cluster creation, found by a combining the cluster name with present working directory.
  3. The first filename found in the KUBECONFIG environment variable.

NO VALIDATION IS PERFORMED. See ValidateFile for validation.

There are other places one may wish to consult or load a kubeconfig file from, but this function tries to walk the narrow line between what the kubernetes client code does (#1, #3, and some other things that we more or less don't support), with some of the existing EKSA CLI tools that look for kubeconfig files relative to the working directory that were created at cluster creation time. These different functionalities don't always mesh, and aren't always compatible, but this function tries to combine them as much as possible, without breaking either.

func ValidateFilename added in v0.12.0

func ValidateFilename(filename string) error

ValidateFilename loads a file to validate it's basic contents.

The values of the fields within aren't validated, but the file's existence and basic structure are checked.

func ValidateKubeconfigPath added in v0.12.0

func ValidateKubeconfigPath(clusterName string, parentFolders ...string) error

Types

type ClientFactory added in v0.19.0

type ClientFactory interface {
	// BuildClientFromKubeconfig builds a Kubernetes client from a kubeconfig file.
	BuildClientFromKubeconfig(kubeconfigPath string) (kubernetes.Client, error)
}

ClientFactory builds Kubernetes clients.

type ClusterAPIKubeconfigSecretWriter added in v0.19.0

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

ClusterAPIKubeconfigSecretWriter reads the kubeconfig secret on a cluster and copies the contents to a writer.

func NewClusterAPIKubeconfigSecretWriter added in v0.19.0

func NewClusterAPIKubeconfigSecretWriter(unauthClient ClientFactory, opts ...WriterOpt) ClusterAPIKubeconfigSecretWriter

NewClusterAPIKubeconfigSecretWriter creates a ClusterAPIKubeconfigSecretWriter.

func (ClusterAPIKubeconfigSecretWriter) GetClusterKubeconfig added in v0.19.0

func (kr ClusterAPIKubeconfigSecretWriter) GetClusterKubeconfig(ctx context.Context, clusterName, kubeconfigPath string) ([]byte, error)

GetClusterKubeconfig gets the cluster's kubeconfig from the secret.

func (ClusterAPIKubeconfigSecretWriter) WriteKubeconfig added in v0.19.0

func (kr ClusterAPIKubeconfigSecretWriter) WriteKubeconfig(ctx context.Context, clusterName, kubeconfigPath string, w io.Writer) error

WriteKubeconfig retrieves the contents of the specified cluster's kubeconfig from a secret and copies it to an io.Writer.

func (ClusterAPIKubeconfigSecretWriter) WriteKubeconfigContent added in v0.19.0

func (kr ClusterAPIKubeconfigSecretWriter) WriteKubeconfigContent(ctx context.Context, clusterName string, content []byte, w io.Writer) error

WriteKubeconfigContent copies a raw kubeconfig to an io.Writer.

type Writer added in v0.19.0

type Writer interface {
	WriteKubeconfig(ctx context.Context, clusterName, kubeconfig string, w io.Writer) error
	WriteKubeconfigContent(ctx context.Context, clusterName string, content []byte, w io.Writer) error
}

Writer reads the kubeconfig secret on a cluster and copies the contents to a writer.

type WriterOpt added in v0.19.0

type WriterOpt func(*ClusterAPIKubeconfigSecretWriter)

WriterOpt allows to configure [KubeconfigWriter].

func WithBackoff added in v0.19.0

func WithBackoff(backoff time.Duration) WriterOpt

WithBackoff sets the optional backoff duration for a KubeconfigWriter.

func WithTimeout added in v0.19.0

func WithTimeout(timeout time.Duration) WriterOpt

WithTimeout sets the optional timeout for a KubeconfigWriter.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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