clientutil

package
v0.0.0-...-e2048a1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SocketWritePermissions = 0o666
)

Variables

View Source
var PredicatePluginWithHelmSpec = func() predicate.Funcs {
	return predicate.NewPredicateFuncs(func(o client.Object) bool {
		if pluginDefinition, ok := o.(*greenhousev1alpha1.PluginDefinition); ok {
			return pluginDefinition.Spec.HelmChart != nil
		}
		return false
	})
}

PredicatePluginWithHelmSpec filters PluginDefinitions without an HelmChart specification.

View Source
var Scheme = runtime.NewScheme()

Functions

func EnsureFinalizer

func EnsureFinalizer(ctx context.Context, c client.Client, o client.Object, finalizer string) error

EnsureFinalizer ensures a finalizer is present on the object. Returns an error on failure.

func FindDirUpwards

func FindDirUpwards(path, dirName string, maxSteps int) (string, error)

Searches for a directory upwards starting from the given path.

func GetEnvOrDefault

func GetEnvOrDefault(envKey, defaultValue string) string

GetEnvOrDefault returns the value of the environment variable or the default value.

func GetIntEnvWithDefault

func GetIntEnvWithDefault(envKey string, def int) int

func GetKubernetesVersion

func GetKubernetesVersion(restClientGetter genericclioptions.RESTClientGetter) (*version.Info, error)

GetKubernetesVersion returns the kubernetes git version using the discovery client.

func GetSecretKeyFromSecretKeyReference

func GetSecretKeyFromSecretKeyReference(ctx context.Context, c client.Client, namespace string, secretReference greenhousev1alpha1.SecretKeyReference) (string, error)

GetSecretKeyFromSecretKeyReference returns the value of the secret identified by SecretKeyReference or an error.

func IgnoreAlreadyExists

func IgnoreAlreadyExists(err error) error

IgnoreAlreadyExists returns nil on IsAlreadyExists errors.

func IsSecretContainsKey

func IsSecretContainsKey(s *corev1.Secret, key string) bool

IsSecretContainsKey checks whether the given secret contains a key.

func LabelSelectorPredicate

func LabelSelectorPredicate(s metav1.LabelSelector) predicate.Predicate

LabelSelectorPredicate constructs a Predicate from a LabelSelector. Only objects matching the LabelSelector will be admitted. Credit https://github.com/kubernetes-sigs/controller-runtime/blob/v0.10.1/pkg/predicate/predicate.go#L323-L333.

func LogIntoContext

func LogIntoContext(ctx context.Context, keysAndValues ...interface{}) context.Context

func LogIntoContextFromRequest

func LogIntoContextFromRequest(ctx context.Context, req ctrl.Request) context.Context

func NewClientConfigLoaderFromBytes

func NewClientConfigLoaderFromBytes(kubeConfig []byte) clientcmd.ClientConfigLoader

func NewClientConfigLoaderFromSecret

func NewClientConfigLoaderFromSecret(kubeConfig *corev1.Secret) clientcmd.ClientConfigLoader

func NewHeadscaleGRPCClient

func NewHeadscaleGRPCClient(url, apiKey string) (v1.HeadscaleServiceClient, error)

NewHeadscaleGRPCClient returns a new gRPC client for the Headscale API.

func NewHeadscaleGRPCSocketClient

func NewHeadscaleGRPCSocketClient(socketPath string) (v1.HeadscaleServiceClient, error)

func NewHeadscaleK8sClientFromRestClientGetter

func NewHeadscaleK8sClientFromRestClientGetter(restClientGetter genericclioptions.RESTClientGetter, proxy, headscaleAddress string) (client.Client, error)

func NewK8sClient

func NewK8sClient(cfg *rest.Config) (client.Client, error)

NewK8sClient returns a Kubernetes client with registered schemes for the given config or an error.

func NewK8sClientFromRestClientGetter

func NewK8sClientFromRestClientGetter(restClientGetter genericclioptions.RESTClientGetter) (client.Client, error)

NewK8sClientFromRestClientGetter returns a Kubernetes client with registered schemes for the given RESTClientGetter or an error.

func PredicateByName

func PredicateByName(name string) predicate.Predicate

func PredicateClusterByAccessMode

func PredicateClusterByAccessMode(accessMode greenhousev1alpha1.ClusterAccessMode) predicate.Predicate

func PredicateFilterBySecretType

func PredicateFilterBySecretType(secretType corev1.SecretType) predicate.Predicate

PredicateFilterBySecretType filters secrets by the given type.

func PredicateSecretContainsKey

func PredicateSecretContainsKey(key string) predicate.Predicate

PredicateSecretContainsKey filters secrets by the given key.

func RemoveFinalizer

func RemoveFinalizer(ctx context.Context, c client.Client, o client.Object, finalizer string) error

RemoveFinalizer removes a finalizer from an object. Returns an error on failure.

func ValidateSecretForKubeConfig

