@@ -17,9 +17,11 @@ limitations under the License.
17
17
package v1alpha3
18
18
19
19
import (
20
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20
21
apiconversion "k8s.io/apimachinery/pkg/conversion"
21
22
"sigs.k8s.io/controller-runtime/pkg/conversion"
22
23
24
+ clusterv1alpha3 "sigs.k8s.io/cluster-api/internal/api/core/v1alpha3"
23
25
infrav1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta2"
24
26
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
25
27
)
@@ -31,6 +33,15 @@ func (src *DockerCluster) ConvertTo(dstRaw conversion.Hub) error {
31
33
return err
32
34
}
33
35
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
+
34
45
// Manually restore data.
35
46
restored := & infrav1.DockerCluster {}
36
47
if ok , err := utilconversion .UnmarshalData (src , restored ); err != nil || ! ok {
@@ -48,7 +59,8 @@ func (src *DockerCluster) ConvertTo(dstRaw conversion.Hub) error {
48
59
if restored .Spec .LoadBalancer .CustomHAProxyConfigTemplateRef != nil {
49
60
dst .Spec .LoadBalancer .CustomHAProxyConfigTemplateRef = restored .Spec .LoadBalancer .CustomHAProxyConfigTemplateRef
50
61
}
51
- dst .Status .V1Beta2 = restored .Status .V1Beta2
62
+
63
+ dst .Status .Conditions = restored .Status .Conditions
52
64
53
65
return nil
54
66
}
@@ -60,6 +72,13 @@ func (dst *DockerCluster) ConvertFrom(srcRaw conversion.Hub) error {
60
72
return err
61
73
}
62
74
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
+
63
82
// Preserve Hub data on down-conversion except for metadata
64
83
if err := utilconversion .MarshalData (src , dst ); err != nil {
65
84
return err
@@ -75,6 +94,16 @@ func (src *DockerMachine) ConvertTo(dstRaw conversion.Hub) error {
75
94
return err
76
95
}
77
96
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
+
78
107
// Manually restore data.
79
108
restored := & infrav1.DockerMachine {}
80
109
if ok , err := utilconversion .UnmarshalData (src , restored ); err != nil || ! ok {
@@ -84,7 +113,8 @@ func (src *DockerMachine) ConvertTo(dstRaw conversion.Hub) error {
84
113
if restored .Spec .BootstrapTimeout != nil {
85
114
dst .Spec .BootstrapTimeout = restored .Spec .BootstrapTimeout
86
115
}
87
- dst .Status .V1Beta2 = restored .Status .V1Beta2
116
+
117
+ dst .Status .Conditions = restored .Status .Conditions
88
118
89
119
return nil
90
120
}
@@ -96,6 +126,13 @@ func (dst *DockerMachine) ConvertFrom(srcRaw conversion.Hub) error {
96
126
return err
97
127
}
98
128
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
+
99
136
if err := utilconversion .MarshalData (src , dst ); err != nil {
100
137
return err
101
138
}
@@ -161,3 +198,13 @@ func Convert_v1beta2_DockerClusterStatus_To_v1alpha3_DockerClusterStatus(in *inf
161
198
func Convert_v1beta2_DockerMachineStatus_To_v1alpha3_DockerMachineStatus (in * infrav1.DockerMachineStatus , out * DockerMachineStatus , s apiconversion.Scope ) error {
162
199
return autoConvert_v1beta2_DockerMachineStatus_To_v1alpha3_DockerMachineStatus (in , out , s )
163
200
}
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