common

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const (
	UninstallingAnnotation string = "policy.open-cluster-management.io/uninstalling"
	PolicyDBIDAnnotation   string = "policy.open-cluster-management.io/policy-compliance-db-id"
	ParentDBIDAnnotation   string = "policy.open-cluster-management.io/parent-policy-compliance-db-id"
)
View Source
const (
	ForceRunModeEnv             = "OSDK_FORCE_RUN_MODE"
	LocalRunMode    RunModeType = "local"
	ClusterRunMode  RunModeType = "cluster"

	// OperatorNameEnvVar is the constant for env variable OPERATOR_NAME
	// which is the name of the current operator
	OperatorNameEnvVar = "OPERATOR_NAME"
)

Variables

View Source
var ErrNoNamespace = fmt.Errorf("namespace not found for current environment")

ErrNoNamespace indicates that a namespace could not be found for the current environment

View Source
var ErrRunLocal = fmt.Errorf("operator run mode forced to local")

ErrRunLocal indicates that the operator is set to run in local mode (this error is returned by functions that only work on operators running in cluster mode)

Functions

func CreateRecorder

func CreateRecorder(kubeClient kubernetes.Interface, componentName string) (record.EventRecorder, error)

CreateRecorder return recorder

func GetAllNamespaces

func GetAllNamespaces(client kubernetes.Interface, labelSelector metav1.LabelSelector) ([]string, error)

GetAllNamespaces gets the list of all namespaces from k8s that matches the input label selector.

func GetOperatorName added in v0.10.0

func GetOperatorName() (string, error)

GetOperatorName returns the operator name

func GetOperatorNamespace

func GetOperatorNamespace() (string, error)

GetOperatorNamespace returns the namespace the operator should be running in.

func GetOperatorNamespacedName added in v0.10.0

func GetOperatorNamespacedName() (types.NamespacedName, error)

GetOperatorNamespacedName returns the name and namespace of the operator.

func GetSelectedNamespaces

func GetSelectedNamespaces(client kubernetes.Interface, selector policyv1.Target) ([]string, error)

GetSelectedNamespaces returns the list of filtered namespaces according to the policy namespace selector.

func GetWatchNamespace

func GetWatchNamespace() (string, error)

GetWatchNamespace returns the Namespace the operator should be watching for changes

func Matches added in v0.8.0

func Matches(
	namespaces []string,
	includeList []policyv1.NonEmptyString,
	excludeList []policyv1.NonEmptyString,
) ([]string, error)

Matches filters a slice of strings, and returns ones that match the selector

Types

type NamespaceSelectorReconciler added in v0.12.0

type NamespaceSelectorReconciler struct {
	Client client.Client
	// contains filtered or unexported fields
}

func (*NamespaceSelectorReconciler) Get added in v0.12.0

Get returns the items matching the given Target for the given policy. If no selection for that policy and Target has been calculated, it will be calculated now. Otherwise, a cached value may be used.

func (*NamespaceSelectorReconciler) HasUpdate added in v0.12.0

func (r *NamespaceSelectorReconciler) HasUpdate(name string) bool

HasUpdate indicates when the cached selection for this policy has been changed since the last time that Get was called for that policy.

func (*NamespaceSelectorReconciler) Reconcile added in v0.12.0

Reconcile runs whenever a namespace on the target cluster is created, deleted, or has a change in labels. It updates the cached selections for NamespaceSelectors that it knows about.

func (*NamespaceSelectorReconciler) SetupWithManager added in v0.12.0

func (r *NamespaceSelectorReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

func (*NamespaceSelectorReconciler) Stop added in v0.12.0

func (r *NamespaceSelectorReconciler) Stop(name string)

Stop tells the SelectorReconciler to stop updating the cached selection for the name.

type RunModeType

type RunModeType string

type SelectorReconciler added in v0.12.0

type SelectorReconciler interface {
	// Get returns the items matching the given Target for the given name. If no selection for that
	// name and Target has been calculated, it will be calculated now. Otherwise, a cached value
	// may be used.
	Get(string, policyv1.Target) ([]string, error)

	// HasUpdate indicates when the cached selection for this name has been changed since the last
	// time that Get was called for that name.
	HasUpdate(string) bool

	// Stop tells the SelectorReconciler to stop updating the cached selection for the name.
	Stop(string)
}

SelectorReconciler keeps a cache of NamespaceSelector results, which it should update when namespaces are created, deleted, or re-labeled.

Jump to

Keyboard shortcuts

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