func ValidateSecretForKubeConfig(secret *corev1.Secret) error

Types

type ClientConfigGetter

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

ClientConfigGetter implements the clientcmd.ClientConfigLoader interface.

func (*ClientConfigGetter) GetDefaultFilename

func (g *ClientConfigGetter) GetDefaultFilename() string

func (*ClientConfigGetter) GetExplicitFile

func (g *ClientConfigGetter) GetExplicitFile() string

func (*ClientConfigGetter) GetLoadingPrecedence

func (g *ClientConfigGetter) GetLoadingPrecedence() []string

func (*ClientConfigGetter) GetStartingConfig

func (g *ClientConfigGetter) GetStartingConfig() (*clientcmdapi.Config, error)

func (*ClientConfigGetter) IsDefaultConfig

func (g *ClientConfigGetter) IsDefaultConfig(config *rest.Config) bool

func (*ClientConfigGetter) IsExplicitFile

func (g *ClientConfigGetter) IsExplicitFile() bool

func (*ClientConfigGetter) Load

type KubeClientOption

type KubeClientOption func(*RestClientGetter)

func WithDiscoveryOpts

func WithDiscoveryOpts(qps float32, burst int) KubeClientOption

WithDiscoveryOpts allows overwriting the discovery QPS and Burst

func WithOverrides

func WithOverrides(overrides clientcmd.ConfigOverrides) KubeClientOption

func WithPersistentConfig

func WithPersistentConfig() KubeClientOption

func WithRuntimeOptions

func WithRuntimeOptions(o RuntimeOptions) KubeClientOption

WithRuntimeOptions allows overwriting client QPS and Burst

type OperationResult

type OperationResult string

OperationResult is the action result of a CreateOrUpdate call

const (
	// OperationResultNone means that the resource has not been changed
	OperationResultNone OperationResult = "unchanged"
	// OperationResultCreated means that a new resource is created
	OperationResultCreated OperationResult = "created"
	// OperationResultUpdated means that an existing resource is updated
	OperationResultUpdated OperationResult = "updated"
)

func CreateOrPatch

func CreateOrPatch(ctx context.Context, c client.Client, obj client.Object, mutate func() error) (OperationResult, error)

CreateOrPatch creates or patches the given object using the mutate function. Returns the result and an error.

func Patch

func Patch(ctx context.Context, c client.Client, obj client.Object, mutate func() error) (OperationResult, error)

Patch uses a PATCH operation on an object. Returns the Result or an error.

func PatchStatus

func PatchStatus(ctx context.Context, c client.Client, obj client.Object, mutate func() error) (OperationResult, error)

PatchStatus uses a PATCH operation on an object status. Returns the Result or an error.

type RestClientGetter

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

Implements the genericclioptions.RESTClientGetter interface and additionally allows to access the KubeConfig from Bytes/Secret.

func NewRestClientGetterForInCluster

func NewRestClientGetterForInCluster(namespace string, opts ...KubeClientOption) (*RestClientGetter, error)

func NewRestClientGetterFromBytes

func NewRestClientGetterFromBytes(config []byte, namespace string, opts ...KubeClientOption) *RestClientGetter

NewRestClientGetterFromBytes returns a RestClientGetter from a []bytes containing a Kube Config.

func NewRestClientGetterFromRestConfig

func NewRestClientGetterFromRestConfig(cfg *rest.Config, namespace string, opts ...KubeClientOption) *RestClientGetter

NewRestClientGetterFromRestConfig returns a RestClientGetter from a in-memory kube config.

func NewRestClientGetterFromSecret

func NewRestClientGetterFromSecret(secret *corev1.Secret, namespace string, opts ...KubeClientOption) (*RestClientGetter, error)

NewRestClientGetterFromSecret returns a RestClientGetter from a secret containing a Kube Config.

func (*RestClientGetter) ToDiscoveryClient

func (cg *RestClientGetter) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

func (*RestClientGetter) ToRESTConfig

func (cg *RestClientGetter) ToRESTConfig() (*rest.Config, error)

func (*RestClientGetter) ToRESTMapper

func (cg *RestClientGetter) ToRESTMapper() (meta.RESTMapper, error)

func (*RestClientGetter) ToRawKubeConfigLoader

func (cg *RestClientGetter) ToRawKubeConfigLoader() clientcmd.ClientConfig

type RuntimeOptions

type RuntimeOptions struct {
	// QPS indicates the maximum QPS to the master from this client. Default is 50.
	QPS float32
	// Maximum burst for throttle. Default is 300.
	Burst int
}

RuntimeOptions contains the runtime options for the Kubernetes client.

func (RuntimeOptions) BindFlags

func (o RuntimeOptions) BindFlags(fs *pflag.FlagSet)

BindFlags will parse the given flagset for runtime option flags and set the runtime options accordingly. Defaults QPS to 50 and Burst to 300 if the flag was not set.

Jump to

Keyboard shortcuts

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