v1helpers

package
v0.0.0-...-5152f1c Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureFinalizer

func EnsureFinalizer(ctx context.Context, client OperatorClientWithFinalizers, controllerName string) error

EnsureFinalizer adds a new finalizer to the operator CR, if it does not exists. No-op otherwise. The finalizer name is computed from the controller name and operator name ($OPERATOR_NAME or os.Args[0]) It re-tries on conflicts.

func FindCondition

func FindCondition(conditions []metav1.Condition, conditionType string) *metav1.Condition

func FindOperandVersion

func FindOperandVersion(versions []configv1.OperandVersion, name string) *configv1.OperandVersion

func FindOperatorCondition

func FindOperatorCondition(conditions []operatorv1.OperatorCondition, conditionType string) *operatorv1.OperatorCondition

func FlagsFromUnstructured

func FlagsFromUnstructured(unstructuredArgs map[string]interface{}) (map[string][]string, error)

FlagsFromUnstructured process the unstructured arguments usually retrieved from an operator's configuration file under a specific key. There are only two supported/valid types for arguments, that is []sting and/or string. Passing a different type yield an error.

Use ToFlagSlice function to get a slice of string flags.

func InjectObservedProxyIntoContainers

func InjectObservedProxyIntoContainers(podSpec *corev1.PodSpec, containerNames []string, observedConfig []byte, fields ...string) error

InjectObservedProxyIntoContainers injects proxy environment variables in containers specified in containerNames.

func InjectTrustedCAIntoContainers

func InjectTrustedCAIntoContainers(podSpec *corev1.PodSpec, configMapName string, containerNames []string) error

func IsConditionFalse

func IsConditionFalse(conditions []metav1.Condition, conditionType string) bool

func IsConditionPresentAndEqual

func IsConditionPresentAndEqual(conditions []metav1.Condition, conditionType string, status metav1.ConditionStatus) bool

func IsConditionTrue

func IsConditionTrue(conditions []metav1.Condition, conditionType string) bool

func IsOperatorConditionFalse

func IsOperatorConditionFalse(conditions []operatorv1.OperatorCondition, conditionType string) bool

func IsOperatorConditionPresentAndEqual

func IsOperatorConditionPresentAndEqual(conditions []operatorv1.OperatorCondition, conditionType string, status operatorv1.ConditionStatus) bool

func IsOperatorConditionTrue

func IsOperatorConditionTrue(conditions []operatorv1.OperatorCondition, conditionType string) bool

func MapToEnvVars

func MapToEnvVars(mapEnvVars map[string]string) []corev1.EnvVar

MapToEnvVars converts a string-string map to a slice of corev1.EnvVar-s

func NewFakeNodeLister

func NewFakeNodeLister(client kubernetes.Interface) corev1listers.NodeLister

NewFakeNodeLister returns a fake node lister suitable to use in node controller unit test

func NewFakeSharedIndexInformer

func NewFakeSharedIndexInformer() cache.SharedIndexInformer

NewFakeSharedIndexInformer returns a fake shared index informer, suitable to use in static pod controller unit tests.

func NewMultiLineAggregate

func NewMultiLineAggregate(errList []error) error

NewMultiLineAggregate returns an aggregate error with multi-line output

func RemoveCondition

func RemoveCondition(conditions *[]metav1.Condition, conditionType string)

func RemoveFinalizer

func RemoveFinalizer(ctx context.Context, client OperatorClientWithFinalizers, controllerName string) error

RemoveFinalizer removes a finalizer from the operator CR, if it is there. No-op otherwise. The finalizer name is computed from the controller name and operator name ($OPERATOR_NAME or os.Args[0]) It re-tries on conflicts.

func RemoveOperatorCondition

func RemoveOperatorCondition(conditions *[]operatorv1.OperatorCondition, conditionType string)

func SetCondition

func SetCondition(conditions *[]metav1.Condition, newCondition metav1.Condition)

