From 60735db135209f9717132fcfbb184cd039e859f0 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Mon, 16 Sep 2024 08:18:16 +0200 Subject: [PATCH] Disable static kubetoken --- internal/gardener/shoot/converter.go | 2 +- .../shoot/extender/kubernetes_version.go | 8 +++++++- .../shoot/extender/kubernetes_version_test.go | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/gardener/shoot/converter.go b/internal/gardener/shoot/converter.go index aa819a47..4e6a891b 100644 --- a/internal/gardener/shoot/converter.go +++ b/internal/gardener/shoot/converter.go @@ -74,7 +74,7 @@ func NewConverter(config ConverterConfig) Converter { extenders := []Extend{ extender.ExtendWithAnnotations, extender.ExtendWithLabels, - extender.NewKubernetesVersionExtender(config.Kubernetes.DefaultVersion), + extender.NewKubernetesExtender(config.Kubernetes.DefaultVersion), extender.NewProviderExtender(config.Provider.AWS.EnableIMDSv2, config.MachineImage.DefaultVersion), extender.NewDNSExtender(config.DNS.SecretName, config.DNS.DomainPrefix, config.DNS.ProviderType), extender.ExtendWithOIDC, diff --git a/internal/gardener/shoot/extender/kubernetes_version.go b/internal/gardener/shoot/extender/kubernetes_version.go index fd2c9ca4..91693f26 100644 --- a/internal/gardener/shoot/extender/kubernetes_version.go +++ b/internal/gardener/shoot/extender/kubernetes_version.go @@ -3,9 +3,14 @@ package extender import ( gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1" imv1 "github.com/kyma-project/infrastructure-manager/api/v1" + "k8s.io/utils/ptr" ) -func NewKubernetesVersionExtender(defaultKubernetesVersion string) func(runtime imv1.Runtime, shoot *gardener.Shoot) error { +// NewKubernetesExtender creates a new Kubernetes extender function. +// It sets the Kubernetes version of the Shoot to the version specified in the Runtime. +// If the version is not specified in the Runtime, it sets the version to the `defaultKubernetesVersion`, set in `converter_config.json`. +// It sets the EnableStaticTokenKubeconfig field of the Shoot to false. +func NewKubernetesExtender(defaultKubernetesVersion string) func(runtime imv1.Runtime, shoot *gardener.Shoot) error { return func(runtime imv1.Runtime, shoot *gardener.Shoot) error { kubernetesVersion := runtime.Spec.Shoot.Kubernetes.Version if kubernetesVersion == nil || *kubernetesVersion == "" { @@ -13,6 +18,7 @@ func NewKubernetesVersionExtender(defaultKubernetesVersion string) func(runtime } shoot.Spec.Kubernetes.Version = *kubernetesVersion + shoot.Spec.Kubernetes.EnableStaticTokenKubeconfig = ptr.To(false) return nil } diff --git a/internal/gardener/shoot/extender/kubernetes_version_test.go b/internal/gardener/shoot/extender/kubernetes_version_test.go index 9de870e3..edbf99aa 100644 --- a/internal/gardener/shoot/extender/kubernetes_version_test.go +++ b/internal/gardener/shoot/extender/kubernetes_version_test.go @@ -16,7 +16,7 @@ func TestKubernetesVersionExtender(t *testing.T) { runtime := imv1.Runtime{} // when - kubernetesVersionExtender := NewKubernetesVersionExtender("1.99") + kubernetesVersionExtender := NewKubernetesExtender("1.99") err := kubernetesVersionExtender(runtime, &shoot) // then @@ -24,6 +24,20 @@ func TestKubernetesVersionExtender(t *testing.T) { assert.Equal(t, "1.99", shoot.Spec.Kubernetes.Version) }) + t.Run("Disable static token kubeconfig", func(t *testing.T) { + // given + shoot := fixEmptyGardenerShoot("test", "kcp-system") + runtime := imv1.Runtime{} + + // when + kubernetesVersionExtender := NewKubernetesExtender("1.99") + err := kubernetesVersionExtender(runtime, &shoot) + + // then + require.NoError(t, err) + assert.Equal(t, false, *shoot.Spec.Kubernetes.EnableStaticTokenKubeconfig) + }) + t.Run("Use version provided in the Runtime CR", func(t *testing.T) { // given shoot := fixEmptyGardenerShoot("test", "kcp-system") @@ -38,7 +52,7 @@ func TestKubernetesVersionExtender(t *testing.T) { } // when - kubernetesVersionExtender := NewKubernetesVersionExtender("1.99") + kubernetesVersionExtender := NewKubernetesExtender("1.99") err := kubernetesVersionExtender(runtime, &shoot) // then