cluster

package
v2.24.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2025 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package cluster contains utility functions used to operate on cluster resources.

This includes getting cluster domain, operator namespace and CSV, defining different GVK being used in the project, config metadata on reousrces, managing reousrces like rolebinding, secret and configmap.

Index

Constants

View Source
const (
	// ManagedRhoai defines expected addon catalogsource.
	ManagedRhoai common.Platform = "OpenShift AI Cloud Service"
	// SelfManagedRhoai defines display name in csv.
	SelfManagedRhoai common.Platform = "OpenShift AI Self-Managed"
	// OpenDataHub defines display name in csv.
	OpenDataHub common.Platform = "Open Data Hub"
	// Unknown indicates that operator is not deployed using OLM.
	Unknown common.Platform = ""

	// DefaultNotebooksNamespace defines default namespace for notebooks.
	DefaultNotebooksNamespace = "rhods-notebooks"

	// Default cluster-scope Authentication CR name.
	ClusterAuthenticationObj = "cluster"

	// Default OpenShift version CR name.
	OpenShiftVersionObj = "version"

	// Managed cluster required route.
	NameConsoleLink      = "console"
	NamespaceConsoleLink = "openshift-console"
)
View Source
const IngressNamespace = "openshift-ingress"

Variables

View Source
var IngressControllerName = types.NamespacedName{
	Namespace: "openshift-ingress-operator",
	Name:      "default",
}

Functions

func ApplyMetaOptions added in v2.10.0

func ApplyMetaOptions(obj metav1.Object, opts ...MetaOptions) error

func CreateNamespace

func CreateNamespace(ctx context.Context, cli client.Client, namespace string, metaOptions ...MetaOptions) (*corev1.Namespace, error)

CreateNamespace creates a namespace and apply metadata. If a namespace already exists, the operation has no effect on it.

func CreateOrUpdateConfigMap added in v2.10.1

func CreateOrUpdateConfigMap(ctx context.Context, c client.Client, desiredCfgMap *corev1.ConfigMap, metaOptions ...MetaOptions) error

CreateOrUpdateConfigMap creates a new configmap or updates an existing one. If the configmap already exists, it will be updated with the merged Data and MetaOptions, if any. ConfigMap.ObjectMeta.Name and ConfigMap.ObjectMeta.Namespace are both required, it returns an error otherwise.

func CreateSelfSignedCertificate added in v2.14.0

func CreateSelfSignedCertificate(ctx context.Context, c client.Client, secretName, domain, namespace string, metaOptions ...MetaOptions) error

func CreateWithRetry added in v2.12.0

func CreateWithRetry(ctx context.Context, cli client.Client, obj client.Object, timeoutMin int) error

func CustomResourceDefinitionExists added in v2.21.0

func CustomResourceDefinitionExists(ctx context.Context, cli client.Client, crdGK schema.GroupKind) error

CustomResourceDefinitionExists checks if a CustomResourceDefinition with the given GVK exists.

func DeleteExistingSubscription added in v2.13.0

func DeleteExistingSubscription(ctx context.Context, cli client.Client, operatorNs string, subsName string) error

DeleteExistingSubscription deletes given Subscription if it exists Do not error if the Subscription does not exist.

func ExecuteOnAllNamespaces added in v2.15.0

func ExecuteOnAllNamespaces(ctx context.Context, cli client.Client, processFunc func(*corev1.Namespace) error) error

ExecuteOnAllNamespaces executes the passed function for all namespaces in the cluster retrieved in batches.

func FindAvailableIngressController added in v2.14.0

func FindAvailableIngressController(ctx context.Context, c client.Client) (*operatorv1.IngressController, error)

func FindDefaultIngressSecret added in v2.23.0

func FindDefaultIngressSecret(ctx context.Context, c client.Client) (*corev1.Secret, error)

func GenerateSelfSignedCertificateAsSecret added in v2.14.0

func GenerateSelfSignedCertificateAsSecret(name, addr, namespace string) (*corev1.Secret, error)

func GetClusterServiceVersion added in v2.10.0

func GetClusterServiceVersion(ctx context.Context, c client.Client, namespace string) (*ofapiv1alpha1.ClusterServiceVersion, error)

GetClusterServiceVersion retries CSV only from the defined namespace.

func GetDSC added in v2.24.0

GetDSC retrieves the DataScienceCluster (DSC) instance from the Kubernetes cluster.

func GetDSCI added in v2.24.0

GetDSCI retrieves the DSCInitialization (DSCI) instance from the Kubernetes cluster.

func GetDefaultIngressCertSecretName added in v2.14.0

func GetDefaultIngressCertSecretName(ingressCtrl *operatorv1.IngressController) string

func GetDomain added in v2.8.0

func GetDomain(ctx context.Context, c client.Client) (string, error)

func GetOperatorNamespace added in v2.10.0

func GetOperatorNamespace() (string, error)

func GetRelease added in v2.13.0

func GetRelease() common.Release

