Skip to content

Commit f90a0e5

Browse files
committed
implement conversion
1 parent ff246a3 commit f90a0e5

File tree

5 files changed

+310
-185
lines changed

5 files changed

+310
-185
lines changed

config/crd/bases/runtime.cluster.x-k8s.io_extensionconfigs.yaml

Lines changed: 104 additions & 94 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/runtime/api/v1alpha1/conversion.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
2022
"sigs.k8s.io/controller-runtime/pkg/conversion"
2123

24+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
2225
runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1beta2"
2326
)
2427

@@ -33,3 +36,69 @@ func (dst *ExtensionConfig) ConvertFrom(srcRaw conversion.Hub) error {
3336

3437
return Convert_v1beta2_ExtensionConfig_To_v1alpha1_ExtensionConfig(src, dst, nil)
3538
}
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 (v1alpha1).
47+
out.Conditions = nil
48+
49+
// Retrieve legacy conditions (v1alpha1) from the deprecated field.
50+
if in.Deprecated != nil && in.Deprecated.V1Alpha1 != nil {
51+
if in.Deprecated.V1Alpha1.Conditions != nil {
52+
out.Conditions = in.Deprecated.V1Alpha1.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: v1alpha1 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 (v1alpha1) 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.V1Alpha1 == nil {
88+
out.Deprecated.V1Alpha1 = &runtimev1.ExtensionConfigV1Alpha1DeprecatedStatus{}
89+
}
90+
if in.Conditions != nil {
91+
out.Deprecated.V1Alpha1.Conditions = in.Conditions
92+
}
93+
return nil
94+
}
95+
96+
func Convert_v1_Condition_To_v1beta2_Condition(_ *metav1.Condition, _ *clusterv1.Condition, _ apimachineryconversion.Scope) error {
97+
// NOTE: v1beta2 conditions should not be automatically converted into legacy (v1beta2) conditions.
98+
return nil
99+
}
100+
101+
func Convert_v1beta2_Condition_To_v1_Condition(_ *clusterv1.Condition, _ *metav1.Condition, _ apimachineryconversion.Scope) error {
102+
// NOTE: legacy (v1beta2) conditions should not be automatically converted into v1beta2 conditions.
103+
return nil
104+
}

0 commit comments

Comments
 (0)