k8sutil

package
v0.1.76 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugDeploymentsAnnotation contains a comma separated list of deployment names which should always be scaled to 0
	// for development.
	DebugDeploymentsAnnotation = "hypershift.openshift.io/debug-deployments"
	// EnableHostedClustersAnnotationScopingEnv is the env var that enables annotation-based scoping for hosted clusters.
	EnableHostedClustersAnnotationScopingEnv = "ENABLE_HOSTEDCLUSTERS_ANNOTATION_SCOPING"
	// HostedClustersScopeAnnotationEnv is the env var that specifies the scope annotation value to match.
	HostedClustersScopeAnnotationEnv = "HOSTEDCLUSTERS_SCOPE_ANNOTATION"
	// HostedClustersScopeAnnotation is the annotation key used to scope hosted clusters to specific operators.
	HostedClustersScopeAnnotation = "hypershift.openshift.io/scope"
	// HostedClusterAnnotation is the annotation key that links a resource to its owning HostedCluster (namespace/name).
	HostedClusterAnnotation = "hypershift.openshift.io/cluster"

	// GCPLabelCluster is the GCP resource label key used to identify the HostedCluster name.
	GCPLabelCluster = "hypershift-openshift-io-cluster"
	// GCPLabelInfraID is the GCP resource label key used to identify the infrastructure ID.
	GCPLabelInfraID = "hypershift-openshift-io-infra-id"
)

Variables

View Source
var (
	BaseResources = []client.Object{
		&capiv1.Cluster{},
	}

	AWSResources = []client.Object{
		&capiaws.AWSCluster{},
		&hyperv1.AWSEndpointService{},
	}

	AzureResources = []client.Object{
		&capiazure.AzureCluster{},
		&capiazure.AzureClusterIdentity{},
	}

	ManagedAzure = []client.Object{
		&secretsstorev1.SecretProviderClass{},
	}

	IBMCloudResources = []client.Object{
		&capiibmv1.IBMVPCCluster{},
	}

	KubevirtResources = []client.Object{
		&capikubevirt.KubevirtCluster{},
	}

	AgentResources = []client.Object{
		&agentv1.AgentCluster{},
	}

	OpenStackResources = []client.Object{
		&capiopenstackv1beta1.OpenStackCluster{},
	}

	AWSNodePoolResources = []client.Object{
		&capiaws.AWSMachineTemplate{},
	}

	AzureNodePoolResources = []client.Object{
		&capiazure.AzureMachineTemplate{},
	}

	AgentNodePoolResources = []client.Object{
		&agentv1.AgentMachineTemplate{},
	}

	OpenStackNodePoolResources = []client.Object{
		&capiopenstackv1beta1.OpenStackMachineTemplate{},
	}
)

Functions

func ApplyAWSLoadBalancerTargetNodesAnnotation

func ApplyAWSLoadBalancerTargetNodesAnnotation(svc *corev1.Service, hcp *hyperv1.HostedControlPlane)

func CollectLBMessageIfNotProvisioned

func CollectLBMessageIfNotProvisioned(svc *corev1.Service, messageCollector events.MessageCollector) (string, error)

func CopyConfigMap

func CopyConfigMap(cm, source *corev1.ConfigMap)

CopyConfigMap copies the .Data field of configMap source into configmap cm.

func CreateTokenForServiceAccount

func CreateTokenForServiceAccount(ctx context.Context, serviceAccount *corev1.ServiceAccount, saClient ServiceAccountTokenCreator) (string, error)

func DeleteAllIfNeeded

func DeleteAllIfNeeded(ctx context.Context, c client.Client, o ...client.Object) error

func DeleteIfNeeded

func DeleteIfNeeded(ctx context.Context, c client.Client, o client.Object) (exists bool, err error)

func DeleteIfNeededWithOptions

func DeleteIfNeededWithOptions(ctx context.Context, c client.Client, o client.Object, opts ...client.DeleteOption) (exists bool, err error)

func DeleteIfNeededWithPredicate

func DeleteIfNeededWithPredicate[T client.Object](ctx context.Context, c client.Client, o T, predicate func(T) bool) (exists bool, err error)

func DeserializeResource

func DeserializeResource(data string, resource runtime.Object, objectTyper runtime.ObjectTyper) error

func EnsureOwnerRef

func EnsureOwnerRef(resource client.Object, ownerRef *metav1.OwnerReference)

func EnsurePullSecret

func EnsurePullSecret(serviceAccount *corev1.ServiceAccount, secretName string)

func ExtractHostedControlPlaneOwnerName

func ExtractHostedControlPlaneOwnerName(ownerRefs []metav1.OwnerReference) string

ExtractHostedControlPlaneOwnerName finds the HostedControlPlane owner reference name from a list of OwnerReferences.

func ExtractLoadBalancerIP

func ExtractLoadBalancerIP(svc *corev1.Service) (string, bool)

ExtractLoadBalancerIP extracts the LoadBalancer IP from a Service's status and returns whether it's valid.

func FindJobCondition

func FindJobCondition(object *batchv1.Job, conditionType batchv1.JobConditionType) *batchv1.JobCondition

func GetHostedClusterManagedResources

func GetHostedClusterManagedResources(platformsInstalled string) []client.Object

func GetNodePoolManagedResources

func GetNodePoolManagedResources(platformsInstalled string) []client.Object

func HasAnnotationWithValue

func HasAnnotationWithValue(obj metav1.Object, key, expectedValue string) bool

HasAnnotationWithValue checks if a Kubernetes object has a specific annotation with a given value.

func HostedClusterFromAnnotation

func HostedClusterFromAnnotation(ctx context.Context, reader client.Reader, obj client.Object) (*hyperv1.HostedCluster, error)

HostedClusterFromAnnotation retrieves the HostedCluster referenced by the HostedClusterAnnotation on the given object. The annotation value must be in "namespace/name" format. This is a shared utility used by platform controllers (e.g. Azure PLS, GCP Private Service Connect) whose custom resources carry this annotation to link back to their owning HostedCluster.

func ParseNodeSelector

func ParseNodeSelector(str string) map[string]string

ParseNodeSelector parses a comma separated string of key=value pairs into a map.

func SerializeResource

func SerializeResource(resource runtime.Object, objectTyper runtime.ObjectTyper) (string, error)

func ServiceAccountClient

func ServiceAccountClient(client kubernetes.Interface, namespace string) corev1client.ServiceAccountInterface

func UpdateObject

func UpdateObject[T client.Object](ctx context.Context, c client.Client, obj T, mutate func() error) error

Types

type ServiceAccountTokenCreator

type ServiceAccountTokenCreator interface {
	Get(ctx context.Context, name string, opts metav1.GetOptions) (*corev1.ServiceAccount, error)
	CreateToken(ctx context.Context, name string, tokenRequest *authenticationv1.TokenRequest, opts metav1.CreateOptions) (*authenticationv1.TokenRequest, error)
}

Jump to

Keyboard shortcuts

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