func GetSecret added in v2.14.0

func GetSecret(ctx context.Context, c client.Client, namespace, name string) (*corev1.Secret, error)

func GetSingleton added in v2.24.0

func GetSingleton[T client.Object](ctx context.Context, cli client.Client, obj T) error

GetSingleton retrieves a singleton instance of a Kubernetes resource of type T.

It ensures that only one instance exists and updates the provided object pointer with the retrieved data and:

  • If no instances are found, it returns a "NotFound" error.
  • If multiple instances are found, it returns an error indicating an unexpected number of instances.
  • A generic error in case of other failures

Generic Parameters:

  • T: A Kubernetes API resource that implements client.Object. T **must be a pointer to a struct**, allowing the function to update its contents.

Parameters:

  • ctx: The context for the API request, allowing for cancellation and timeouts.
  • cli: The Kubernetes client used to interact with the cluster.
  • obj: A **pointer to a struct** that implements client.Object, which will be populated with the retrieved resource.

Returns:

  • nil if exactly one instance of the resource is found and successfully assigned to obj.
  • An error if no instances or multiple instances are found, or if any failure occurs.

func GetSubscription added in v2.13.0

func GetSubscription(ctx context.Context, cli client.Client, namespace string, name string) (*v1alpha1.Subscription, error)

GetSubscription checks if a Subscription for the operator exists in the given namespace. if exists, return object; otherwise, return error.

func HasCRDWithVersion added in v2.24.0

func HasCRDWithVersion(ctx context.Context, cli client.Client, crdGK schema.GroupKind, version string) (bool, error)

return true if found, return false if not found required CRD with version checks on both CRD API version also if it is under deletion.

func Init added in v2.19.0

func Init(ctx context.Context, cli client.Client) error

Init initializes cluster configuration variables on startup init() won't work since it is needed to check the error.

func IsDefaultAuthMethod added in v2.20.0

func IsDefaultAuthMethod(ctx context.Context, cli client.Client) (bool, error)

IsDefaultAuthMethod returns true if the default authentication method is IntegratedOAuth or empty. This will give indication that Operator should create userGroups or not in the cluster.

func IsNotReservedNamespace added in v2.15.0

func IsNotReservedNamespace(ns *corev1.Namespace) bool

func OperatorExists added in v2.13.0

func OperatorExists(ctx context.Context, cli client.Client, operatorPrefix string) (bool, error)

OperatorExists checks if an Operator with 'operatorPrefix' is installed. Return true if found it, false if not. if we need to check exact version of the operator installed, can append vX.Y.Z later.

func PropagateDefaultIngressCertificate added in v2.14.0

func PropagateDefaultIngressCertificate(ctx context.Context, c client.Client, secretName, namespace string) error

PropagateDefaultIngressCertificate copies ingress cert secrets from openshift-ingress ns to given namespace.

func SubjectExistInRoleBinding added in v2.23.0

func SubjectExistInRoleBinding(subjectList []rbacv1.Subject, serviceAccountName, namespace string) bool

SubjectExistInRoleBinding return whether RoleBinding matching service account and namespace exists or not.

func SubscriptionExists added in v2.13.0

func SubscriptionExists(ctx context.Context, cli client.Client, name string) (bool, error)

func UpdatePodSecurityRolebinding

func UpdatePodSecurityRolebinding(ctx context.Context, cli client.Client, namespace string, serviceAccountsList ...string) error

UpdatePodSecurityRolebinding update default rolebinding which is created in applications namespace by manifests being used by different components and SRE monitoring.

Types

type ClusterInfo added in v2.23.0

type ClusterInfo struct {
	Type    string                  `json:"type,omitempty"` // openshift , TODO: can be other value if we later support other type
	Version version.OperatorVersion `json:"version,omitempty"`
}

func GetClusterInfo added in v2.23.0

func GetClusterInfo() ClusterInfo

type MetaOptions added in v2.7.0

type MetaOptions func(obj metav1.Object) error

MetaOptions allows to add additional settings for the object being created through a chain of functions which are applied on metav1.Object before actual resource creation.

func ControlledBy added in v2.24.0

func ControlledBy(owner metav1.Object, scheme *runtime.Scheme) MetaOptions

func InNamespace added in v2.14.0

func InNamespace(ns string) MetaOptions

func OwnedBy added in v2.11.0

func OwnedBy(owner metav1.Object, scheme *runtime.Scheme) MetaOptions

OwnedBy sets the owner reference for the object being created. It requires scheme to be passed as TypeMeta might not be set for the owning object, see: https://github.com/kubernetes-sigs/controller-runtime/issues/1517

func WithAnnotations added in v2.14.0

func WithAnnotations(annotationKeyValue ...string) MetaOptions

func WithLabels added in v2.7.0

func WithLabels(labels ...string) MetaOptions

func WithOwnerReference added in v2.10.0

func WithOwnerReference(ownerReferences ...metav1.OwnerReference) MetaOptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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