Skip to content

Commit b8cf724

Browse files
committed
Fix conversion issue in KubeadmControlPlaneTemplate with
rolloutStrategy.type Signed-off-by: Stefan Büringer [email protected]
1 parent a5e21a3 commit b8cf724

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

api/controlplane/kubeadm/v1beta1/conversion.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,15 @@ func Convert_v1beta1_KubeadmControlPlaneTemplateResourceSpec_To_v1beta2_KubeadmC
287287
out.Rollout.After = *in.RolloutAfter
288288
}
289289
if in.RolloutStrategy != nil {
290-
out.Rollout.Strategy.Type = controlplanev1.KubeadmControlPlaneRolloutStrategyType(in.RolloutStrategy.Type)
290+
// If Type is empty in v1beta1, set it to RollingUpdateStrategyType.
291+
// This is the same behavior as in previous versions of Cluster API as Type
292+
// was always defaulted to RollingUpdateStrategyType, and also RollingUpdateStrategyType
293+
// is the only valid value.
294+
if in.RolloutStrategy.Type == "" {
295+
out.Rollout.Strategy.Type = controlplanev1.RollingUpdateStrategyType
296+
} else {
297+
out.Rollout.Strategy.Type = controlplanev1.KubeadmControlPlaneRolloutStrategyType(in.RolloutStrategy.Type)
298+
}
291299
if in.RolloutStrategy.RollingUpdate != nil && in.RolloutStrategy.RollingUpdate.MaxSurge != nil {
292300
out.Rollout.Strategy.RollingUpdate.MaxSurge = in.RolloutStrategy.RollingUpdate.MaxSurge
293301
}

api/controlplane/kubeadm/v1beta1/conversion_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func KubeadmControlPlaneTemplateFuzzFuncs(_ runtimeserializer.CodecFactory) []in
9999
spokeDiscovery,
100100
hubKubeadmConfigSpec,
101101
hubNodeRegistrationOptions,
102+
hubKubeadmControlPlaneTemplate,
102103
spokeKubeadmControlPlaneTemplate,
103104
spokeRemediationStrategy,
104105
spokeKubeadmControlPlaneTemplateMachineTemplate,
@@ -364,6 +365,15 @@ func spokeClusterConfiguration(in *bootstrapv1beta1.ClusterConfiguration, c rand
364365
}
365366
}
366367

368+
func hubKubeadmControlPlaneTemplate(in *controlplanev1.KubeadmControlPlaneTemplate, c randfill.Continue) {
369+
c.FillNoCustom(in)
370+
371+
// In v1beta2 Type is required and RollingUpdateStrategyType is the only valid value.
372+
if in.Spec.Template.Spec.Rollout.Strategy.Type == "" {
373+
in.Spec.Template.Spec.Rollout.Strategy.Type = controlplanev1.RollingUpdateStrategyType
374+
}
375+
}
376+
367377
func spokeKubeadmControlPlaneTemplate(in *KubeadmControlPlaneTemplate, c randfill.Continue) {
368378
c.FillNoCustom(in)
369379

@@ -384,6 +394,13 @@ func spokeKubeadmControlPlaneTemplate(in *KubeadmControlPlaneTemplate, c randfil
384394
if reflect.DeepEqual(in.Spec.Template.Spec.MachineNamingStrategy, &MachineNamingStrategy{}) {
385395
in.Spec.Template.Spec.MachineNamingStrategy = nil
386396
}
397+
398+
// In v1beta1 Type was always defaulted to RollingUpdateStrategyType.
399+
// RollingUpdateStrategyType is also the only valid value.
400+
if in.Spec.Template.Spec.RolloutStrategy != nil &&
401+
in.Spec.Template.Spec.RolloutStrategy.Type == "" {
402+
in.Spec.Template.Spec.RolloutStrategy.Type = RollingUpdateStrategyType
403+
}
387404
}
388405

389406
func spokeRemediationStrategy(in *RemediationStrategy, c randfill.Continue) {

0 commit comments

Comments
 (0)