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 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 2026 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 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.
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
- Variables
- func ApplyConfigPatch(applyConfig interface{}) client.Patch
- func AsTerminalWithReasonError(err error) *terminalWithReasonError
- func ContainsString(slice []string, s string) bool
- func DeepCopyMapStringString(original map[string]string) map[string]string
- func EnsureCAPIConditions(existing conditions.Setter, converted conditions.Setter)
- func EnsureCAPIDeprecatedV1Beta1Conditions(existing deprecatedv1beta1conditions.Setter, ...)
- func EnsureCAPIV1Beta1Conditions(existing v1beta1conditions.Setter, converted v1beta1conditions.Setter)
- func EnsureCAPIV1Beta2Conditions(existing v1beta2conditions.Setter, converted v1beta2conditions.Setter)
- func EnsureFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string) (bool, error)
- func FilterNamespace(namespace string) predicate.Predicate
- func GenerateInfraMachineTemplateNameWithSpecHash(name string, spec interface{}) (string, error)
- func GetCondition(obj client.Object, conditionType string) (*metav1.Condition, error)
- func GetConditionStatus(obj client.Object, conditionType string) (corev1.ConditionStatus, error)
- func GetFeatureGates(ctx context.Context, log logr.Logger, componentName string, ...) (featuregates.FeatureGate, error)
- func GetInfra(ctx context.Context, cl client.Reader) (*configv1.Infrastructure, error)
- func GetMAPICondition(conditions []mapiv1beta1.Condition, conditionType string) *mapiv1beta1.Condition
- func GetPlatform(ctx context.Context, cl client.Reader) (configv1.PlatformType, *configv1.Infrastructure, error)
- func GetPlatformFromInfra(infra *configv1.Infrastructure) (configv1.PlatformType, error)
- func GetReferencedObject(ctx context.Context, c client.Reader, scheme *runtime.Scheme, ...) (client.Object, error)
- func GetReleaseVersion() string
- func GetResourceVersion(obj client.Object) string
- func IsCAPIEnabledForPlatform(currentFeatureGates featuregates.FeatureGate, platform configv1.PlatformType) bool
- func IsControlPlaneMAPIMachine(machine *mapiv1beta1.Machine) bool
- func IsNilObject(obj client.Object) bool
- func IsPatchRequired(origObj client.Object, patch client.Patch) (bool, error)
- func IsTerminalWithReasonError(err error) bool
- func IterFilter[T any](i iter.Seq[T], filter func(T) bool) iter.Seq[T]
- func MergeMaps(m1, m2 map[string]string) map[string]string
- func NewDefaultDiffer(opts ...DiffOption) *differ
- func ReadImagesFile(imagesFile string) (map[string]string, error)
- func RemoveAnnotation(obj client.Object, key string)
- func RemoveFinalizer(ctx context.Context, c client.Client, obj client.Object, finalizer string) (bool, error)
- func ResolveCAPIMachineFromInfraMachine(namespace string) func(context.Context, client.Object) []reconcile.Request
- func ResolveCAPIMachineSetFromInfraMachineTemplate(namespace string) func(context.Context, client.Object) []reconcile.Request
- func RewriteNamespace(namespace string) func(context.Context, client.Object) []reconcile.Request
- func SetLastTransitionTime(condType mapiv1beta1.ConditionType, conditions []mapiv1beta1.Condition, ...)
- func SetLastTransitionTimeMetaV1(now metav1.Time, currentConditions []metav1.Condition, ...) *metav1applyconfig.ConditionApplyConfiguration
- func SetMAPICondition(conditions []mapiv1beta1.Condition, condition *mapiv1beta1.Condition) []mapiv1beta1.Condition
- func SetMAPIProviderCondition(conditions []metav1.Condition, condition *metav1.Condition) []metav1.Condition
- func SliceFilter[A any](source []A, fn func(A) bool) []A
- func SliceMap[A, B any](source []A, fn func(A) B) []B
- func TerminalWithReasonError(err error, reason string) error
- type DiffOption
- type DiffResult
- type InfraTypes
Constants ¶
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 ¶
var ( // ErrUnsupportedPlatform is returned when the platform is not supported. ErrUnsupportedPlatform = errors.New("unsupported platform") )
Functions ¶
func ApplyConfigPatch ¶
ApplyConfigPatch is a helper function for using applyConfigPatch.
func AsTerminalWithReasonError ¶
func AsTerminalWithReasonError(err error) *terminalWithReasonError
AsTerminalWithReasonError checks if the error is a terminal error with a reason. If it is, it returns the terminal error with a reason. If it is not, it returns nil.
func ContainsString ¶
ContainsString checks if a given slice of strings contains the provided string.
func DeepCopyMapStringString ¶
DeepCopyMapStringString creates a deep copy of a map[string]string.
func EnsureCAPIConditions ¶
func EnsureCAPIConditions(existing conditions.Setter, converted conditions.Setter)
EnsureCAPIConditions iterates over all CAPI v1beta2 conditions and sets them on the converted object.
func EnsureCAPIDeprecatedV1Beta1Conditions ¶
func EnsureCAPIDeprecatedV1Beta1Conditions(existing deprecatedv1beta1conditions.Setter, converted deprecatedv1beta1conditions.Setter)
EnsureCAPIDeprecatedV1Beta1Conditions iterates over all CAPI v1beta1 conditions and sets them on the converted object.
func EnsureCAPIV1Beta1Conditions ¶
func EnsureCAPIV1Beta1Conditions(existing v1beta1conditions.Setter, converted v1beta1conditions.Setter)
EnsureCAPIV1Beta1Conditions iterates over all CAPI v1beta1 conditions and sets them on the converted object.
func EnsureCAPIV1Beta2Conditions ¶
func EnsureCAPIV1Beta2Conditions(existing v1beta2conditions.Setter, converted v1beta2conditions.Setter)
EnsureCAPIV1Beta2Conditions iterates over all CAPI v1beta2 conditions and sets them on the converted object.
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 ¶
FilterNamespace filters a client.Object request, ensuring they are in the namespace provided.
func GenerateInfraMachineTemplateNameWithSpecHash ¶
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 ¶
GetCondition retrieves a specific condition from a client.Object.
func GetConditionStatus ¶
GetConditionStatus returns the status for the condition.
func GetFeatureGates ¶
func GetFeatureGates(ctx context.Context, log logr.Logger, componentName string, restConfig *rest.Config, ctxCancel context.CancelFunc) (featuregates.FeatureGate, error)
GetFeatureGates returns feature gates for the current release version. Calling this function will additionally start two background goroutines which together watch cluster feature gates and call ctxCancel() if they change. These goroutines will be cancelled when the given context is cancelled.
func GetMAPICondition ¶
func GetMAPICondition(conditions []mapiv1beta1.Condition, conditionType string) *mapiv1beta1.Condition
GetMAPICondition retrieves a specific condition from a list of MAPI conditions.
func GetPlatform ¶
func GetPlatform(ctx context.Context, cl client.Reader) (configv1.PlatformType, *configv1.Infrastructure, error)
GetPlatform returns the platform type and the infrastructure resource.
func GetPlatformFromInfra ¶
func GetPlatformFromInfra(infra *configv1.Infrastructure) (configv1.PlatformType, error)
GetPlatformFromInfra 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 ¶
GetResourceVersion returns the object ResourceVersion or the zero value for it.
func IsCAPIEnabledForPlatform ¶
func IsCAPIEnabledForPlatform(currentFeatureGates featuregates.FeatureGate, platform configv1.PlatformType) bool
IsCAPIEnabledForPlatform returns true if CAPI support is enabled for the given platform in the given feature gates.
func IsControlPlaneMAPIMachine ¶
func IsControlPlaneMAPIMachine(machine *mapiv1beta1.Machine) bool
IsControlPlaneMAPIMachine returns true if the given MAPI Machine is a control plane machine.
func IsNilObject ¶
IsNilObject checks whether a client.Object is nil or not.
func IsPatchRequired ¶
IsPatchRequired returns true if the calculated patch data is not an empty JSON object.
func IsTerminalWithReasonError ¶
IsTerminalWithReasonError checks if the error is a terminal error with a reason.
func IterFilter ¶
IterFilter returns a new iterator that applies a filter to the input iterator.
func NewDefaultDiffer ¶
func NewDefaultDiffer(opts ...DiffOption) *differ
NewDefaultDiffer creates a new default differ with the default options.
func ReadImagesFile ¶
ReadImagesFile reads the images file and returns the map of container images.
func RemoveAnnotation ¶
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 ResolveCAPIMachineFromInfraMachine ¶
func ResolveCAPIMachineFromInfraMachine(namespace string) func(context.Context, client.Object) []reconcile.Request
ResolveCAPIMachineFromInfraMachine resolves a CAPI Machine from an InfraMachine. It takes client.Object, and uses owner references to determine the owning CAPI machine. If one is found, it returns a reconcile.Request for the corresponding MAPI Machine in the MAPI namespace to trigger reconciliation of the mirror MAPI Machine.
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 ¶
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 mapiv1beta1.ConditionType, conditions []mapiv1beta1.Condition, conditionAc *machinev1applyconfigs.ConditionApplyConfiguration)
SetLastTransitionTime determines if the last transition time should be set or updated for a given condition type.
func SetLastTransitionTimeMetaV1 ¶
func SetLastTransitionTimeMetaV1(now metav1.Time, currentConditions []metav1.Condition, conditionAC *metav1applyconfig.ConditionApplyConfiguration) *metav1applyconfig.ConditionApplyConfiguration
SetLastTransitionTimeMetaV1 sets the last transition time of a condition apply configuration. It retains the last transition time of the current condition if it exists and matches new status, reason, and message values. If it does not exist, it sets the last transition time to the current time.
func SetMAPICondition ¶
func SetMAPICondition(conditions []mapiv1beta1.Condition, condition *mapiv1beta1.Condition) []mapiv1beta1.Condition
SetMAPICondition sets a condition in a list of MAPI 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.
func SetMAPIProviderCondition ¶
func SetMAPIProviderCondition(conditions []metav1.Condition, condition *metav1.Condition) []metav1.Condition
SetMAPIProviderCondition sets a condition in a list of Machine API 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 Cluster API conditions.
func SliceFilter ¶
SliceFilter applies a filter function to each element of a slice and returns a new slice.
func SliceMap ¶
func SliceMap[A, B any](source []A, fn func(A) B) []B
SliceMap applies a map function to each element of a slice and returns a new slice.
func TerminalWithReasonError ¶
TerminalWithReasonError returns a terminal error with a reason. This will prevent the reconcile from being retried.
Types ¶
type DiffOption ¶
type DiffOption func(*differ)
DiffOption is the type for options to configure the differ.
func WithConditionsAsMap ¶
func WithConditionsAsMap() DiffOption
WithConditionsAsMap ensures the conditions are converted to maps for comparison.
func WithIgnoreConditionType ¶
func WithIgnoreConditionType(conditionType string) DiffOption
WithIgnoreConditionType conditionType configures the differ to ignore the condition of the given type when executing Diff.
func WithIgnoreConditionsLastTransitionTime ¶
func WithIgnoreConditionsLastTransitionTime() DiffOption
WithIgnoreConditionsLastTransitionTime configures the differ to ignore LastTransitionTime for conditions when executing Diff.
func WithIgnoreField ¶
func WithIgnoreField(path ...string) DiffOption
WithIgnoreField adds a path to the list of paths to ignore when executing Diff.
func WithProviderSpec ¶
func WithProviderSpec(platform configv1.PlatformType, path []string, marshalProviderSpec func(platform configv1.PlatformType, rawExtension *runtime.RawExtension) (any, error)) DiffOption
WithProviderSpec configures the differ to separately diff .spec.providerSpec.
type DiffResult ¶
type DiffResult interface {
HasChanges() bool
String() string
HasMetadataChanges() bool
HasSpecChanges() bool
HasProviderSpecChanges() bool
HasStatusChanges() bool
}
DiffResult is the interface that represents the result of a diff operation.
type InfraTypes ¶
type InfraTypes interface {
// Machine returns a new Machine object for the current platform.
Machine() client.Object
// Cluster returns a new Cluster object for the current platform.
Cluster() client.Object
// Template returns a new MachineTemplate object for the current platform.
Template() client.Object
// ClusterTemplate returns a new ClusterTemplate object for the current platform.
ClusterTemplate() client.Object
}
InfraTypes provides infrastructure object constructors for the current platform.
func GetCAPITypesForInfrastructure ¶
func GetCAPITypesForInfrastructure(infra *configv1.Infrastructure) (InfraTypes, configv1.PlatformType, error)
GetCAPITypesForInfrastructure returns the infrastructure objects for a given platform. Returns ErrUnsupportedPlatform for unsupported platforms.