func SetOperandVersion

func SetOperandVersion(versions *[]configv1.OperandVersion, operandVersion configv1.OperandVersion) string

SetOperandVersion sets the new version and returns the previous value.

func SetOperatorCondition

func SetOperatorCondition(conditions *[]operatorv1.OperatorCondition, newCondition operatorv1.OperatorCondition)

func ToFlagSlice

func ToFlagSlice(args map[string][]string) []string

ToFlagSlice transforms the provided arguments to a slice of string flags. A flag name is taken directly from the key and the value is simply attached. A flag is repeated iff it has more than one value.

func UpdateSpec

func UpdateSpec(ctx context.Context, client OperatorClient, updateFuncs ...UpdateOperatorSpecFunc) (*operatorv1.OperatorSpec, bool, error)

UpdateSpec applies the update funcs to the oldStatus and tries to update via the client.

func UpdateStaticPodStatus

func UpdateStaticPodStatus(ctx context.Context, client StaticPodOperatorClient, updateFuncs ...UpdateStaticPodStatusFunc) (*operatorv1.StaticPodOperatorStatus, bool, error)

UpdateStaticPodStatus applies the update funcs to the oldStatus abd tries to update via the client.

func UpdateStatus

func UpdateStatus(ctx context.Context, client OperatorClient, updateFuncs ...UpdateStatusFunc) (*operatorv1.OperatorStatus, bool, error)

UpdateStatus applies the update funcs to the oldStatus and tries to update via the client.

Types

type KubeInformersForNamespaces

type KubeInformersForNamespaces interface {
	Start(stopCh <-chan struct{})
	InformersFor(namespace string) informers.SharedInformerFactory
	Namespaces() sets.Set[string]

	ConfigMapLister() corev1listers.ConfigMapLister
	SecretLister() corev1listers.SecretLister

	// Used in by workloads controller and controllers that report deployment pods status
	PodLister() corev1listers.PodLister
}

KubeInformersForNamespaces is a simple way to combine several shared informers into a single struct with unified listing power

func NewFakeKubeInformersForNamespaces

func NewFakeKubeInformersForNamespaces(informers map[string]informers.SharedInformerFactory) KubeInformersForNamespaces

func NewKubeInformersForNamespaces

func NewKubeInformersForNamespaces(kubeClient kubernetes.Interface, namespaces ...string) KubeInformersForNamespaces

type OperatorClient

type OperatorClient interface {
	Informer() cache.SharedIndexInformer
	// GetObjectMeta return the operator metadata.
	GetObjectMeta() (meta *metav1.ObjectMeta, err error)
	// GetOperatorState returns the operator spec, status and the resource version, potentially from a lister.
	GetOperatorState() (spec *operatorv1.OperatorSpec, status *operatorv1.OperatorStatus, resourceVersion string, err error)
	// GetOperatorStateWithQuorum return the operator spec, status and resource version directly from a server read.
	GetOperatorStateWithQuorum(ctx context.Context) (spec *operatorv1.OperatorSpec, status *operatorv1.OperatorStatus, resourceVersion string, err error)
	// UpdateOperatorSpec updates the spec of the operator, assuming the given resource version.
	UpdateOperatorSpec(ctx context.Context, oldResourceVersion string, in *operatorv1.OperatorSpec) (out *operatorv1.OperatorSpec, newResourceVersion string, err error)
	// UpdateOperatorStatus updates the status of the operator, assuming the given resource version.
	UpdateOperatorStatus(ctx context.Context, oldResourceVersion string, in *operatorv1.OperatorStatus) (out *operatorv1.OperatorStatus, err error)
}

type OperatorClientWithFinalizers

type OperatorClientWithFinalizers interface {
	OperatorClient
	// EnsureFinalizer adds a new finalizer to the operator CR, if it does not exists. No-op otherwise.
	EnsureFinalizer(ctx context.Context, finalizer string) error
	// RemoveFinalizer removes a finalizer from the operator CR, if it is there. No-op otherwise.
	RemoveFinalizer(ctx context.Context, finalizer string) error
}

