Skip to content

Commit

Permalink
Allow worker pool Kubernetes version to be behind up to three minor v…
Browse files Browse the repository at this point in the history
…ersions when control plane version is `>= 1.28` (gardener#8402)

* Allow worker pool Kubernetes version to be behind up to three minor versions when control plane version is `>= 1.28`

* Address PR review feedback
  • Loading branch information
shafeeqes authored Aug 30, 2023
1 parent e5ea12b commit 140c8d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
16 changes: 13 additions & 3 deletions pkg/apis/core/validation/shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,24 @@ func validateWorkerGroupAndControlPlaneKubernetesVersion(controlPlaneVersion, wo
if err != nil {
allErrs = append(allErrs, field.Invalid(fldPath, workerGroupVersion, err.Error()))
}
threeMinorSkewVersion := workerVersion.IncMinor().IncMinor().IncMinor()

versionSkewViolation, err := versionutils.CompareVersions(controlPlaneVersion, ">=", threeMinorSkewVersion.String())
var (
k8sGreaterEqual128, _ = versionutils.CheckVersionMeetsConstraint(controlPlaneVersion, ">= 1.28")
minorSkewVersion = workerVersion.IncMinor().IncMinor().IncMinor()
maxSkew = "two"
)

if k8sGreaterEqual128 {
minorSkewVersion = workerVersion.IncMinor().IncMinor().IncMinor().IncMinor()
maxSkew = "three"
}

versionSkewViolation, err := versionutils.CompareVersions(controlPlaneVersion, ">=", minorSkewVersion.String())
if err != nil {
allErrs = append(allErrs, field.Invalid(fldPath, controlPlaneVersion, err.Error()))
}
if versionSkewViolation {
allErrs = append(allErrs, field.Forbidden(fldPath, "worker group kubernetes version must be at most two minor versions behind control plane version"))
allErrs = append(allErrs, field.Forbidden(fldPath, "worker group kubernetes version must be at most "+maxSkew+" minor versions behind control plane version"))
}

return allErrs
Expand Down
26 changes: 25 additions & 1 deletion pkg/apis/core/validation/shoot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2912,7 +2912,7 @@ var _ = Describe("Shoot Validation Tests", func() {
Expect(ValidateShootUpdate(newShoot, shoot)).To(BeEmpty())
})

It("forbid to set worker pool kubernetes version lower three minor than control plane version", func() {
It("forbid to set worker pool kubernetes version lower three minor than control plane version for k8s version < 1.28", func() {
shoot.Spec.Kubernetes.Version = "1.25.0"
shoot.Spec.Provider.Workers[0].Kubernetes = &core.WorkerKubernetes{Version: pointer.String("1.23.2")}

Expand All @@ -2926,6 +2926,30 @@ var _ = Describe("Shoot Validation Tests", func() {
}))))
})

It("allow to set worker pool kubernetes version lower three minor than control plane version for k8s version >= 1.28", func() {
shoot.Spec.Kubernetes.Version = "1.27.0"
shoot.Spec.Provider.Workers[0].Kubernetes = &core.WorkerKubernetes{Version: pointer.String("1.25.2")}

newShoot := prepareShootForUpdate(shoot)
newShoot.Spec.Kubernetes.Version = "1.28.0"

Expect(ValidateShootUpdate(newShoot, shoot)).To(BeEmpty())
})

It("forbid to set worker pool kubernetes version lower four minor than control plane version for k8s version >= 1.28", func() {
shoot.Spec.Kubernetes.Version = "1.27.0"
shoot.Spec.Provider.Workers[0].Kubernetes = &core.WorkerKubernetes{Version: pointer.String("1.24.2")}

newShoot := prepareShootForUpdate(shoot)
newShoot.Spec.Kubernetes.Version = "1.28.0"

Expect(ValidateShootUpdate(newShoot, shoot)).To(ConsistOf(PointTo(MatchFields(IgnoreExtras, Fields{
"Type": Equal(field.ErrorTypeForbidden),
"Field": Equal("spec.provider.workers[0].kubernetes.version"),
"Detail": Equal("worker group kubernetes version must be at most three minor versions behind control plane version"),
}))))
})

It("should allow to set worker pool kubernetes version to nil with one minor difference", func() {
shoot.Spec.Kubernetes.Version = "1.25.0"
shoot.Spec.Provider.Workers[0].Kubernetes = &core.WorkerKubernetes{Version: pointer.String("1.24.2")}
Expand Down

0 comments on commit 140c8d6

Please sign in to comment.