Skip to content

Commit 173d580

Browse files
⚠️ Change bool to *bool for all API types (#12436)
* Change bool to *bool for all API types * Address feedback * More feedback * More feedback
1 parent b54ecba commit 173d580

File tree

125 files changed

+2804
-1106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+2804
-1106
lines changed

api/bootstrap/kubeadm/v1beta1/conversion.go

Lines changed: 165 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"fmt"
2021
"reflect"
2122

2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
25+
"k8s.io/utils/ptr"
2426
"sigs.k8s.io/controller-runtime/pkg/conversion"
2527

2628
bootstrapv1 "sigs.k8s.io/cluster-api/api/bootstrap/kubeadm/v1beta2"
@@ -41,9 +43,26 @@ func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {
4143
if err != nil {
4244
return err
4345
}
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
4462
if ok {
4563
RestoreKubeadmConfigSpec(&restored.Spec, &dst.Spec)
4664
}
65+
4766
// Override restored data with timeouts values already existing in v1beta1 but in other structs.
4867
src.Spec.ConvertTo(&dst.Spec)
4968
return nil
@@ -65,6 +84,144 @@ func RestoreKubeadmConfigSpec(restored *bootstrapv1.KubeadmConfigSpec, dst *boot
6584
}
6685
}
6786

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+
68225
func (src *KubeadmConfigSpec) ConvertTo(dst *bootstrapv1.KubeadmConfigSpec) {
69226
// Override with timeouts values already existing in v1beta1.
70227
var initControlPlaneComponentHealthCheckSeconds *int32
@@ -143,6 +300,12 @@ func (src *KubeadmConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
143300
if err != nil {
144301
return err
145302
}
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
146309
if ok {
147310
RestoreKubeadmConfigSpec(&restored.Spec.Template.Spec, &dst.Spec.Template.Spec)
148311
}
@@ -195,7 +358,7 @@ func Convert_v1beta2_KubeadmConfigStatus_To_v1beta1_KubeadmConfigStatus(in *boot
195358

196359
// Move initialization to old fields
197360
if in.Initialization != nil {
198-
out.Ready = in.Initialization.DataSecretCreated
361+
out.Ready = ptr.Deref(in.Initialization.DataSecretCreated, false)
199362
}
200363

201364
// Move new conditions (v1beta2) to the v1beta2 field.
@@ -294,13 +457,7 @@ func Convert_v1beta1_KubeadmConfigStatus_To_v1beta2_KubeadmConfigStatus(in *Kube
294457
out.Deprecated.V1Beta1.FailureReason = in.FailureReason
295458
out.Deprecated.V1Beta1.FailureMessage = in.FailureMessage
296459

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
304461
return nil
305462
}
306463

0 commit comments

Comments
 (0)