|
| 1 | +/* |
| 2 | +Copyright 2025 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + apimachineryconversion "k8s.io/apimachinery/pkg/conversion" |
| 22 | + "sigs.k8s.io/controller-runtime/pkg/conversion" |
| 23 | + |
| 24 | + clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 25 | + runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1beta2" |
| 26 | +) |
| 27 | + |
| 28 | +func (src *ExtensionConfig) ConvertTo(dstRaw conversion.Hub) error { |
| 29 | + dst := dstRaw.(*runtimev1.ExtensionConfig) |
| 30 | + |
| 31 | + return Convert_v1alpha1_ExtensionConfig_To_v1beta2_ExtensionConfig(src, dst, nil) |
| 32 | +} |
| 33 | + |
| 34 | +func (dst *ExtensionConfig) ConvertFrom(srcRaw conversion.Hub) error { |
| 35 | + src := srcRaw.(*runtimev1.ExtensionConfig) |
| 36 | + |
| 37 | + return Convert_v1beta2_ExtensionConfig_To_v1alpha1_ExtensionConfig(src, dst, nil) |
| 38 | +} |
| 39 | + |
| 40 | +func Convert_v1beta2_ExtensionConfigStatus_To_v1alpha1_ExtensionConfigStatus(in *runtimev1.ExtensionConfigStatus, out *ExtensionConfigStatus, s apimachineryconversion.Scope) error { |
| 41 | + if err := autoConvert_v1beta2_ExtensionConfigStatus_To_v1alpha1_ExtensionConfigStatus(in, out, s); err != nil { |
| 42 | + return err |
| 43 | + } |
| 44 | + |
| 45 | + // Reset conditions from autogenerated conversions |
| 46 | + // NOTE: v1beta2 conditions should not be automatically be converted into legacy conditions (v1beta1). |
| 47 | + out.Conditions = nil |
| 48 | + |
| 49 | + // Retrieve legacy conditions (v1beta1) from the deprecated field. |
| 50 | + if in.Deprecated != nil && in.Deprecated.V1Beta1 != nil { |
| 51 | + if in.Deprecated.V1Beta1.Conditions != nil { |
| 52 | + clusterv1beta1.Convert_v1beta2_Deprecated_V1Beta1_Conditions_To_v1beta1_Conditions(&in.Deprecated.V1Beta1.Conditions, &out.Conditions) |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + // Move new conditions (v1beta2) to the v1beta2 field. |
| 57 | + if in.Conditions == nil { |
| 58 | + return nil |
| 59 | + } |
| 60 | + out.V1Beta2 = &ExtensionConfigV1Beta2Status{} |
| 61 | + out.V1Beta2.Conditions = in.Conditions |
| 62 | + return nil |
| 63 | +} |
| 64 | + |
| 65 | +func Convert_v1alpha1_ExtensionConfigStatus_To_v1beta2_ExtensionConfigStatus(in *ExtensionConfigStatus, out *runtimev1.ExtensionConfigStatus, s apimachineryconversion.Scope) error { |
| 66 | + if err := autoConvert_v1alpha1_ExtensionConfigStatus_To_v1beta2_ExtensionConfigStatus(in, out, s); err != nil { |
| 67 | + return err |
| 68 | + } |
| 69 | + |
| 70 | + // Reset conditions from autogenerated conversions |
| 71 | + // NOTE: v1beta1 conditions should not be automatically be converted into v1beta2 conditions. |
| 72 | + out.Conditions = nil |
| 73 | + |
| 74 | + // Retrieve new conditions (v1beta2) from the v1beta2 field. |
| 75 | + if in.V1Beta2 != nil { |
| 76 | + out.Conditions = in.V1Beta2.Conditions |
| 77 | + } |
| 78 | + |
| 79 | + // Move legacy conditions (v1beta1) to the deprecated field. |
| 80 | + if in.Conditions == nil { |
| 81 | + return nil |
| 82 | + } |
| 83 | + |
| 84 | + if out.Deprecated == nil { |
| 85 | + out.Deprecated = &runtimev1.ExtensionConfigDeprecatedStatus{} |
| 86 | + } |
| 87 | + if out.Deprecated.V1Beta1 == nil { |
| 88 | + out.Deprecated.V1Beta1 = &runtimev1.ExtensionConfigV1Beta1DeprecatedStatus{} |
| 89 | + } |
| 90 | + if in.Conditions != nil { |
| 91 | + clusterv1beta1.Convert_v1beta1_Conditions_To_v1beta2_Deprecated_V1Beta1_Conditions(&in.Conditions, &out.Deprecated.V1Beta1.Conditions) |
| 92 | + } |
| 93 | + return nil |
| 94 | +} |
| 95 | + |
| 96 | +func Convert_v1_Condition_To_v1beta1_Condition(in *metav1.Condition, out *clusterv1beta1.Condition, s apimachineryconversion.Scope) error { |
| 97 | + return clusterv1beta1.Convert_v1_Condition_To_v1beta1_Condition(in, out, s) |
| 98 | +} |
| 99 | + |
| 100 | +func Convert_v1beta1_Condition_To_v1_Condition(in *clusterv1beta1.Condition, out *metav1.Condition, s apimachineryconversion.Scope) error { |
| 101 | + return clusterv1beta1.Convert_v1beta1_Condition_To_v1_Condition(in, out, s) |
| 102 | +} |
0 commit comments