kubernetes

package
v1.53.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0, BSD-2-Clause, MIT, + 1 more Imports: 45 Imported by: 192

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CertificatesV1beta1UsagesToCertificatesV1Usages added in v1.32.0

func CertificatesV1beta1UsagesToCertificatesV1Usages(usages []certificatesv1beta1.KeyUsage) []certificatesv1.KeyUsage

CertificatesV1beta1UsagesToCertificatesV1Usages converts []certificatesv1beta1.KeyUsage to []certificatesv1.KeyUsage.

func CurrentReplicaCountForDeployment added in v1.21.0

func CurrentReplicaCountForDeployment(ctx context.Context, client client.Client, namespace, deploymentName string) (int32, error)

CurrentReplicaCountForDeployment returns the current replicaCount for the given deployment.

func DNSNamesForService added in v1.8.0

func DNSNamesForService(name, namespace string) []string

DNSNamesForService returns the possible DNS names for a service with the given name and namespace.

func DeleteObject added in v1.11.0

func DeleteObject(ctx context.Context, c client.Writer, object client.Object) error

DeleteObject deletes a Kubernetes object. It ignores 'not found' and 'no match' errors.

func DeleteObjects added in v1.11.0

func DeleteObjects(ctx context.Context, c client.Writer, objects ...client.Object) error

DeleteObjects deletes a list of Kubernetes objects.

func DeleteObjectsFromListConditionally added in v1.17.0

func DeleteObjectsFromListConditionally(ctx context.Context, c client.Client, listObj client.ObjectList, predicateFn func(runtime.Object) bool) error

DeleteObjectsFromListConditionally takes a Kubernetes List object. It iterates over its items and, if provided, executes the predicate function. If it evaluates to true then the object will be deleted.

func DeleteSecretByReference added in v1.17.0

func DeleteSecretByReference(ctx context.Context, c client.Client, ref *corev1.SecretReference) error

DeleteSecretByReference deletes the secret referenced by the given secret reference.

func FeatureGatesToCommandLineParameter added in v1.10.0

func FeatureGatesToCommandLineParameter(fg map[string]bool) string

FeatureGatesToCommandLineParameter transforms feature gates given as string/bool map to a command line parameter that is understood by Kubernetes components.

func FetchEventMessages added in v1.17.0

func FetchEventMessages(ctx context.Context, scheme *runtime.Scheme, reader client.Reader, obj client.Object, eventType string, eventsLimit int) (string, error)

FetchEventMessages gets events for the given object of the given `eventType` and returns them as a formatted output. The function expects that the given `obj` is specified with a proper `metav1.TypeMeta`.

func GetAdmissionPluginsForVersion added in v1.25.0

func GetAdmissionPluginsForVersion(v string) []gardencorev1beta1.AdmissionPlugin

GetAdmissionPluginsForVersion returns the set of default admission plugins for the given Kubernetes version. If the given Kubernetes version does not explicitly define admission plugins the set of names for the next available version will be returned (e.g., for version X not defined the set of version X-1 will be returned).

func GetContainerResourcesInStatefulSet added in v1.21.0

func GetContainerResourcesInStatefulSet(ctx context.Context, k8sClient client.Client, key client.ObjectKey) (map[string]*corev1.ResourceRequirements, error)

GetContainerResourcesInStatefulSet returns the containers resources in StatefulSet.

func GetLoadBalancerIngress

func GetLoadBalancerIngress(ctx context.Context, c client.Client, service *corev1.Service) (string, error)

GetLoadBalancerIngress takes a context, a client, a service object. It gets the `service` and queries for a load balancer's technical name (ip address or hostname). It returns the value of the technical name whereby it always prefers the hostname (if given) over the IP address. The passed `service` instance is updated with the information received from the API server.

func GetManagedSeedByName added in v1.34.0

func GetManagedSeedByName(ctx context.Context, client client.Client, name string) (*seedmanagementv1alpha1.ManagedSeed, error)

