Documentation ¶
Index ¶
- Constants
- Variables
- func BuildLabelSelector(requirements ...LabelSelectorRequirement) (labels.Selector, error)
- func ClientConfigFromServiceAccountKey(ctx context.Context, log logr.Logger, k8sClient client.Client, ...) (*clientcmdapi.Config, error)
- func ClientConfigFromServiceAccountSecret(secret *corev1.Secret, kubernetesAddress string) (*clientcmdapi.Config, error)
- func ClientFromKubeconfig(kubeconfig []byte, opts client.Options) (client.Client, error)
- func CreateMetrics(namespace string) *prometheus.HistogramVec
- func CreateOrUpdateContainer(containers []corev1.Container, name string, ...) ([]corev1.Container, error)
- func CreateOrUpdateMonitor(monitors []v1alpha1.Uptrends, name string, ...) ([]v1alpha1.Uptrends, error)
- func DefaultNewClientWithMetrics(cache cache.Cache, config *rest.Config, options client.Options, ...) (client.Client, error)
- func EnqueueRequestFromNameLabel(label string, namespace ...string) handler.EventHandler
- func EnsureFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string) error
- func EnsureNoFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string) error
- func EnsureResourceDeletion(ctx context.Context, clusterClient client.Client, ...) error
- func EnsureResourceGone(ctx context.Context, k8sClient GetterDeleter, obj client.Object) error
- func FetchObject(ctx context.Context, client client.Client, namespace string, name string, ...) error
- func FindContainer(containers []corev1.Container, name string) (*corev1.Container, bool)
- func FindMonitor(monitors []v1alpha1.Uptrends, name string) (*v1alpha1.Uptrends, bool)
- func GetK8sNamespace(fallback string) (string, error)
- func GetKind(obj runtime.Object) string
- func HasFinalizer(obj metav1.Object, finalizer string) bool
- func IsControlledBy(obj metav1.Object, owner metav1.Object) bool
- func IsObjectFound(ctx context.Context, client client.Client, namespace string, name string, ...) bool
- func IsOwnedBy(obj metav1.Object, owner metav1.Object) bool
- func LabelToNamespacedName(l string) (types.NamespacedName, error)
- func MergeEnvVars(oldEnvs []corev1.EnvVar, newEnvs ...corev1.EnvVar) []corev1.EnvVar
- func MergeTaints(oldTaints []corev1.Taint, newTaints ...corev1.Taint) []corev1.Taint
- func MetaObjectToObjectKey(meta metav1.Object) client.ObjectKey
- func NamespacedNameToLabel(nn types.NamespacedName) string
- func NewClient(client client.Client) client.Client
- func NodeAffinityFromSelector(nodeSelector map[string]string) *corev1.NodeAffinity
- func ObjectKeyToObjectMeta(key client.ObjectKey) metav1.ObjectMeta
- func ParseNamespacedNamed(nn string) (types.NamespacedName, error)
- func RESTConfigFromServiceAccountSecret(secret *corev1.Secret, kubernetesAddress string) (*rest.Config, error)
- func RemoveOwnerReference(ctx context.Context, c client.Client, obj client.Object, owner metav1.Object) error
- func SetAnnotation(obj metav1.Object, key, value string)
- func SetInheritedLabels(obj metav1.Object, parent metav1.Object, keys ...string)
- func SetLabel(obj metav1.Object, key, value string)
- func SkipReconcile(obj client.Object) bool
- func SortTypedLocalObjectReference(refs []corev1.TypedLocalObjectReference)
- func UpdateSecretData(secret *corev1.Secret, data map[string]interface{})
- func UpdateStatus(ctx context.Context, c client.Client, obj client.Object) error
- func UpdateStatusWithResult(ctx context.Context, c client.Client, obj client.Object) (controllerutil.OperationResult, error)
- func WithFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string, ...) (ctrl.Result, error)
- type Deleter
- type GetterDeleter
- type LabelSelectorRequirement
Constants ¶
const LabelSeparator = "_"
LabelSeparator to use instead of types.Separator.
Variables ¶
var ( ErrHoldFinalizer = errors.New("hold finalizer") ErrSAHasNoSecrets = errors.New("service account has no secrets") )
ErrHoldFinalizer indicates that the finalizer should be held.
Functions ¶
func BuildLabelSelector ¶
func BuildLabelSelector(requirements ...LabelSelectorRequirement) (labels.Selector, error)
BuildLabelSelector builds a label selector or returns an error if any of the requirements are invalid.
func ClientConfigFromServiceAccountKey ¶
func ClientConfigFromServiceAccountKey( ctx context.Context, log logr.Logger, k8sClient client.Client, accountKey client.ObjectKey, externalKubernetesAddress string, ) (*clientcmdapi.Config, error)
ClientConfigFromServiceAccountKey fetches the service account secret and calls ClientConfigFromServiceAccountSecret.
func ClientConfigFromServiceAccountSecret ¶
func ClientConfigFromServiceAccountSecret(secret *corev1.Secret, kubernetesAddress string) (*clientcmdapi.Config, error)
ClientConfigFromServiceAccountSecret uses the secret and address to construct a clientconfig that can be used to create a KUBECONFIG.
func ClientFromKubeconfig ¶
func CreateMetrics ¶
func CreateMetrics(namespace string) *prometheus.HistogramVec
CreateMetrics creates a new Kubernetes Histogram metric and registers it in the given RegistererGatherer using given namespace. It is safe to call that method multiple times, the metric will be created only once. Subsequent calls returns the same metric.
func CreateOrUpdateContainer ¶
func CreateOrUpdateContainer(containers []corev1.Container, name string, updateFn func(c *corev1.Container) error) ([]corev1.Container, error)
CreateOrUpdateContainer either creates or finds a container with the given name. The desired state of that container should be reconciled inside updateFn. The updated container slice is returned.
func CreateOrUpdateMonitor ¶
func CreateOrUpdateMonitor(monitors []v1alpha1.Uptrends, name string, updateFn func(m *v1alpha1.Uptrends) error) ([]v1alpha1.Uptrends, error)
CreateOrUpdateMonitor creates or updates a monitor for the given object.
func DefaultNewClientWithMetrics ¶
func DefaultNewClientWithMetrics( cache cache.Cache, config *rest.Config, options client.Options, uncachedObjects ...client.Object, ) (client.Client, error)
DefaultNewClientWithMetrics supports read and list caching and enables monitoring measured by ignored cache requests. This method is used by a k8s manager.
func EnqueueRequestFromNameLabel ¶
func EnqueueRequestFromNameLabel(label string, namespace ...string) handler.EventHandler
EnqueueRequestFromNameLabel determines the reconcile request name based on the value of the specified label. If a namespace is specified, that namespace will be used instead of the objects namespace. This is useful if you want to reconcile based on changes without using an OwnerReference.
func EnsureFinalizer ¶
func EnsureFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string) error
EnsureFinalizer appends the given finalizer. If it did not exist before the object is updated using the client.
func EnsureNoFinalizer ¶
func EnsureNoFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string) error
EnsureNoFinalizer removes the given finalizer. If it existed the object is updated using the client.
func EnsureResourceDeletion ¶
func EnsureResourceDeletion(ctx context.Context, clusterClient client.Client, resourcesToDelete ...client.Object) error
EnsureResourceDeletion deletes all resources and returns an error if not all could be deleted.
func EnsureResourceGone ¶
EnsureResourceGone calls Delete() only of the object still exists, so it is safe to use during reconciliation, as it will not cause additional load on the API Server.
func FetchObject ¶
func FetchObject(ctx context.Context, client client.Client, namespace string, name string, obj client.Object) error
FetchObject ...
func FindContainer ¶
FindContainer finds a container by name. Second return value will be false, if no matching container was found.
func FindMonitor ¶
FindMonitor finds a monitor by name.
func GetK8sNamespace ¶
GetK8sNamespace returns the namespace the process is running in, when actually running in-cluster. Returns fallback otherwise.
func GetKind ¶
GetKind returns the Kind of the kubernetes object. If the kind is not set (e.g. during tests without envtest), it returns the struct name, which should usually match the kind.
func HasFinalizer ¶
HasFinalizer returns true if the given finalizer is present on the object.
func IsControlledBy ¶
IsControlledBy checks if the object has a controller ref set to the given owner.
func IsObjectFound ¶
func IsObjectFound(ctx context.Context, client client.Client, namespace string, name string, obj client.Object) bool
IsObjectFound ...
func LabelToNamespacedName ¶
func LabelToNamespacedName(l string) (types.NamespacedName, error)
LabelToNamespacedName reads from a label-encoded name ("namespace_resource") and parses the namespaced name.
func MergeEnvVars ¶
MergeEnvVars returns a new slice of EnvVar after merging all the new envvars. If a envvar with the same name already existed it will be overwritten, otherwise it will be appended.
func MergeTaints ¶
MergeTaints returns a new list of taints after merging all the new taints. If a taint with the same key already existed it will be overwritten, otherwise it will be appended.
func MetaObjectToObjectKey ¶
MetaObjectToObjectKey returns a new client.ObjectKey for the meta object.
func NamespacedNameToLabel ¶
func NamespacedNameToLabel(nn types.NamespacedName) string
NamespacedNameToLabel encodes a namespacedname into a label-compliant string ("namespace_resource").
func NodeAffinityFromSelector ¶
func NodeAffinityFromSelector(nodeSelector map[string]string) *corev1.NodeAffinity
NodeAffinityFromSelector converts a simple nodeSelector to a nodeAffinity, where the terms are ANDed.
func ObjectKeyToObjectMeta ¶
func ObjectKeyToObjectMeta(key client.ObjectKey) metav1.ObjectMeta
ObjectKeyToObjectMeta returns a new metav1.ObjectMeta for the object key.
func ParseNamespacedNamed ¶
func ParseNamespacedNamed(nn string) (types.NamespacedName, error)
ParseNamespacedNamed turns "namespace/resource" into a NamespacedName.
func RESTConfigFromServiceAccountSecret ¶
func RESTConfigFromServiceAccountSecret(secret *corev1.Secret, kubernetesAddress string) (*rest.Config, error)
RESTConfigFromServiceAccountSecret constructs a rest config using the secret and host provided.
func RemoveOwnerReference ¶
func RemoveOwnerReference(ctx context.Context, c client.Client, obj client.Object, owner metav1.Object) error
RemoveOwnerReference removes the given owner reference from the given object.
func SetAnnotation ¶
SetAnnotation is a helper function that sets the given annotation and creates the annotation map if it does not exist yet.
func SetInheritedLabels ¶
SetInheritedLabels sets the labels from the parent if they exist, overwriting labels that existed before.
func SetLabel ¶
SetLabel is a helper function that sets the given label and creates the labels map if it does not exist yet.
func SkipReconcile ¶
SkipReconcile returns true if reconciliation should be temporarily skipped for this resource.
func SortTypedLocalObjectReference ¶
func SortTypedLocalObjectReference(refs []corev1.TypedLocalObjectReference)
SortTypedLocalObjectReference into a stable order.
func UpdateSecretData ¶
UpdateSecretData writes the provided fields in the Data field of the struct. Provided values should either be []byte or string.
func UpdateStatus ¶
UpdateStatus updates the status of the object, only if the status sub-resource has changed.
func UpdateStatusWithResult ¶
func UpdateStatusWithResult(ctx context.Context, c client.Client, obj client.Object) (controllerutil.OperationResult, error)
UpdateStatusWithResult updates the status of the object, only if the status sub-resource has changed, and returns whether it was changed or not.
func WithFinalizer ¶
func WithFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string, reconcile, delete func() (ctrl.Result, error)) (ctrl.Result, error)
WithFinalizer ensures that finalizer is on obj until obj is deleted. Delete is called when obj is deleted. The finalizer is removed if delete return no error.
Types ¶
type Deleter ¶
type Deleter interface {
Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
}
Deleter can delete resources from kubernetes.
type GetterDeleter ¶
type GetterDeleter interface { Deleter Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error }
GetterDeleter can get and delete resources from kubernetes.
type LabelSelectorRequirement ¶
LabelSelectorRequirement is an unchecked representation of labels.Requirements.
func NewRequirement ¶
func NewRequirement(key string, op selection.Operator, vals []string) LabelSelectorRequirement
NewRequirement creates a new requirement to be used for BuildLabelSelector.