clientutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Scheme = runtime.NewScheme()

Functions

func ExtractDeletionSchedule

func ExtractDeletionSchedule(annotations map[string]string) (bool, time.Time, error)

ExtractDeletionSchedule - extracts the deletion schedule from the annotation in time.DateTime format

func FilterClustersBeingDeleted

func FilterClustersBeingDeleted(clusters *greenhousev1alpha1.ClusterList) *greenhousev1alpha1.ClusterList

FilterClustersBeingDeleted - filters out the clusters that are marked for deletion

func FindDirUpwards

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

Searches for a directory upwards starting from the given path.

func GetEnv

func GetEnv(envKey string) (string, error)

GetEnv returns the value of the environment variable or an error if it is not set

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

GetIntEnvWithDefault returns the integer value of the environment variable or the default value.

func GetKubernetesVersion

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

GetKubernetesVersion returns the kubernetes git version using the discovery client.

func GetOwnerReference

func GetOwnerReference(obj metav1.Object, kind string) *metav1.OwnerReference

GetOwnerReference returns the OwnerReference if found else nil.

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 IgnoreIndexerConflict

func IgnoreIndexerConflict(err error) error

IgnoreIndexerConflict returns nil on indexer conflict errors. This is used to ignore errors when the indexer is already set up.

func IsSecretContainsKey

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

IsSecretContainsKey checks whether the given secret contains a key.

func LogIntoContext

func LogIntoContext(ctx context.Context, keysAndValues ...any) 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 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 NewK8sClientFromCluster

func NewK8sClientFromCluster(ctx context.Context, c client.Client, cluster *greenhousev1alpha1.Cluster) (client.Client, error)

NewK8sClientFromCluster returns a client.Client based on the given clusters kubeconfig secret.

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 ParseDateTime

func ParseDateTime(t time.Time) (time.Time, error)

ParseDateTime - parses the time object to time.DateTime format

func PredicateByName

func PredicateByName(name string) predicate.Predicate

func PredicateClusterByAccessMode

func PredicateClusterByAccessMode(accessMode greenhousev1alpha1.ClusterAccessMode) predicate.Predicate

func PredicateClusterIsReady

func PredicateClusterIsReady() predicate.Predicate

func PredicateFilterBySecretTypes

func PredicateFilterBySecretTypes(secretTypes ...corev1.SecretType) predicate.Predicate

PredicateFilterBySecretTypes filters secrets by the given types.

func PredicateOrganizationSCIMStatusChange

func PredicateOrganizationSCIMStatusChange() predicate.Predicate

func PredicatePluginWithStatusReadyChange

func PredicatePluginWithStatusReadyChange() predicate.Predicate

func Ptr

func Ptr[T any](v T) *T

Ptr - is a helper func that allocates a new T value to store v and returns a pointer to it.

func ShouldProceedDeletion

func ShouldProceedDeletion(now, schedule time.Time) (bool, error)

ShouldProceedDeletion - checks if the deletion should be allowed if the schedule has elapsed

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(_ *rest.Config) bool

func (*ClientConfigGetter) IsExplicitFile

func (g *ClientConfigGetter) IsExplicitFile() bool

func (*ClientConfigGetter) Load

type DeletionResult

type DeletionResult string

DeletionResult is the action result of a Delete call

const (
	// DeletionResultDeleted means that the resource has been deleted
	DeletionResultDeleted DeletionResult = "deleted"
	// DeletionResultNotFound means that the resource was not found
	DeletionResultNotFound DeletionResult = "not found"
	// DeletionResultNone means that the resource has not been changed
	DeletionResultNone DeletionResult = "unchanged"
)

func Delete

Delete deletes the object if it exists, otherwise it does nothing. Returns the result and an error.

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