GetManagedSeedByName tries to reads a ManagedSeed in the garden namespace. If it's not found then `nil` is returned.

func GetManagedSeedWithReader added in v1.31.0

func GetManagedSeedWithReader(ctx context.Context, r client.Reader, shootNamespace, shootName string) (*seedmanagementv1alpha1.ManagedSeed, error)

GetManagedSeedWithReader gets the ManagedSeed resource for the given shoot namespace and name, by searching for all ManagedSeeds in the shoot namespace that have spec.shoot.name set to the shoot name. If no such ManagedSeeds are found, nil is returned.

func GetSecretByReference added in v1.17.0

func GetSecretByReference(ctx context.Context, c client.Reader, ref *corev1.SecretReference) (*corev1.Secret, error)

GetSecretByReference returns the secret referenced by the given secret reference.

func HasMetaDataAnnotation

func HasMetaDataAnnotation(meta metav1.Object, key, value string) bool

HasMetaDataAnnotation checks if the passed meta object has the given key, value set in the annotations section.

func IgnoreAlreadyExists added in v1.21.0

func IgnoreAlreadyExists(err error) error

IgnoreAlreadyExists returns nil on AlreadyExists errors. All other values that are not AlreadyExists errors or nil are returned unmodified.

func IsNamespaceInUse added in v1.22.0

func IsNamespaceInUse(ctx context.Context, reader client.Reader, namespace string, gvk schema.GroupVersionKind) (bool, error)

IsNamespaceInUse checks if there are is at least one object of the given kind left inside the given namespace.

func Key

func Key(namespaceOrName string, nameOpt ...string) client.ObjectKey

Key creates a new client.ObjectKey from the given parameters. There are only two ways to call this function:

  • If only namespaceOrName is set, then a client.ObjectKey with name set to namespaceOrName is returned.
  • If namespaceOrName and one nameOpt is given, then a client.ObjectKey with namespace set to namespaceOrName and name set to nameOpt[0] is returned.

For all other cases, this method panics.

func LookupObject added in v1.7.0

func LookupObject(ctx context.Context, c client.Client, apiReader client.Reader, key client.ObjectKey, obj client.Object) error

LookupObject retrieves an obj for the given object key dealing with potential stale cache that still does not contain the obj. It first tries to retrieve the obj using the given cached client. If the object key is not found, then it does live lookup from the API server using the given apiReader.

func MakeUnique added in v1.31.0

func MakeUnique(obj runtime.Object) error

MakeUnique takes either a *corev1.ConfigMap or a *corev1.Secret object and makes it immutable, i.e., it sets .immutable=true, computes a checksum based on .data, and appends the first 8 characters of the computed checksum to the name of the object. Additionally, it injects the `resources.gardener.cloud/garbage-collectable-reference=true` label.

func MapStringBoolToCommandLineParameter added in v1.33.0

func MapStringBoolToCommandLineParameter(m map[string]bool, param string) string

MapStringBoolToCommandLineParameter transforms a string/bool map to a command line parameter that is understood by Kubernetes components.

func MergeOwnerReferences added in v1.16.0

func MergeOwnerReferences(references []metav1.OwnerReference, newReferences ...metav1.OwnerReference) []metav1.OwnerReference

MergeOwnerReferences merges the newReferences with the list of existing references.

func MostRecentCompleteLogs added in v1.16.0

func MostRecentCompleteLogs(
	ctx context.Context,
	podInterface corev1client.PodInterface,
	pod *corev1.Pod,
	containerName string,
	tailLines,
	headBytes *int64,
) (
	string,
	error,
)

MostRecentCompleteLogs returns the logs of the pod/container in case it is not running. If the pod/container is running then the logs of the previous pod/container are being returned.

func NewKubeconfig added in v1.36.0

func NewKubeconfig(contextName string, cluster clientcmdv1.Cluster, authInfo clientcmdv1.AuthInfo) *clientcmdv1.Config

NewKubeconfig returns a new kubeconfig structure.

func NewestObject added in v1.16.0

