Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align fields with provisioner: Static Kubetoken + Network Filter #380

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 25 additions & 0 deletions internal/gardener/shoot/extender/kubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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"
)

// 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
}
}
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
19 changes: 0 additions & 19 deletions internal/gardener/shoot/extender/kubernetes_version.go

This file was deleted.

6 changes: 3 additions & 3 deletions internal/gardener/shoot/extender/network_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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"
)

const NetworkFilterType = "shoot-networking-filter"

func ExtendWithNetworkFilter(runtime imv1.Runtime, shoot *gardener.Shoot) error { //nolint:revive
networkingFilter := gardener.Extension{
Type: NetworkFilterType,
Disabled: ptr.To(false),
Type: NetworkFilterType,
// this pointer is safe, because runtime is fully pass-by-value
Disabled: &runtime.Spec.Security.Networking.Filter.Egress.Enabled,
}

shoot.Spec.Extensions = append(shoot.Spec.Extensions, networkingFilter)
Expand Down
Loading