@@ -17,10 +17,12 @@ limitations under the License.
17
17
package v1beta1
18
18
19
19
import (
20
+ "fmt"
20
21
"reflect"
21
22
22
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
24
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
25
+ "k8s.io/utils/ptr"
24
26
"sigs.k8s.io/controller-runtime/pkg/conversion"
25
27
26
28
bootstrapv1 "sigs.k8s.io/cluster-api/api/bootstrap/kubeadm/v1beta2"
@@ -41,9 +43,26 @@ func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {
41
43
if err != nil {
42
44
return err
43
45
}
46
+
47
+ // Recover intent for bool values converted to *bool.
48
+ initialization := bootstrapv1.KubeadmConfigInitializationStatus {}
49
+ var restoredBootstrapDataSecretCreated * bool
50
+ if restored .Status .Initialization != nil {
51
+ restoredBootstrapDataSecretCreated = restored .Status .Initialization .DataSecretCreated
52
+ }
53
+ clusterv1 .Convert_bool_To_Pointer_bool (src .Status .Ready , ok , restoredBootstrapDataSecretCreated , & initialization .DataSecretCreated )
54
+ if ! reflect .DeepEqual (initialization , bootstrapv1.KubeadmConfigInitializationStatus {}) {
55
+ dst .Status .Initialization = & initialization
56
+ }
57
+ if err := RestoreBoolIntentKubeadmConfigSpec (& src .Spec , & dst .Spec , ok , & restored .Spec ); err != nil {
58
+ return err
59
+ }
60
+
61
+ // Recover other values
44
62
if ok {
45
63
RestoreKubeadmConfigSpec (& restored .Spec , & dst .Spec )
46
64
}
65
+
47
66
// Override restored data with timeouts values already existing in v1beta1 but in other structs.
48
67
src .Spec .ConvertTo (& dst .Spec )
49
68
return nil
@@ -65,6 +84,144 @@ func RestoreKubeadmConfigSpec(restored *bootstrapv1.KubeadmConfigSpec, dst *boot
65
84
}
66
85
}
67
86
87
+ func RestoreBoolIntentKubeadmConfigSpec (src * KubeadmConfigSpec , dst * bootstrapv1.KubeadmConfigSpec , hasRestored bool , restored * bootstrapv1.KubeadmConfigSpec ) error {
88
+ if dst .JoinConfiguration != nil {
89
+ if dst .JoinConfiguration .Discovery .BootstrapToken != nil {
90
+ var restoredUnsafeSkipCAVerification * bool
91
+ if restored .JoinConfiguration != nil && restored .JoinConfiguration .Discovery .BootstrapToken != nil {
92
+ restoredUnsafeSkipCAVerification = restored .JoinConfiguration .Discovery .BootstrapToken .UnsafeSkipCAVerification
93
+ }
94
+ clusterv1 .Convert_bool_To_Pointer_bool (src .JoinConfiguration .Discovery .BootstrapToken .UnsafeSkipCAVerification , hasRestored , restoredUnsafeSkipCAVerification , & dst .JoinConfiguration .Discovery .BootstrapToken .UnsafeSkipCAVerification )
95
+ }
96
+
97
+ if dst .JoinConfiguration .Discovery .File != nil && dst .JoinConfiguration .Discovery .File .KubeConfig != nil {
98
+ if dst .JoinConfiguration .Discovery .File .KubeConfig .Cluster != nil {
99
+ var restoredInsecureSkipTLSVerify * bool
100
+ if restored .JoinConfiguration != nil && restored .JoinConfiguration .Discovery .File != nil && restored .JoinConfiguration .Discovery .File .KubeConfig != nil && restored .JoinConfiguration .Discovery .File .KubeConfig .Cluster != nil {
101
+ restoredInsecureSkipTLSVerify = restored .JoinConfiguration .Discovery .File .KubeConfig .Cluster .InsecureSkipTLSVerify
102
+ }
103
+ clusterv1 .Convert_bool_To_Pointer_bool (src .JoinConfiguration .Discovery .File .KubeConfig .Cluster .InsecureSkipTLSVerify , hasRestored , restoredInsecureSkipTLSVerify , & dst .JoinConfiguration .Discovery .File .KubeConfig .Cluster .InsecureSkipTLSVerify )
104
+ }
105
+ if dst .JoinConfiguration .Discovery .File .KubeConfig .User .Exec != nil {
106
+ var restoredExecProvideClusterInfo * bool
107
+ if restored .JoinConfiguration != nil && restored .JoinConfiguration .Discovery .File != nil && restored .JoinConfiguration .Discovery .File .KubeConfig != nil && restored .JoinConfiguration .Discovery .File .KubeConfig .User .Exec != nil {
108
+ restoredExecProvideClusterInfo = restored .JoinConfiguration .Discovery .File .KubeConfig .User .Exec .ProvideClusterInfo
109
+ }
110
+ clusterv1 .Convert_bool_To_Pointer_bool (src .JoinConfiguration .Discovery .File .KubeConfig .User .Exec .ProvideClusterInfo , hasRestored , restoredExecProvideClusterInfo , & dst .JoinConfiguration .Discovery .File .KubeConfig .User .Exec .ProvideClusterInfo )
111
+ }
112
+ }
113
+ }
114
+
115
+ if dst .ClusterConfiguration != nil {
116
+ for i , volume := range dst .ClusterConfiguration .APIServer .ExtraVolumes {
117
+ var srcVolume * HostPathMount
118
+ if src .ClusterConfiguration != nil {
119
+ for _ , v := range src .ClusterConfiguration .APIServer .ExtraVolumes {
120
+ if v .HostPath == volume .HostPath {
121
+ srcVolume = & v
122
+ break
123
+ }
124
+ }
125
+ }
126
+ if srcVolume == nil {
127
+ return fmt .Errorf ("apiServer extraVolume with hostPath %q not found in source data" , volume .HostPath )
128
+ }
129
+ var restoredVolumeReadOnly * bool
130
+ if restored .ClusterConfiguration != nil {
131
+ for _ , v := range restored .ClusterConfiguration .APIServer .ExtraVolumes {
132
+ if v .HostPath == volume .HostPath {
133
+ restoredVolumeReadOnly = v .ReadOnly
134
+ break
135
+ }
136
+ }
137
+ }
138
+ clusterv1 .Convert_bool_To_Pointer_bool (srcVolume .ReadOnly , hasRestored , restoredVolumeReadOnly , & volume .ReadOnly )
139
+ dst .ClusterConfiguration .APIServer .ExtraVolumes [i ] = volume
140
+ }
141
+ for i , volume := range dst .ClusterConfiguration .ControllerManager .ExtraVolumes {
142
+ var srcVolume * HostPathMount
143
+ if src .ClusterConfiguration != nil {
144
+ for _ , v := range src .ClusterConfiguration .ControllerManager .ExtraVolumes {
145
+ if v .HostPath == volume .HostPath {
146
+ srcVolume = & v
147
+ break
148
+ }
149
+ }
150
+ }
151
+ if srcVolume == nil {
152
+ return fmt .Errorf ("controllerManager extraVolume with hostPath %q not found in source data" , volume .HostPath )
153
+ }
154
+ var restoredVolumeReadOnly * bool
155
+ if restored .ClusterConfiguration != nil {
156
+ for _ , v := range restored .ClusterConfiguration .ControllerManager .ExtraVolumes {
157
+ if v .HostPath == volume .HostPath {
158
+ restoredVolumeReadOnly = v .ReadOnly
159
+ break
160
+ }
161
+ }
162
+ }
163
+ clusterv1 .Convert_bool_To_Pointer_bool (srcVolume .ReadOnly , hasRestored , restoredVolumeReadOnly , & volume .ReadOnly )
164
+ dst .ClusterConfiguration .ControllerManager .ExtraVolumes [i ] = volume
165
+ }
166
+ for i , volume := range dst .ClusterConfiguration .Scheduler .ExtraVolumes {
167
+ var srcVolume * HostPathMount
168
+ if src .ClusterConfiguration != nil {
169
+ for _ , v := range src .ClusterConfiguration .Scheduler .ExtraVolumes {
170
+ if v .HostPath == volume .HostPath {
171
+ srcVolume = & v
172
+ break
173
+ }
174
+ }
175
+ }
176
+ if srcVolume == nil {
177
+ return fmt .Errorf ("scheduler extraVolume with hostPath %q not found in source data" , volume .HostPath )
178
+ }
179
+ var restoredVolumeReadOnly * bool
180
+ if restored .ClusterConfiguration != nil {
181
+ for _ , v := range restored .ClusterConfiguration .Scheduler .ExtraVolumes {
182
+ if v .HostPath == volume .HostPath {
183
+ restoredVolumeReadOnly = v .ReadOnly
184
+ break
185
+ }
186
+ }
187
+ }
188
+ clusterv1 .Convert_bool_To_Pointer_bool (srcVolume .ReadOnly , hasRestored , restoredVolumeReadOnly , & volume .ReadOnly )
189
+ dst .ClusterConfiguration .Scheduler .ExtraVolumes [i ] = volume
190
+ }
191
+ }
192
+
193
+ for i , file := range dst .Files {
194
+ var srcFile * File
195
+ for _ , f := range src .Files {
196
+ if f .Path == file .Path {
197
+ srcFile = & f
198
+ break
199
+ }
200
+ }
201
+ if srcFile == nil {
202
+ return fmt .Errorf ("file with path %q not found in source data" , file .Path )
203
+ }
204
+ var restoredFileAppend * bool
205
+ for _ , f := range restored .Files {
206
+ if f .Path == file .Path {
207
+ restoredFileAppend = f .Append
208
+ break
209
+ }
210
+ }
211
+ clusterv1 .Convert_bool_To_Pointer_bool (srcFile .Append , hasRestored , restoredFileAppend , & file .Append )
212
+ dst .Files [i ] = file
213
+ }
214
+
215
+ if dst .Ignition != nil && dst .Ignition .ContainerLinuxConfig != nil {
216
+ var restoredIgnitionStrict * bool
217
+ if restored .Ignition != nil && restored .Ignition .ContainerLinuxConfig != nil {
218
+ restoredIgnitionStrict = restored .Ignition .ContainerLinuxConfig .Strict
219
+ }
220
+ clusterv1 .Convert_bool_To_Pointer_bool (src .Ignition .ContainerLinuxConfig .Strict , hasRestored , restoredIgnitionStrict , & dst .Ignition .ContainerLinuxConfig .Strict )
221
+ }
222
+ return nil
223
+ }
224
+
68
225
func (src * KubeadmConfigSpec ) ConvertTo (dst * bootstrapv1.KubeadmConfigSpec ) {
69
226
// Override with timeouts values already existing in v1beta1.
70
227
var initControlPlaneComponentHealthCheckSeconds * int32
@@ -143,6 +300,12 @@ func (src *KubeadmConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
143
300
if err != nil {
144
301
return err
145
302
}
303
+ // Recover intent for bool values converted to *bool.
304
+ if err := RestoreBoolIntentKubeadmConfigSpec (& src .Spec .Template .Spec , & dst .Spec .Template .Spec , ok , & restored .Spec .Template .Spec ); err != nil {
305
+ return err
306
+ }
307
+
308
+ // Recover other values
146
309
if ok {
147
310
RestoreKubeadmConfigSpec (& restored .Spec .Template .Spec , & dst .Spec .Template .Spec )
148
311
}
@@ -195,7 +358,7 @@ func Convert_v1beta2_KubeadmConfigStatus_To_v1beta1_KubeadmConfigStatus(in *boot
195
358
196
359
// Move initialization to old fields
197
360
if in .Initialization != nil {
198
- out .Ready = in .Initialization .DataSecretCreated
361
+ out .Ready = ptr . Deref ( in .Initialization .DataSecretCreated , false )
199
362
}
200
363
201
364
// Move new conditions (v1beta2) to the v1beta2 field.
@@ -294,13 +457,7 @@ func Convert_v1beta1_KubeadmConfigStatus_To_v1beta2_KubeadmConfigStatus(in *Kube
294
457
out .Deprecated .V1Beta1 .FailureReason = in .FailureReason
295
458
out .Deprecated .V1Beta1 .FailureMessage = in .FailureMessage
296
459
297
- // Move ready to Initialization
298
- if in .Ready {
299
- if out .Initialization == nil {
300
- out .Initialization = & bootstrapv1.KubeadmConfigInitializationStatus {}
301
- }
302
- out .Initialization .DataSecretCreated = in .Ready
303
- }
460
+ // Move ready to Initialization is implemented in ConvertTo
304
461
return nil
305
462
}
306
463
0 commit comments