func NewestObject(ctx context.Context, c client.Reader, listObj client.ObjectList, filterFn func(client.Object) bool, listOpts ...client.ListOption) (client.Object, error)

NewestObject returns the most recently created object based on the provided list object type. If a filter function is provided then it will be applied for each object right after listing all objects. If no object remains then nil is returned. The Items field in the list object will be populated with the result returned from the server after applying the filter function (if provided).

func NewestPodForDeployment added in v1.16.0

func NewestPodForDeployment(ctx context.Context, c client.Reader, deployment *appsv1.Deployment) (*corev1.Pod, error)

NewestPodForDeployment returns the most recently created Pod object for the given deployment.

func ObjectKeyForCreateWebhooks added in v1.40.3

func ObjectKeyForCreateWebhooks(obj client.Object) client.ObjectKey

ObjectKeyForCreateWebhooks creates an object key for an object handled by webhooks registered for CREATE verbs.

func ObjectKeyFromSecretRef added in v1.51.0

func ObjectKeyFromSecretRef(ref corev1.SecretReference) client.ObjectKey

ObjectKeyFromSecretRef returns an ObjectKey for the given SecretReference.

func ObjectMeta

func ObjectMeta(namespaceOrName string, nameOpt ...string) metav1.ObjectMeta

ObjectMeta creates a new metav1.ObjectMeta from the given parameters. There are only two ways to call this function:

  • If only namespaceOrName is set, then a metav1.ObjectMeta with name set to namespaceOrName is returned.
  • If namespaceOrName and one nameOpt is given, then a metav1.ObjectMeta with namespace set to namespaceOrName and name set to nameOpt[0] is returned.

For all other cases, this method panics.

func ObjectMetaFromKey

func ObjectMetaFromKey(key client.ObjectKey) metav1.ObjectMeta

ObjectMetaFromKey returns an ObjectMeta with the namespace and name set to the values from the key.

func ObjectName added in v1.8.0

func ObjectName(obj client.Object) string

ObjectName returns the name of the given object in the format <namespace>/<name>

func OwnedBy added in v1.16.0

func OwnedBy(obj client.Object, apiVersion, kind, name string, uid types.UID) bool

OwnedBy checks if the given object's owner reference contains an entry with the provided attributes.

func ParseObjectName added in v1.36.0

func ParseObjectName(objectName string) (string, string)

ParseObjectName parses the given object name (in the format <namespace>/<name>) to its constituent namespace and name. If the given object name is not namespaced, an empty namespace is returned.

func ReadLeaderElectionRecord added in v1.15.0

func ReadLeaderElectionRecord(ctx context.Context, client client.Client, lock, namespace, name string) (*resourcelock.LeaderElectionRecord, error)

ReadLeaderElectionRecord returns the leader election record for a given lock type and a namespace/name combination.

func ReconcileServicePorts added in v1.10.0

func ReconcileServicePorts(existingPorts []corev1.ServicePort, desiredPorts []corev1.ServicePort, desiredServiceType corev1.ServiceType) []corev1.ServicePort

ReconcileServicePorts reconciles the existing service ports with the desired ports. This means that it takes the existing port (identified by name), and applies the settings from the desired port to it. This way it can keep fields that are defaulted by controllers, e.g. the node port. However, it does not keep ports that are not part of the desired list.

func SetAnnotationAndUpdate added in v1.21.0

func SetAnnotationAndUpdate(ctx context.Context, c client.Client, obj client.Object, key, value string) error

SetAnnotationAndUpdate sets the annotation on the given object and updates it.

func SetMetaDataAnnotation

func SetMetaDataAnnotation(meta metav1.Object, key, value string)

SetMetaDataAnnotation sets the annotation on the given object. If the given Object did not yet have annotations, they are initialized.

func SetMetaDataLabel

func SetMetaDataLabel(meta metav1.Object, key, value string)

SetMetaDataLabel sets the key value pair in the labels section of the given Object. If the given Object did not yet have labels, they are initialized.

func TLSCipherSuites added in v1.31.0

