Documentation ¶
Index ¶
- Constants
- Variables
- func Become(ctx context.Context, lockName string) error
- func GetGVKsFromAddToScheme(addToSchemeFunc func(*runtime.Scheme) error) ([]schema.GroupVersionKind, error)
- func GetOperatorName() (string, error)
- func GetOperatorNamespace() (string, error)
- func GetPod(ctx context.Context, client crclient.Client, ns string) (*corev1.Pod, error)
- func GetWatchNamespace() (string, error)
- func ResourceExists(dc discovery.DiscoveryInterface, apiGroupVersion, kind string) (bool, error)
Constants ¶
const ( // KubeConfigEnvVar defines the env variable KUBECONFIG which // contains the kubeconfig file path. KubeConfigEnvVar = "KUBECONFIG" // WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE // which is the namespace where the watch activity happens. // this value is empty if the operator is running with clusterScope. WatchNamespaceEnvVar = "WATCH_NAMESPACE" // OperatorNameEnvVar is the constant for env variable OPERATOR_NAME // which is the name of the current operator OperatorNameEnvVar = "OPERATOR_NAME" // PodNameEnvVar is the constant for env variable POD_NAME // which is the name of the current pod. PodNameEnvVar = "POD_NAME" )
Variables ¶
var ErrNoNamespace = fmt.Errorf("namespace not found for current environment")
errNoNS indicates that a namespace could not be found for the current environment
Functions ¶
func Become ¶
Become ensures that the current pod is the leader within its namespace. If run outside a cluster, it will skip leader election and return nil. It continuously tries to create a ConfigMap with the provided name and the current pod set as the owner reference. Only one can exist at a time with the same name, so the pod that successfully creates the ConfigMap is the leader. Upon termination of that pod, the garbage collector will delete the ConfigMap, enabling a different pod to become the leader.
func GetGVKsFromAddToScheme ¶
func GetGVKsFromAddToScheme(addToSchemeFunc func(*runtime.Scheme) error) ([]schema.GroupVersionKind, error)
GetGVKsFromAddToScheme takes in the runtime scheme and filters out all generic apimachinery meta types. It returns just the GVK specific to this scheme.
func GetOperatorName ¶
GetOperatorName return the operator name
func GetOperatorNamespace ¶
GetOperatorNamespace returns the namespace the operator should be running in.
func GetPod ¶
GetPod returns a Pod object that corresponds to the pod in which the code is currently running. It expects the environment variable POD_NAME to be set by the downwards API.
func GetWatchNamespace ¶
GetWatchNamespace returns the namespace the operator should be watching for changes
func ResourceExists ¶
func ResourceExists(dc discovery.DiscoveryInterface, apiGroupVersion, kind string) (bool, error)
ResourceExists returns true if the given resource kind exists in the given api groupversion
Types ¶
This section is empty.