func NewFakeOperatorClient

func NewFakeOperatorClient(spec *operatorv1.OperatorSpec, status *operatorv1.OperatorStatus, triggerErr func(rv string, status *operatorv1.OperatorStatus) error) OperatorClientWithFinalizers

NewFakeOperatorClient returns a fake operator client suitable to use in static pod controller unit tests.

func NewFakeOperatorClientWithObjectMeta

func NewFakeOperatorClientWithObjectMeta(meta *metav1.ObjectMeta, spec *operatorv1.OperatorSpec, status *operatorv1.OperatorStatus, triggerErr func(rv string, status *operatorv1.OperatorStatus) error) OperatorClientWithFinalizers

type StaticPodOperatorClient

type StaticPodOperatorClient interface {
	OperatorClient
	// GetStaticPodOperatorState returns the static pod operator spec, status and the resource version,
	// potentially from a lister.
	GetStaticPodOperatorState() (spec *operatorv1.StaticPodOperatorSpec, status *operatorv1.StaticPodOperatorStatus, resourceVersion string, err error)
	// GetStaticPodOperatorStateWithQuorum return the static pod operator spec, status and resource version
	// directly from a server read.
	GetStaticPodOperatorStateWithQuorum(ctx context.Context) (spec *operatorv1.StaticPodOperatorSpec, status *operatorv1.StaticPodOperatorStatus, resourceVersion string, err error)
	// UpdateStaticPodOperatorStatus updates the status, assuming the given resource version.
	UpdateStaticPodOperatorStatus(ctx context.Context, resourceVersion string, in *operatorv1.StaticPodOperatorStatus) (out *operatorv1.StaticPodOperatorStatus, err error)
	// UpdateStaticPodOperatorSpec updates the spec, assuming the given resource  version.
	UpdateStaticPodOperatorSpec(ctx context.Context, resourceVersion string, in *operatorv1.StaticPodOperatorSpec) (out *operatorv1.StaticPodOperatorSpec, newResourceVersion string, err error)
}

func NewFakeStaticPodOperatorClient

func NewFakeStaticPodOperatorClient(
	staticPodSpec *operatorv1.StaticPodOperatorSpec, staticPodStatus *operatorv1.StaticPodOperatorStatus,
	triggerStatusErr func(rv string, status *operatorv1.StaticPodOperatorStatus) error,
	triggerSpecErr func(rv string, spec *operatorv1.StaticPodOperatorSpec) error) StaticPodOperatorClient

NewFakeStaticPodOperatorClient returns a fake operator client suitable to use in static pod controller unit tests.

type UpdateOperatorSpecFunc

type UpdateOperatorSpecFunc func(spec *operatorv1.OperatorSpec) error

UpdateOperatorSpecFunc is a func that mutates an operator spec.

func UpdateObservedConfigFn

func UpdateObservedConfigFn(config map[string]interface{}) UpdateOperatorSpecFunc

UpdateObservedConfigFn returns a func to update the config.

type UpdateStaticPodStatusFunc

type UpdateStaticPodStatusFunc func(status *operatorv1.StaticPodOperatorStatus) error

UpdateStaticPodStatusFunc is a func that mutates an operator status.

func UpdateStaticPodConditionFn

func UpdateStaticPodConditionFn(cond operatorv1.OperatorCondition) UpdateStaticPodStatusFunc

UpdateStaticPodConditionFn returns a func to update a condition.

type UpdateStatusFunc

type UpdateStatusFunc func(status *operatorv1.OperatorStatus) error

UpdateStatusFunc is a func that mutates an operator status.

func UpdateConditionFn

func UpdateConditionFn(cond operatorv1.OperatorCondition) UpdateStatusFunc

UpdateConditionFn returns a func to update a condition.

Jump to

Keyboard shortcuts

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