func TLSCipherSuites(k8sVersion *semver.Version) []string

TLSCipherSuites returns the wanted and acceptable cipher suits depending on the passed Kubernetes version.

func TruncateLabelValue

func TruncateLabelValue(s string) string

TruncateLabelValue truncates a string at 63 characters so it's suitable for a label value.

func ValidDeploymentContainerImageVersion

func ValidDeploymentContainerImageVersion(deploymentToCheck *appsv1.Deployment, containerName, minimumVersion string) (bool, error)

ValidDeploymentContainerImageVersion validates compliance of a deployment container image to a minimum version

func WaitUntilLoadBalancerIsReady added in v1.15.0

func WaitUntilLoadBalancerIsReady(
	ctx context.Context,
	log logr.Logger,
	c client.Client,
	namespace, name string,
	timeout time.Duration,
) (
	string,
	error,
)

WaitUntilLoadBalancerIsReady waits until the given external load balancer has been created (i.e., its ingress information has been updated in the service status).

func WaitUntilResourceDeleted

func WaitUntilResourceDeleted(ctx context.Context, c client.Client, obj client.Object, interval time.Duration) error

WaitUntilResourceDeleted deletes the given resource and then waits until it has been deleted. It respects the given interval and timeout.

func WaitUntilResourceDeletedWithDefaults

func WaitUntilResourceDeletedWithDefaults(ctx context.Context, c client.Client, obj client.Object) error

WaitUntilResourceDeletedWithDefaults deletes the given resource and then waits until it has been deleted. It uses a default interval and timeout

func WaitUntilResourcesDeleted added in v1.1.0

func WaitUntilResourcesDeleted(ctx context.Context, c client.Client, list client.ObjectList, interval time.Duration, opts ...client.ListOption) error

WaitUntilResourcesDeleted waits until the given resources are gone. It respects the given interval and timeout.

Types

type ControlledResourceEventHandler added in v1.21.0

type ControlledResourceEventHandler struct {
	// ControllerTypes is a list of controller types. If multiple controller types are specified,
	// there is a chain of controllers. Only the top-most controller (with the last listed type) is eventually enqueued.
	ControllerTypes []ControllerType
	// Ctx is the context used to get controller objects.
	Ctx context.Context
	// Reader is the reader used to get controller objects.
	Reader client.Reader
	// ControllerPredicateFactory is used to create a predicate to check if an object event is of interest to a controller,
	// before enqueueing it. If nil, the controller is always enqueued.
	ControllerPredicateFactory ControllerPredicateFactory
	// Enqueuer is used to enqueue the controller.
	Enqueuer Enqueuer
	// Scheme is used to resolve types to their GroupKinds.
	Scheme *runtime.Scheme
	// Logger is used to log messages.
	Logger logr.Logger
}

ControlledResourceEventHandler is an implementation of cache.ResourceEventHandler that enqueues controllers upon controlled resource events, if a predicate check is successful.

func (*ControlledResourceEventHandler) OnAdd added in v1.21.0

func (h *ControlledResourceEventHandler) OnAdd(o interface{})

OnAdd is called when an object is added.

func (*ControlledResourceEventHandler) OnDelete added in v1.21.0

func (h *ControlledResourceEventHandler) OnDelete(o interface{})

OnDelete is called when an object is deleted. It will get the final state of the item if it is known, otherwise it will get an object of type DeletedFinalStateUnknown.

func (*ControlledResourceEventHandler) OnUpdate added in v1.21.0

func (h *ControlledResourceEventHandler) OnUpdate(old, new interface{})

OnUpdate is called when an object is modified.

type ControllerPredicateFactory added in v1.21.0

type ControllerPredicateFactory interface {
	// NewControllerPredicate creates and returns a new Predicate with the given controller.
	NewControllerPredicate(client.Object) predicate.Predicate
}

ControllerPredicateFactory provides a method for creating new Predicates for a controller.

type ControllerPredicateFactoryFunc added in v1.21.0

type ControllerPredicateFactoryFunc func(client.Object, client.Object, client.Object, bool) bool

