diff --git a/api/controlplane/kubeadm/v1beta1/conversion.go b/api/controlplane/kubeadm/v1beta1/conversion.go index 720e58066fac..9ea3863d6169 100644 --- a/api/controlplane/kubeadm/v1beta1/conversion.go +++ b/api/controlplane/kubeadm/v1beta1/conversion.go @@ -287,7 +287,15 @@ func Convert_v1beta1_KubeadmControlPlaneTemplateResourceSpec_To_v1beta2_KubeadmC out.Rollout.After = *in.RolloutAfter } if in.RolloutStrategy != nil { - out.Rollout.Strategy.Type = controlplanev1.KubeadmControlPlaneRolloutStrategyType(in.RolloutStrategy.Type) + // If Type is empty in v1beta1, set it to RollingUpdateStrategyType. + // This is the same behavior as in previous versions of Cluster API as Type + // was always defaulted to RollingUpdateStrategyType, and also RollingUpdateStrategyType + // is the only valid value. + if in.RolloutStrategy.Type == "" { + out.Rollout.Strategy.Type = controlplanev1.RollingUpdateStrategyType + } else { + out.Rollout.Strategy.Type = controlplanev1.KubeadmControlPlaneRolloutStrategyType(in.RolloutStrategy.Type) + } if in.RolloutStrategy.RollingUpdate != nil && in.RolloutStrategy.RollingUpdate.MaxSurge != nil { out.Rollout.Strategy.RollingUpdate.MaxSurge = in.RolloutStrategy.RollingUpdate.MaxSurge } diff --git a/api/controlplane/kubeadm/v1beta1/conversion_test.go b/api/controlplane/kubeadm/v1beta1/conversion_test.go index b7ca66fae4ad..e58dc265cf51 100644 --- a/api/controlplane/kubeadm/v1beta1/conversion_test.go +++ b/api/controlplane/kubeadm/v1beta1/conversion_test.go @@ -99,6 +99,7 @@ func KubeadmControlPlaneTemplateFuzzFuncs(_ runtimeserializer.CodecFactory) []in spokeDiscovery, hubKubeadmConfigSpec, hubNodeRegistrationOptions, + hubKubeadmControlPlaneTemplate, spokeKubeadmControlPlaneTemplate, spokeRemediationStrategy, spokeKubeadmControlPlaneTemplateMachineTemplate, @@ -364,6 +365,15 @@ func spokeClusterConfiguration(in *bootstrapv1beta1.ClusterConfiguration, c rand } } +func hubKubeadmControlPlaneTemplate(in *controlplanev1.KubeadmControlPlaneTemplate, c randfill.Continue) { + c.FillNoCustom(in) + + // In v1beta2 Type is required and RollingUpdateStrategyType is the only valid value. + if in.Spec.Template.Spec.Rollout.Strategy.Type == "" { + in.Spec.Template.Spec.Rollout.Strategy.Type = controlplanev1.RollingUpdateStrategyType + } +} + func spokeKubeadmControlPlaneTemplate(in *KubeadmControlPlaneTemplate, c randfill.Continue) { c.FillNoCustom(in) @@ -384,6 +394,13 @@ func spokeKubeadmControlPlaneTemplate(in *KubeadmControlPlaneTemplate, c randfil if reflect.DeepEqual(in.Spec.Template.Spec.MachineNamingStrategy, &MachineNamingStrategy{}) { in.Spec.Template.Spec.MachineNamingStrategy = nil } + + // In v1beta1 Type was always defaulted to RollingUpdateStrategyType. + // RollingUpdateStrategyType is also the only valid value. + if in.Spec.Template.Spec.RolloutStrategy != nil && + in.Spec.Template.Spec.RolloutStrategy.Type == "" { + in.Spec.Template.Spec.RolloutStrategy.Type = RollingUpdateStrategyType + } } func spokeRemediationStrategy(in *RemediationStrategy, c randfill.Continue) {