Skip to content

Commit 9545b69

Browse files
authored
Merge pull request #6916 from killianmuldoon/fix/controlplane-maxSurge-parsing
🌱 KCP webhook - compare maxSurge using IntValue
2 parents 44b6689 + cc27d25 commit 9545b69

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func validateRolloutStrategy(rolloutStrategy *RolloutStrategy, replicas *int32,
338338
ios1 := intstr.FromInt(1)
339339
ios0 := intstr.FromInt(0)
340340

341-
if *rolloutStrategy.RollingUpdate.MaxSurge == ios0 && (replicas != nil && *replicas < int32(3)) {
341+
if rolloutStrategy.RollingUpdate.MaxSurge.IntValue() == ios0.IntValue() && (replicas != nil && *replicas < int32(3)) {
342342
allErrs = append(
343343
allErrs,
344344
field.Required(
@@ -348,7 +348,7 @@ func validateRolloutStrategy(rolloutStrategy *RolloutStrategy, replicas *int32,
348348
)
349349
}
350350

351-
if *rolloutStrategy.RollingUpdate.MaxSurge != ios1 && *rolloutStrategy.RollingUpdate.MaxSurge != ios0 {
351+
if rolloutStrategy.RollingUpdate.MaxSurge.IntValue() != ios1.IntValue() && rolloutStrategy.RollingUpdate.MaxSurge.IntValue() != ios0.IntValue() {
352352
allErrs = append(
353353
allErrs,
354354
field.Required(

controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_webhook_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func TestKubeadmControlPlaneValidateCreate(t *testing.T) {
103103
invalidMaxSurge := valid.DeepCopy()
104104
invalidMaxSurge.Spec.RolloutStrategy.RollingUpdate.MaxSurge.IntVal = int32(3)
105105

106+
stringMaxSurge := valid.DeepCopy()
107+
val := intstr.FromString("1")
108+
stringMaxSurge.Spec.RolloutStrategy.RollingUpdate.MaxSurge = &val
109+
106110
invalidNamespace := valid.DeepCopy()
107111
invalidNamespace.Spec.MachineTemplate.InfrastructureRef.Namespace = "bar"
108112

@@ -204,6 +208,12 @@ func TestKubeadmControlPlaneValidateCreate(t *testing.T) {
204208
expectErr: true,
205209
kcp: invalidMaxSurge,
206210
},
211+
{
212+
name: "should succeed when maxSurge is a string",
213+
expectErr: false,
214+
kcp: stringMaxSurge,
215+
},
216+
207217
{
208218
name: "should return error when Ignition configuration is invalid",
209219
enableIgnitionFeature: true,

0 commit comments

Comments
 (0)