ControllerPredicateFactoryFunc is a function that implements ControllerPredicateFactory.

func (ControllerPredicateFactoryFunc) NewControllerPredicate added in v1.21.0

func (f ControllerPredicateFactoryFunc) NewControllerPredicate(controller client.Object) predicate.Predicate

NewControllerPredicate creates and returns a new Predicate with the given controller.

type ControllerType added in v1.21.0

type ControllerType struct {
	// Type is the controller type. It is used to check the controller group and kind and get objects of the specified type.
	Type client.Object
	// Namespace is an optional namespace to look for controllers. If nil, the namespace of the controlled object is used.
	Namespace *string
	// NameFunc is an optional function that returns the controller name from the given object.
	// It is only used if the object doesn't have a controller ref.
	NameFunc func(obj client.Object) string
	// contains filtered or unexported fields
}

ControllerType contains information about a controller type.

type DaemonSetLister

type DaemonSetLister interface {
	// List lists all DaemonSets that match the given selector.
	List(selector labels.Selector) ([]*appsv1.DaemonSet, error)
	// DaemonSets yields a DaemonSetNamespaceLister for the given namespace.
	DaemonSets(namespace string) DaemonSetNamespaceLister
}

DaemonSetLister is a lister of DaemonSets.

func NewDaemonSetLister

func NewDaemonSetLister(source DaemonSetSource) DaemonSetLister

NewDaemonSetLister creates a new DaemonSetLister from the given DaemonSetSource.

type DaemonSetNamespaceLister

type DaemonSetNamespaceLister interface {
	// List lists all DaemonSets that match the given selector in the current namespace.
	List(selector labels.Selector) ([]*appsv1.DaemonSet, error)
	// Get retrieves the DaemonSet with the given name in the current namespace.
	Get(name string) (*appsv1.DaemonSet, error)
}

DaemonSetNamespaceLister is a lister of deployments for a specific namespace.

type DaemonSetSource

type DaemonSetSource func() ([]*appsv1.DaemonSet, error)

DaemonSetSource is a function that produces a slice of DaemonSets or an error.

type DeploymentLister

type DeploymentLister interface {
	// List lists all Deployments that match the given selector.
	List(selector labels.Selector) ([]*appsv1.Deployment, error)
	// Deployments yields a DeploymentNamespaceLister for the given namespace.
	Deployments(namespace string) DeploymentNamespaceLister
}

DeploymentLister is a lister of Deployments.

func NewDeploymentLister

func NewDeploymentLister(source DeploymentSource) DeploymentLister

NewDeploymentLister creates a new DeploymentLister from the given DeploymentSource.

type DeploymentNamespaceLister

type DeploymentNamespaceLister interface {
	// List lists all Deployments that match the given selector in the current namespace.
	List(selector labels.Selector) ([]*appsv1.Deployment, error)
	// Get retrieves the Deployment with the given name in the current namespace.
	Get(name string) (*appsv1.Deployment, error)
}

DeploymentNamespaceLister is a lister of deployments for a specific namespace.

type DeploymentSource

type DeploymentSource func() ([]*appsv1.Deployment, error)

DeploymentSource is a function that produces a slice of Deployments or an error.

type Enqueuer added in v1.21.0

type Enqueuer interface {
	// Enqueue enqueues the object for processing.
	Enqueue(client.Object)
}

Enqueuer provides a method for enqueuing an object for processing.

type EnqueuerFunc added in v1.21.0

type EnqueuerFunc func(client.Object)

EnqueuerFunc is a function that implements Enqueuer.

func (EnqueuerFunc) Enqueue added in v1.21.0

func (f EnqueuerFunc) Enqueue(obj client.Object)

Enqueue enqueues the object for processing.

type EtcdLister added in v1.2.0

type EtcdLister interface {
	// List lists all Etcds that match the given selector.
	List(selector labels.Selector) ([]*druidv1alpha1.Etcd, error)
	// Etcds yields a EtcdNamespaceLister for the given namespace.
	Etcds(namespace string) EtcdNamespaceLister
}

