util

package
v0.0.0-...-2a0af92 Latest Latest
Warning

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

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

Documentation

Overview

Copyright 2025 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2025 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2025 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2025 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2025 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const MapiDeleteMachineAnnotation = "machine.openshift.io/delete-machine"

MapiDeleteMachineAnnotation is the delete-machine annotation used in Machine API. It has an equivalent annotation in Cluster API to convert to.

Variables

View Source
var (
	// LeaseDuration is the default duration for the leader election lease.
	LeaseDuration = metav1.Duration{Duration: 137 * time.Second}
	// RenewDeadline is the default duration for the leader renewal.
	RenewDeadline = metav1.Duration{Duration: 107 * time.Second}
	// RetryPeriod is the default duration for the leader election retrial.
	RetryPeriod = metav1.Duration{Duration: 26 * time.Second}
)

The default durations for the leader election operations.

Functions

func ApplyConfigPatch

func ApplyConfigPatch(applyConfig interface{}) client.Patch

ApplyConfigPatch is a helper function for using applyConfigPatch.

func CAPIMachineSetStatusEqual

func CAPIMachineSetStatusEqual(a, b clusterv1.MachineSetStatus) map[string]any

CAPIMachineSetStatusEqual compares variables a and b, and returns a list of differences, or nil if there are none, for the fields we care about when synchronising MAPI and CAPI Machines.

func ContainsString

func ContainsString(slice []string, s string) bool

ContainsString checks if a given slice of strings contains the provided string.

func DeepCopyMapStringString

func DeepCopyMapStringString(original map[string]string) map[string]string

DeepCopyMapStringString creates a deep copy of a map[string]string.

func EnsureFinalizer

func EnsureFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string) (bool, error)

EnsureFinalizer ensures that the specified finalizer is added to the given object using a Patch operation.

func FilterNamespace

func FilterNamespace(namespace string) predicate.Predicate

FilterNamespace filters a client.Object request, ensuring they are in the namespace provided.

func GenerateInfraMachineTemplateNameWithSpecHash

func GenerateInfraMachineTemplateNameWithSpecHash(name string, spec interface{}) (string, error)

GenerateInfraMachineTemplateNameWithSpecHash generates hash infra machine spec and combines it with infra machine name. Resulting name is "<name>-<hash>" where <hash> is a hex string of 8 characters. The hash function is FNV-1a 32-bit.

func GetCondition

func GetCondition(obj client.Object, conditionType string) (*metav1.Condition, error)

GetCondition retrieves a specific condition from a client.Object.

func GetConditionStatus

func GetConditionStatus(obj client.Object, conditionType string) (corev1.ConditionStatus, error)

GetConditionStatus returns the status for the condition.

func GetInfra

GetInfra returns the infrastructure resource.

func GetMAPIMachineSetCondition

func GetMAPIMachineSetCondition(conditions []machinev1beta1.Condition, conditionType string) *machinev1beta1.Condition

GetMAPIMachineSetCondition retrieves a specific condition from a list of MAPI MachineSet conditions.

func GetPlatform

func GetPlatform(ctx context.Context, infra *configv1.Infrastructure) (configv1.PlatformType, error)

GetPlatform returns the platform type from the infrastructure resource.

func GetReferencedObject

func GetReferencedObject(ctx context.Context, c client.Reader, scheme *runtime.Scheme, ref corev1.ObjectReference) (client.Object, error)

GetReferencedObject retrieves a Kubernetes object dynamically based on an ObjectReference.

func GetReleaseVersion

func GetReleaseVersion() string

GetReleaseVersion is used to get the current release version from the env. This is used to identify which version of feature gates should be observed, and to know which version to set in the operator status.

func GetResourceVersion

func GetResourceVersion(obj client.Object) string

GetResourceVersion returns the object ResourceVersion or the zero value for it.

func IsNilObject

func IsNilObject(obj client.Object) bool

IsNilObject checks whether a client.Object is nil or not.

func IsPatchRequired

func IsPatchRequired(origObj client.Object, patch client.Patch) (bool, error)

IsPatchRequired returns true if the calculated patch data is not an empty JSON object.

func MAPIMachineSetStatusEqual

func MAPIMachineSetStatusEqual(a, b machinev1beta1.MachineSetStatus) map[string]any

MAPIMachineSetStatusEqual compares variables a and b, and returns a list of differences, or nil if there are none, for the fields we care about when synchronising MAPI and CAPI Machines.

func MergeMaps

func MergeMaps(m1, m2 map[string]string) map[string]string

MergeMaps merges two maps, with values from the second map taking precedence.

func ObjectMetaEqual

func ObjectMetaEqual(a, b metav1.ObjectMeta) map[string]any

ObjectMetaEqual compares variables a and b, and returns a list of differences, or nil if there are none, for the fields we care about when synchronising MAPI and CAPI Machines.

func ReadImagesFile

func ReadImagesFile(imagesFile string) (map[string]string, error)

ReadImagesFile reads the images file and returns the map of container images.

func ReadProvidersFile

func ReadProvidersFile(providersFile string) (map[string]bool, error)

ReadProvidersFile reads the providers file and returns the map of supported providers.

func RemoveAnnotation

func RemoveAnnotation(obj client.Object, key string)

RemoveAnnotation deletes a specific annotation from a client.Object.

func RemoveFinalizer

func RemoveFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string) (bool, error)

RemoveFinalizer ensures that the specified finalizer is removed from the given object using a Patch operation.

func ResolveCAPIMachineSetFromInfraMachineTemplate

func ResolveCAPIMachineSetFromInfraMachineTemplate(namespace string) func(context.Context, client.Object) []reconcile.Request

ResolveCAPIMachineSetFromInfraMachineTemplate resolves a synchronized MachineSet from an InfrastructureMachineTemplate. It takes a client.Object (expecting a CAPI InfrastructureMachineTemplate) and checks if it has the machine.openshift.io/cluster-api-machineset label. If present, it returns a reconcile.Request for the corresponding MachineSet in the MAPI namespace to trigger reconciliation of the mirror MAPI MachineSet.

func RewriteNamespace

func RewriteNamespace(namespace string) func(context.Context, client.Object) []reconcile.Request

RewriteNamespace takes a client.Object and returns a reconcile.Request for it in the namespace provided.

It is intended for use with CAPI Machines and MachineSet requests, where we expect there to be a mirror object in the MAPI namespace.

func SetLastTransitionTime

func SetLastTransitionTime(condType machinev1beta1.ConditionType, conditions []machinev1beta1.Condition, conditionAc *machinev1applyconfigs.ConditionApplyConfiguration)

SetLastTransitionTime determines if the last transition time should be set or updated for a given condition type.

func SetMAPIMachineSetCondition

func SetMAPIMachineSetCondition(conditions []machinev1beta1.Condition, condition *machinev1beta1.Condition) []machinev1beta1.Condition

SetMAPIMachineSetCondition sets a condition in a list of MAPI MachineSet conditions. If the condition already exists and state (Status, Reason, Message) has changed: - if the lasttransitiontime is not set, it sets it to the current time - if the lasttransitiontime is set, it updates it with the one of the newly provided condition lasttransitiontime. If the condition state has not changed, it preserves the existing LastTransitionTime. If the condition does not exist, it adds it. This function behaves similarly to conditions.Set() for CAPI conditions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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