Skip to content

Commit

Permalink
Disable static kubetoken
Browse files Browse the repository at this point in the history
  • Loading branch information
VOID404 committed Sep 16, 2024
1 parent 696edfb commit 60735db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/gardener/shoot/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion internal/gardener/shoot/extender/kubernetes_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ 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 == "" {
kubernetesVersion = &defaultKubernetesVersion
}

shoot.Spec.Kubernetes.Version = *kubernetesVersion
shoot.Spec.Kubernetes.EnableStaticTokenKubeconfig = ptr.To(false)

return nil
}
Expand Down
18 changes: 16 additions & 2 deletions internal/gardener/shoot/extender/kubernetes_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@ func TestKubernetesVersionExtender(t *testing.T) {
runtime := imv1.Runtime{}

// when
kubernetesVersionExtender := NewKubernetesVersionExtender("1.99")
kubernetesVersionExtender := NewKubernetesExtender("1.99")
err := kubernetesVersionExtender(runtime, &shoot)

// then
require.NoError(t, err)
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")
Expand All @@ -38,7 +52,7 @@ func TestKubernetesVersionExtender(t *testing.T) {
}

// when
kubernetesVersionExtender := NewKubernetesVersionExtender("1.99")
kubernetesVersionExtender := NewKubernetesExtender("1.99")
err := kubernetesVersionExtender(runtime, &shoot)

// then
Expand Down

0 comments on commit 60735db

Please sign in to comment.