EtcdLister is a lister of Etcds.

func NewEtcdLister added in v1.2.0

func NewEtcdLister(source EtcdSource) EtcdLister

NewEtcdLister creates a new EtcdLister from the given EtcdSource.

type EtcdNamespaceLister added in v1.2.0

type EtcdNamespaceLister interface {
	// List lists all Etcds that match the given selector in the current namespace.
	List(selector labels.Selector) ([]*druidv1alpha1.Etcd, error)
	// Get retrieves the Etcd with the given name in the current namespace.
	Get(name string) (*druidv1alpha1.Etcd, error)
}

EtcdNamespaceLister is a lister of etcds for a specific namespace.

type EtcdSource added in v1.2.0

type EtcdSource func() ([]*druidv1alpha1.Etcd, error)

EtcdSource is a function that produces a slice of Etcds or an error.

type SortBy added in v1.15.2

type SortBy func(o1, o2 client.Object) bool

SortBy the type of a "less" function that defines the ordering of its object arguments.

func ByCreationTimestamp added in v1.15.2

func ByCreationTimestamp() SortBy

ByCreationTimestamp returns a comparison function for sorting by creation timestamp.

func ByName added in v1.15.2

func ByName() SortBy

ByName returns a comparison function for sorting by name.

func (SortBy) Sort added in v1.15.2

func (sortBy SortBy) Sort(objList runtime.Object)

Sort sorts the items in the provided list objects according to the sort-by function.

type StatefulSetLister

type StatefulSetLister interface {
	// List lists all StatefulSets that match the given selector.
	List(selector labels.Selector) ([]*appsv1.StatefulSet, error)
	// StatefulSets yields a StatefulSetNamespaceLister for the given namespace.
	StatefulSets(namespace string) StatefulSetNamespaceLister
}

StatefulSetLister is a lister of StatefulSets.

func NewStatefulSetLister

func NewStatefulSetLister(source StatefulSetSource) StatefulSetLister

NewStatefulSetLister creates a new StatefulSetLister form the given StatefulSetSource.

type StatefulSetNamespaceLister

type StatefulSetNamespaceLister interface {
	// List lists all StatefulSets that match the given selector in the current namespace.
	List(selector labels.Selector) ([]*appsv1.StatefulSet, error)
	// Get retrieves the StatefulSet with the given name in the current namespace.
	Get(name string) (*appsv1.StatefulSet, error)
}

StatefulSetNamespaceLister is a lister of StatefulSets for a specific namespace.

type StatefulSetSource

type StatefulSetSource func() ([]*appsv1.StatefulSet, error)

StatefulSetSource is a function that produces a slice of StatefulSets or an error.

type WorkerLister added in v0.34.0

type WorkerLister interface {
	// List lists all Workers that match the given selector in the current namespace.
	List(selector labels.Selector) ([]*extensionsv1alpha1.Worker, error)
	// Workers yields a WorkerNamespaceLister for the given namespace.
	Workers(namespace string) WorkerNamespaceLister
}

WorkerLister is a lister of Workers for a specific namespace.

func NewWorkerLister added in v0.34.0

func NewWorkerLister(source WorkerSource) WorkerLister

NewWorkerLister creates a new WorkerLister from the given WorkerSource.

type WorkerNamespaceLister added in v0.34.0

type WorkerNamespaceLister interface {
	// List lists all Workers that match the given selector in the current namespace.
	List(selector labels.Selector) ([]*extensionsv1alpha1.Worker, error)
	// Get retrieves the MachineDeployment with the given name in the current namespace.
	Get(name string) (*extensionsv1alpha1.Worker, error)
}

WorkerNamespaceLister is a lister of Workers for a specific namespace.

type WorkerSource added in v0.34.0

type WorkerSource func() ([]*extensionsv1alpha1.Worker, error)

WorkerSource is a function that produces a slice of Workers or an error.

Directories

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

Jump to

Keyboard shortcuts

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