@@ -17,9 +17,11 @@ limitations under the License.
1717package v1alpha3
1818
1919import (
20+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2021 apiconversion "k8s.io/apimachinery/pkg/conversion"
2122 "sigs.k8s.io/controller-runtime/pkg/conversion"
2223
24+ clusterv1alpha3 "sigs.k8s.io/cluster-api/internal/api/core/v1alpha3"
2325 infrav1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta2"
2426 utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2527)
@@ -31,6 +33,15 @@ func (src *DockerCluster) ConvertTo(dstRaw conversion.Hub) error {
3133 return err
3234 }
3335
36+ // Reset conditions from autogenerated conversions
37+ // NOTE: v1alpha3 conditions should not be automatically be converted into v1beta2 conditions.
38+ dst .Status .Conditions = nil
39+ if src .Status .Conditions != nil {
40+ dst .Status .Deprecated = & infrav1.DockerClusterDeprecatedStatus {}
41+ dst .Status .Deprecated .V1Beta1 = & infrav1.DockerClusterV1Beta1DeprecatedStatus {}
42+ clusterv1alpha3 .Convert_v1alpha3_Conditions_To_v1beta2_Deprecated_V1Beta1_Conditions (& src .Status .Conditions , & dst .Status .Deprecated .V1Beta1 .Conditions )
43+ }
44+
3445 // Manually restore data.
3546 restored := & infrav1.DockerCluster {}
3647 if ok , err := utilconversion .UnmarshalData (src , restored ); err != nil || ! ok {
@@ -48,7 +59,8 @@ func (src *DockerCluster) ConvertTo(dstRaw conversion.Hub) error {
4859 if restored .Spec .LoadBalancer .CustomHAProxyConfigTemplateRef != nil {
4960 dst .Spec .LoadBalancer .CustomHAProxyConfigTemplateRef = restored .Spec .LoadBalancer .CustomHAProxyConfigTemplateRef
5061 }
51- dst .Status .V1Beta2 = restored .Status .V1Beta2
62+
63+ dst .Status .Conditions = restored .Status .Conditions
5264
5365 return nil
5466}
@@ -60,6 +72,13 @@ func (dst *DockerCluster) ConvertFrom(srcRaw conversion.Hub) error {
6072 return err
6173 }
6274
75+ // Reset conditions from autogenerated conversions
76+ // NOTE: v1beta2 conditions should not be automatically be converted into v1alpha3 conditions.
77+ dst .Status .Conditions = nil
78+ if src .Status .Deprecated != nil && src .Status .Deprecated .V1Beta1 != nil && src .Status .Deprecated .V1Beta1 .Conditions != nil {
79+ clusterv1alpha3 .Convert_v1beta2_Deprecated_V1Beta1_Conditions_To_v1alpha3_Conditions (& src .Status .Deprecated .V1Beta1 .Conditions , & dst .Status .Conditions )
80+ }
81+
6382 // Preserve Hub data on down-conversion except for metadata
6483 if err := utilconversion .MarshalData (src , dst ); err != nil {
6584 return err
@@ -75,6 +94,16 @@ func (src *DockerMachine) ConvertTo(dstRaw conversion.Hub) error {
7594 return err
7695 }
7796
97+ // Reset conditions from autogenerated conversions
98+ // NOTE: v1alpha3 conditions should not be automatically be converted into v1beta2 conditions.
99+ dst .Status .Conditions = nil
100+
101+ if src .Status .Conditions != nil {
102+ dst .Status .Deprecated = & infrav1.DockerMachineDeprecatedStatus {}
103+ dst .Status .Deprecated .V1Beta1 = & infrav1.DockerMachineV1Beta1DeprecatedStatus {}
104+ clusterv1alpha3 .Convert_v1alpha3_Conditions_To_v1beta2_Deprecated_V1Beta1_Conditions (& src .Status .Conditions , & dst .Status .Deprecated .V1Beta1 .Conditions )
105+ }
106+
78107 // Manually restore data.
79108 restored := & infrav1.DockerMachine {}
80109 if ok , err := utilconversion .UnmarshalData (src , restored ); err != nil || ! ok {
@@ -84,7 +113,8 @@ func (src *DockerMachine) ConvertTo(dstRaw conversion.Hub) error {
84113 if restored .Spec .BootstrapTimeout != nil {
85114 dst .Spec .BootstrapTimeout = restored .Spec .BootstrapTimeout
86115 }
87- dst .Status .V1Beta2 = restored .Status .V1Beta2
116+
117+ dst .Status .Conditions = restored .Status .Conditions
88118
89119 return nil
90120}
@@ -96,6 +126,13 @@ func (dst *DockerMachine) ConvertFrom(srcRaw conversion.Hub) error {
96126 return err
97127 }
98128
129+ // Reset conditions from autogenerated conversions
130+ // NOTE: v1beta2 conditions should not be automatically be converted into v1alpha3 conditions.
131+ dst .Status .Conditions = nil
132+ if src .Status .Deprecated != nil && src .Status .Deprecated .V1Beta1 != nil && src .Status .Deprecated .V1Beta1 .Conditions != nil {
133+ clusterv1alpha3 .Convert_v1beta2_Deprecated_V1Beta1_Conditions_To_v1alpha3_Conditions (& src .Status .Deprecated .V1Beta1 .Conditions , & dst .Status .Conditions )
134+ }
135+
99136 if err := utilconversion .MarshalData (src , dst ); err != nil {
100137 return err
101138 }
@@ -161,3 +198,13 @@ func Convert_v1beta2_DockerClusterStatus_To_v1alpha3_DockerClusterStatus(in *inf
161198func Convert_v1beta2_DockerMachineStatus_To_v1alpha3_DockerMachineStatus (in * infrav1.DockerMachineStatus , out * DockerMachineStatus , s apiconversion.Scope ) error {
162199 return autoConvert_v1beta2_DockerMachineStatus_To_v1alpha3_DockerMachineStatus (in , out , s )
163200}
201+
202+ // Implement local conversion func because conversion-gen is not aware of conversion func in other packages (see https://github.com/kubernetes/code-generator/issues/94)
203+
204+ func Convert_v1alpha3_Condition_To_v1_Condition (in * clusterv1alpha3.Condition , out * metav1.Condition , s apiconversion.Scope ) error {
205+ return clusterv1alpha3 .Convert_v1alpha3_Condition_To_v1_Condition (in , out , s )
206+ }
207+
208+ func Convert_v1_Condition_To_v1alpha3_Condition (in * metav1.Condition , out * clusterv1alpha3.Condition , s apiconversion.Scope ) error {
209+ return clusterv1alpha3 .Convert_v1_Condition_To_v1alpha3_Condition (in , out , s )
210+ }
0 commit comments