kubeconfig

package
v0.22.10 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// SecretType is used to indicate which kubernetes secrets contain a KubeConfig.
	SecretType = "solo.io/kubeconfig"

	// Key is the KubeConfig's key in the KubeConfig secret data.
	Key = "kubeconfig"
)

Variables

View Source
var (
	FailedToConvertKubeConfigToSecret = func(err error) error {
		return eris.Wrap(err, "Could not serialize KubeConfig to yaml while generating secret.")
	}
	FailedToConvertSecretToKubeConfig = func(err error) error {
		return eris.Wrapf(err, "Could not deserialize string to KubeConfig while generating KubeConfig")
	}
	FailedToConvertSecretToClientConfig = func(err error) error {
		return eris.Wrap(err, "Could not convert config to ClientConfig")
	}
	SecretHasNoKubeConfig = func(meta metav1.ObjectMeta) error {
		return eris.Errorf("kube config secret %s.%s has no KubeConfig value for key %v",
			meta.Namespace, meta.Name, Key)
	}
	FailedToConvertSecretToRestConfig = func(err error) error {
		return eris.Wrap(err, "Could not convert config to *rest.Config")
	}
)
View Source
var (
	FailedToReadCAFile = func(err error, fileName string) error {
		return eris.Wrapf(err, "Failed to read kubeconfig CA file: %s", fileName)
	}
)
View Source
var Predicate = predicate.Funcs{
	CreateFunc: func(e event.CreateEvent) bool {
		return isKubeConfigSecret(e.Object)
	},
	DeleteFunc: func(e event.DeleteEvent) bool {
		return isKubeConfigSecret(e.Object)
	},
	UpdateFunc: func(e event.UpdateEvent) bool {
		if isKubeConfigSecret(e.ObjectNew) {

			oldSecret, newSecret := e.ObjectOld.(*corev1.Secret), e.ObjectNew.(*corev1.Secret)
			return !reflect.DeepEqual(oldSecret.Data, newSecret.Data)
		}
		return false
	},
	GenericFunc: func(e event.GenericEvent) bool {
		return isKubeConfigSecret(e.Object)
	},
}

Functions

func BuildRemoteCfg

func BuildRemoteCfg(
	remoteCluster *api.Cluster,
	remoteCtx *api.Context,
	clusterName, token string,
) api.Config

func GetClientConfigWithContext added in v0.7.17

func GetClientConfigWithContext(kubeConfigPath, kubeContext, apiServerUrl string) (clientcmd.ClientConfig, error)

Fetch ClientConfig. If kubeConfigPath is not specified, retrieve the kubeconfig from environment in which this is invoked. Override the API Server URL and current context if specified.

func GetRawConfigWithContext added in v0.7.17

func GetRawConfigWithContext(kubeConfigPath, kubeContext, apiServerUrl string) (clientcmdapi.Config, error)

Fetch raw Config for environment in which this is invoked, override the API Server URL and current context if specified.

func GetRestConfigWithContext added in v0.7.17

func GetRestConfigWithContext(kubeConfigPath, kubeContext, apiServerUrl string) (*rest.Config, error)

Fetch rest.Config for environment in which this is invoked, override the API Server URL and current context if specified.

func SecretObjMeta added in v0.7.17

func SecretObjMeta(namespace string, cluster string, resourceLabels map[string]string) metav1.ObjectMeta

func SecretToConfig

func SecretToConfig(secret *kubev1.Secret) (clusterName string, config clientcmd.ClientConfig, err error)

SecretToConfig extracts the cluster name and *Config from a KubeConfig secret. If the provided secret is not a KubeConfig secret, an error is returned.

func ToSecret

func ToSecret(namespace string, cluster string, resourceLabels map[string]string, kc api.Config) (*kubev1.Secret, error)

ToSecret converts a kubernetes api.Config to a secret with the provided name and namespace.

Types

type KubeLoader

type KubeLoader interface {
	GetRestConfigForContext(path string, context string) (*rest.Config, error)
	GetRawConfigForContext(path, context string) (clientcmdapi.Config, error)
	GetClientConfigForContext(path, context string) (clientcmd.ClientConfig, error)
	GetRestConfigFromBytes(config []byte) (*rest.Config, error)
}

Directories

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

Jump to

Keyboard shortcuts

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