Skip to content

Commit

Permalink
Merge pull request #480 from rfranzke/kubernetes-v1.23
Browse files Browse the repository at this point in the history
Support for Kubernetes v1.23
  • Loading branch information
dkistner authored Jan 25, 2022
2 parents 5994906 + 9892434 commit c586b26
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 97 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This extension controller supports the following Kubernetes versions:

| Version | Support | Conformance test results |
| --------------- | ----------- | ------------------------ |
| Kubernetes 1.23 | 1.23.0+ | N/A |
| Kubernetes 1.22 | 1.22.0+ | [![Gardener v1.22 Conformance Tests](https://testgrid.k8s.io/q/summary/conformance-gardener/Gardener,%20v1.22%20AWS/tests_status?style=svg)](https://testgrid.k8s.io/conformance-gardener#Gardener,%20v1.22%20AWS) |
| Kubernetes 1.21 | 1.21.0+ | [![Gardener v1.21 Conformance Tests](https://testgrid.k8s.io/q/summary/conformance-gardener/Gardener,%20v1.21%20AWS/tests_status?style=svg)](https://testgrid.k8s.io/conformance-gardener#Gardener,%20v1.21%20AWS) |
| Kubernetes 1.20 | 1.20.0+ | [![Gardener v1.20 Conformance Tests](https://testgrid.k8s.io/q/summary/conformance-gardener/Gardener,%20v1.20%20AWS/tests_status?style=svg)](https://testgrid.k8s.io/conformance-gardener#Gardener,%20v1.20%20AWS) |
Expand Down
13 changes: 9 additions & 4 deletions charts/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,23 @@ images:
- name: cloud-controller-manager
sourceRepository: github.com/gardener/cloud-provider-aws
repository: eu.gcr.io/gardener-project/kubernetes/cloud-provider-aws
tag: "v1.20.10"
tag: "v1.20.15"
targetVersion: "1.20.x"
- name: cloud-controller-manager
sourceRepository: github.com/gardener/cloud-provider-aws
repository: eu.gcr.io/gardener-project/kubernetes/cloud-provider-aws
tag: "v1.21.4"
tag: "v1.21.9"
targetVersion: "1.21.x"
- name: cloud-controller-manager
sourceRepository: github.com/gardener/cloud-provider-aws
repository: eu.gcr.io/gardener-project/kubernetes/cloud-provider-aws
tag: "v1.22.0"
targetVersion: ">= 1.22"
tag: "v1.22.6"
targetVersion: "1.22.x"
- name: cloud-controller-manager
sourceRepository: github.com/gardener/cloud-provider-aws
repository: eu.gcr.io/gardener-project/kubernetes/cloud-provider-aws
tag: "v1.23.2"
targetVersion: ">= 1.23"
- name: machine-controller-manager
sourceRepository: github.com/gardener/machine-controller-manager
repository: eu.gcr.io/gardener-project/gardener/machine-controller-manager
Expand Down
16 changes: 12 additions & 4 deletions pkg/webhook/controlplane/ensurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ import (
"github.com/gardener/gardener/extensions/pkg/webhook/controlplane/genericmutator"
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/gardener/gardener/pkg/utils/version"
versionutils "github.com/gardener/gardener/pkg/utils/version"
"github.com/go-logr/logr"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -401,7 +403,7 @@ func (e *ensurer) EnsureKubeletServiceUnitOptions(ctx context.Context, gctx gcon

if opt := extensionswebhook.UnitOptionWithSectionAndName(new, "Service", "ExecStart"); opt != nil {
command := extensionswebhook.DeserializeCommandLine(opt.Value)
command = ensureKubeletCommandLineArgs(command, csiEnabled)
command = ensureKubeletCommandLineArgs(command, csiEnabled, kubeletVersion)
opt.Value = extensionswebhook.SerializeCommandLine(command, 1, " \\\n ")
}

Expand All @@ -414,10 +416,12 @@ func (e *ensurer) EnsureKubeletServiceUnitOptions(ctx context.Context, gctx gcon
return new, nil
}

func ensureKubeletCommandLineArgs(command []string, csiEnabled bool) []string {
func ensureKubeletCommandLineArgs(command []string, csiEnabled bool, kubeletVersion *semver.Version) []string {
if csiEnabled {
command = extensionswebhook.EnsureStringWithPrefix(command, "--cloud-provider=", "external")
command = extensionswebhook.EnsureStringWithPrefix(command, "--enable-controller-attach-detach=", "true")
if !version.ConstraintK8sGreaterEqual123.Check(kubeletVersion) {
command = extensionswebhook.EnsureStringWithPrefix(command, "--cloud-provider=", "external")
command = extensionswebhook.EnsureStringWithPrefix(command, "--enable-controller-attach-detach=", "true")
}
} else {
command = extensionswebhook.EnsureStringWithPrefix(command, "--cloud-provider=", "aws")
}
Expand Down Expand Up @@ -449,6 +453,10 @@ func (e *ensurer) EnsureKubeletConfiguration(ctx context.Context, gctx gcontext.
new.FeatureGates["CSIMigrationAWS"] = true
// kubelets of new worker nodes can directly be started with the the <csiMigrationCompleteFeatureGate> feature gate
new.FeatureGates[csiMigrationCompleteFeatureGate] = true

if version.ConstraintK8sGreaterEqual123.Check(kubeletVersion) {
new.EnableControllerAttachDetach = pointer.Bool(true)
}
}

return nil
Expand Down
142 changes: 53 additions & 89 deletions pkg/webhook/controlplane/ensurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"context"
"testing"

"github.com/Masterminds/semver"
"github.com/gardener/gardener-extension-provider-aws/pkg/aws"

"github.com/Masterminds/semver"
"github.com/coreos/go-systemd/v22/unit"
extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/extensions/pkg/controller/csimigration"
Expand All @@ -35,6 +35,7 @@ import (
"github.com/gardener/gardener/pkg/utils/version"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -618,57 +619,38 @@ done
}
})

It("should modify existing elements of kubelet.service unit options (k8s < 1.17)", func() {
newUnitOptions := []*unit.UnitOption{
{
Section: "Service",
Name: "ExecStart",
Value: `/opt/bin/hyperkube kubelet \
--config=/var/lib/kubelet/config/kubelet \
--cloud-provider=aws`,
},
hostnamectlUnitOption,
}

opts, err := ensurer.EnsureKubeletServiceUnitOptions(ctx, eContextK8s116, semver.MustParse("1.16.0"), oldUnitOptions, nil)
Expect(err).To(Not(HaveOccurred()))
Expect(opts).To(Equal(newUnitOptions))
})
DescribeTable("should modify existing elements of kubelet.service unit options",
func(gctx gcontext.GardenContext, kubeletVersion *semver.Version, cloudProvider string, withControllerAttachDetachFlag bool) {
newUnitOptions := []*unit.UnitOption{
{
Section: "Service",
Name: "ExecStart",
Value: `/opt/bin/hyperkube kubelet \
--config=/var/lib/kubelet/config/kubelet`,
},
hostnamectlUnitOption,
}

It("should modify existing elements of kubelet.service unit options (k8s >= 1.17)", func() {
newUnitOptions := []*unit.UnitOption{
{
Section: "Service",
Name: "ExecStart",
Value: `/opt/bin/hyperkube kubelet \
--config=/var/lib/kubelet/config/kubelet \
--cloud-provider=aws`,
},
hostnamectlUnitOption,
}
if cloudProvider != "" {
newUnitOptions[0].Value += ` \
--cloud-provider=` + cloudProvider
}

opts, err := ensurer.EnsureKubeletServiceUnitOptions(ctx, eContextK8s117, semver.MustParse("1.17.0"), oldUnitOptions, nil)
Expect(err).To(Not(HaveOccurred()))
Expect(opts).To(Equal(newUnitOptions))
})
if withControllerAttachDetachFlag {
newUnitOptions[0].Value += ` \
--enable-controller-attach-detach=true`
}

It("should modify existing elements of kubelet.service unit options (k8s >= 1.18)", func() {
newUnitOptions := []*unit.UnitOption{
{
Section: "Service",
Name: "ExecStart",
Value: `/opt/bin/hyperkube kubelet \
--config=/var/lib/kubelet/config/kubelet \
--cloud-provider=external \
--enable-controller-attach-detach=true`,
},
hostnamectlUnitOption,
}
opts, err := ensurer.EnsureKubeletServiceUnitOptions(ctx, gctx, kubeletVersion, oldUnitOptions, nil)
Expect(err).To(Not(HaveOccurred()))
Expect(opts).To(Equal(newUnitOptions))
},

opts, err := ensurer.EnsureKubeletServiceUnitOptions(ctx, eContextK8s118, semver.MustParse("1.18.0"), oldUnitOptions, nil)
Expect(err).To(Not(HaveOccurred()))
Expect(opts).To(Equal(newUnitOptions))
})
Entry("kubelet version < 1.17", eContextK8s116, semver.MustParse("1.16.0"), "aws", false),
Entry("1.17 <= kubelet version < 1.18", eContextK8s117, semver.MustParse("1.17.0"), "aws", false),
Entry("1.18 <= kubelet version < 1.23", eContextK8s118, semver.MustParse("1.18.0"), "external", true),
Entry("kubelet version >= 1.23", eContextK8s118, semver.MustParse("1.23.0"), "", false),
)
})

Describe("#EnsureKubeletConfiguration", func() {
Expand All @@ -686,50 +668,32 @@ done
}
})

It("should modify existing elements of kubelet configuration (< 1.17)", func() {
newKubeletConfig := &kubeletconfigv1beta1.KubeletConfiguration{
FeatureGates: map[string]bool{
"Foo": true,
},
}
kubeletConfig := *oldKubeletConfig

err := ensurer.EnsureKubeletConfiguration(ctx, eContextK8s117, semver.MustParse("1.17.0"), &kubeletConfig, nil)
Expect(err).To(Not(HaveOccurred()))
Expect(&kubeletConfig).To(Equal(newKubeletConfig))
})

It("should modify existing elements of kubelet configuration (>= 1.18)", func() {
newKubeletConfig := &kubeletconfigv1beta1.KubeletConfiguration{
FeatureGates: map[string]bool{
"Foo": true,
"CSIMigration": true,
"CSIMigrationAWS": true,
"CSIMigrationAWSComplete": true,
},
}
kubeletConfig := *oldKubeletConfig
DescribeTable("should modify existing elements of kubelet configuration",
func(gctx gcontext.GardenContext, kubeletVersion *semver.Version, withCSIFeatureGates bool, csiMigrationCompleteFeatureGate string, enableControllerAttachDetach *bool) {
newKubeletConfig := &kubeletconfigv1beta1.KubeletConfiguration{
FeatureGates: map[string]bool{
"Foo": true,
},
EnableControllerAttachDetach: enableControllerAttachDetach,
}
kubeletConfig := *oldKubeletConfig

err := ensurer.EnsureKubeletConfiguration(ctx, eContextK8s118, semver.MustParse("1.18.0"), &kubeletConfig, nil)
Expect(err).To(Not(HaveOccurred()))
Expect(&kubeletConfig).To(Equal(newKubeletConfig))
})
if withCSIFeatureGates {
newKubeletConfig.FeatureGates["CSIMigration"] = true
newKubeletConfig.FeatureGates["CSIMigrationAWS"] = true
newKubeletConfig.FeatureGates[csiMigrationCompleteFeatureGate] = true
}

It("should modify existing elements of kubelet configuration (>= 1.21)", func() {
newKubeletConfig := &kubeletconfigv1beta1.KubeletConfiguration{
FeatureGates: map[string]bool{
"Foo": true,
"CSIMigration": true,
"CSIMigrationAWS": true,
"InTreePluginAWSUnregister": true,
},
}
kubeletConfig := *oldKubeletConfig
err := ensurer.EnsureKubeletConfiguration(ctx, gctx, kubeletVersion, &kubeletConfig, nil)
Expect(err).To(Not(HaveOccurred()))
Expect(&kubeletConfig).To(Equal(newKubeletConfig))
},

err := ensurer.EnsureKubeletConfiguration(ctx, eContextK8s121, semver.MustParse("1.21.0"), &kubeletConfig, nil)
Expect(err).To(Not(HaveOccurred()))
Expect(&kubeletConfig).To(Equal(newKubeletConfig))
})
Entry("kubelet < 1.18", eContextK8s117, semver.MustParse("1.17.0"), false, "", nil),
Entry("1.18 <= kubelet < 1.21", eContextK8s118, semver.MustParse("1.18.0"), true, "CSIMigrationAWSComplete", nil),
Entry("1.21 <= kubelet < 1.23", eContextK8s121, semver.MustParse("1.21.0"), true, "InTreePluginAWSUnregister", nil),
Entry("kubelet >= 1.23", eContextK8s121, semver.MustParse("1.23.0"), true, "InTreePluginAWSUnregister", pointer.Bool(true)),
)
})

Describe("#EnsureKubernetesGeneralConfiguration", func() {
Expand Down

0 comments on commit c586b26

Please sign in to comment.