From 879993080426733f1f901ce38ea5ddf938e86c42 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Tue, 3 Sep 2024 13:27:43 +0200 Subject: [PATCH 1/3] Update metallb to v0.14.8 (#418) --- charts/images.yaml | 6 +++--- charts/internal/shoot-control-plane/templates/metallb.yaml | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/charts/images.yaml b/charts/images.yaml index 662b6327..1b47dec9 100644 --- a/charts/images.yaml +++ b/charts/images.yaml @@ -22,11 +22,11 @@ images: - name: metallb-speaker sourceRepository: https://github.com/metallb/metallb repository: quay.io/metallb/speaker - tag: "v0.14.3" + tag: "v0.14.8" - name: metallb-controller sourceRepository: https://github.com/metallb/metallb repository: quay.io/metallb/controller - tag: "v0.14.3" + tag: "v0.14.8" - name: duros-controller sourceRepository: https://github.com/metal-stack/duros-controller repository: ghcr.io/metal-stack/duros-controller @@ -38,7 +38,7 @@ images: - name: metallb-health-sidecar sourceRepository: https://github.com/metal-stack/metallb-health-sidecar repository: ghcr.io/metal-stack/metallb-health-sidecar - tag: "v0.1.1" + tag: "v0.1.2" - name: firewall-controller-manager sourceRepository: https://github.com/metal-stack/firewall-controller-manager repository: ghcr.io/metal-stack/firewall-controller-manager diff --git a/charts/internal/shoot-control-plane/templates/metallb.yaml b/charts/internal/shoot-control-plane/templates/metallb.yaml index 29b9e6a2..5efb2c7a 100644 --- a/charts/internal/shoot-control-plane/templates/metallb.yaml +++ b/charts/internal/shoot-control-plane/templates/metallb.yaml @@ -267,6 +267,7 @@ rules: - pods verbs: - list + - get - apiGroups: - "" resources: @@ -551,6 +552,10 @@ spec: valueFrom: fieldRef: fieldPath: spec.nodeName + - name: METALLB_POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name - name: METALLB_HOST valueFrom: fieldRef: From 74739b80ede1b6096dc93093acc10ccdd1df7b91 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Tue, 3 Sep 2024 13:31:51 +0200 Subject: [PATCH 2/3] Remove old kubernetes defaultings (#419) --- .github/workflows/docker.yaml | 2 +- pkg/admission/mutator/config.go | 6 +----- pkg/admission/mutator/defaulter.go | 11 +---------- pkg/admission/mutator/defaulter_test.go | 3 +-- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 73f1642f..5c158fb4 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -38,7 +38,7 @@ jobs: [ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true - name: Build and push image - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . push: true diff --git a/pkg/admission/mutator/config.go b/pkg/admission/mutator/config.go index d58f4e25..6e57c79c 100644 --- a/pkg/admission/mutator/config.go +++ b/pkg/admission/mutator/config.go @@ -11,10 +11,6 @@ import ( type config struct{} -func (c *config) allowedPrivilegedContainers() bool { - return c.bool("DEFAULTER_ALLOWEDPRIVILEGEDCONTAINERS", true) -} - func (c *config) maxPods() int32 { return c.int32("DEFAULTER_MAXPODS", 250) } @@ -126,5 +122,5 @@ func (c *config) int32(key string, fallback int32) int32 { return fallback } - return int32(parsed) + return int32(parsed) // nolint:gosec } diff --git a/pkg/admission/mutator/defaulter.go b/pkg/admission/mutator/defaulter.go index 9fa40c99..bcc53cf5 100644 --- a/pkg/admission/mutator/defaulter.go +++ b/pkg/admission/mutator/defaulter.go @@ -12,7 +12,6 @@ import ( "github.com/metal-stack/gardener-extension-provider-metal/pkg/apis/metal" "github.com/metal-stack/gardener-extension-provider-metal/pkg/apis/metal/helper" metalv1alpha1 "github.com/metal-stack/gardener-extension-provider-metal/pkg/apis/metal/v1alpha1" - "github.com/metal-stack/metal-lib/pkg/k8s" "github.com/metal-stack/metal-lib/pkg/pointer" "k8s.io/apimachinery/pkg/runtime" @@ -27,14 +26,6 @@ type defaulter struct { } func (d *defaulter) defaultShoot(shoot *gardenv1beta1.Shoot) error { - lessThan125, err := k8s.LessThan(shoot.Spec.Kubernetes.Version, k8s.KubernetesV125) - if err != nil { - return err - } - if shoot.Spec.Kubernetes.AllowPrivilegedContainers == nil && lessThan125 { - shoot.Spec.Kubernetes.AllowPrivilegedContainers = pointer.Pointer(d.c.allowedPrivilegedContainers()) - } - if shoot.Spec.Kubernetes.KubeControllerManager == nil { shoot.Spec.Kubernetes.KubeControllerManager = &gardenv1beta1.KubeControllerManagerConfig{} } @@ -51,7 +42,7 @@ func (d *defaulter) defaultShoot(shoot *gardenv1beta1.Shoot) error { shoot.Spec.Kubernetes.Kubelet.MaxPods = pointer.Pointer(d.c.maxPods()) } - err = d.defaultInfrastructureConfig(shoot) + err := d.defaultInfrastructureConfig(shoot) if err != nil { return err } diff --git a/pkg/admission/mutator/defaulter_test.go b/pkg/admission/mutator/defaulter_test.go index cd81cdfc..75b910fe 100644 --- a/pkg/admission/mutator/defaulter_test.go +++ b/pkg/admission/mutator/defaulter_test.go @@ -117,8 +117,7 @@ func Test_defaulter_defaultShoot(t *testing.T) { want: &gardenv1beta1.Shoot{ Spec: gardenv1beta1.ShootSpec{ Kubernetes: gardenv1beta1.Kubernetes{ - Version: "1.24.0", - AllowPrivilegedContainers: pointer.Pointer(true), + Version: "1.24.0", KubeControllerManager: &gardenv1beta1.KubeControllerManagerConfig{ NodeCIDRMaskSize: pointer.Pointer(int32(23)), }, From e812b5834b3566e7a04ad41f7de01627966b98c1 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Tue, 3 Sep 2024 15:58:06 +0200 Subject: [PATCH 3/3] Remove CCD secret mutation. (#420) --- example/controller-registration.yaml | 2 +- go.mod | 1 - go.sum | 2 - pkg/webhook/shoot/mutator.go | 157 --------------------------- pkg/webhook/shoot/mutator_test.go | 41 ------- 5 files changed, 1 insertion(+), 202 deletions(-) delete mode 100644 pkg/webhook/shoot/mutator_test.go diff --git a/example/controller-registration.yaml b/example/controller-registration.yaml index a2a84ed1..32620ff6 100644 --- a/example/controller-registration.yaml +++ b/example/controller-registration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9zOOsjbfA2+6AG/lH/4T0YTkYysjLr6oM/tgAAwwwwAADDDDAAAMMMMAAAwwwwAADDDDAAAMMMMDnDf8HJasSEQB4AAA= values: image: - tag: v0.24.4 + tag: v0.24.5 --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration diff --git a/go.mod b/go.mod index 828eda6b..83bb4a46 100644 --- a/go.mod +++ b/go.mod @@ -158,7 +158,6 @@ require ( istio.io/api v1.19.2-0.20231011000955-f3015ebb5bd4 // indirect istio.io/client-go v1.19.3 // indirect k8s.io/apiserver v0.29.2 // indirect - k8s.io/cluster-bootstrap v0.28.3 // indirect k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 // indirect k8s.io/helm v2.17.0+incompatible // indirect k8s.io/klog v1.0.0 // indirect diff --git a/go.sum b/go.sum index 071f7909..7c41b9b4 100644 --- a/go.sum +++ b/go.sum @@ -2023,8 +2023,6 @@ k8s.io/autoscaler/vertical-pod-autoscaler v1.0.0 h1:y0TgWoHaeYEv3L1MfLC+D2WVxyN1 k8s.io/autoscaler/vertical-pod-autoscaler v1.0.0/go.mod h1:w6/LjLR3DPQd57vlgvgbpzpuJKsCiily0+OzQI+nyfI= k8s.io/client-go v0.28.3 h1:2OqNb72ZuTZPKCl+4gTKvqao0AMOl9f3o2ijbAj3LI4= k8s.io/client-go v0.28.3/go.mod h1:LTykbBp9gsA7SwqirlCXBWtK0guzfhpoW4qSm7i9dxo= -k8s.io/cluster-bootstrap v0.28.3 h1:hGK3mJsmVGGvRJ61nyQcYNR9g/IYax75TbJcylTmZts= -k8s.io/cluster-bootstrap v0.28.3/go.mod h1:s1B3FTw713b9iw67yGFiVF3zCfw5obrZXWl3EMelvdg= k8s.io/code-generator v0.28.3 h1:I847QvdpYx7xKiG2KVQeCSyNF/xU9TowaDAg601mvlw= k8s.io/code-generator v0.28.3/go.mod h1:A2EAHTRYvCvBrb/MM2zZBNipeCk3f8NtpdNIKawC43M= k8s.io/component-base v0.28.3 h1:rDy68eHKxq/80RiMb2Ld/tbH8uAE75JdCqJyi6lXMzI= diff --git a/pkg/webhook/shoot/mutator.go b/pkg/webhook/shoot/mutator.go index 51b28dd3..9cac9c02 100644 --- a/pkg/webhook/shoot/mutator.go +++ b/pkg/webhook/shoot/mutator.go @@ -2,25 +2,10 @@ package shoot import ( "context" - "errors" "fmt" - "net/url" - "slices" - "strings" extensionswebhook "github.com/gardener/gardener/extensions/pkg/webhook" - gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1" - extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1" - resourcesv1alpha1 "github.com/gardener/gardener/pkg/apis/resources/v1alpha1" - "github.com/gardener/gardener/pkg/component/extensions/operatingsystemconfig/downloader" - "github.com/metal-stack/gardener-extension-provider-metal/pkg/apis/metal/helper" - kutil "github.com/gardener/gardener/pkg/utils/kubernetes" - - metalv1alpha1 "github.com/metal-stack/gardener-extension-provider-metal/pkg/apis/metal/v1alpha1" - - extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller" - "github.com/gardener/gardener/pkg/utils" "github.com/go-logr/logr" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -64,14 +49,6 @@ func (m *mutator) Mutate(ctx context.Context, new, _ client.Object) error { extensionswebhook.LogMutation(logger, x.Kind, x.Namespace, x.Name) return m.mutateVPNShootDeployment(ctx, x) } - case *corev1.Secret: - // TODO: remove this once gardener-node-agent is in use - // the purpose of this hack is to enable the cloud-config-downloader to pull the hyperkube image from - // a registry mirror in case this shoot cluster is configured with networkaccesstype restricted/forbidden - err = m.mutateCloudConfigDownloaderHyperkubeImage(ctx, x) - if err != nil { - return fmt.Errorf("mutating cloud config downlader secret failed %w", err) - } } return nil } @@ -99,137 +76,3 @@ func (m *mutator) mutateVPNShootDeployment(_ context.Context, deployment *appsv1 return nil } - -const ( - gardenerRegistry = "eu.gcr.io" - hyperkubeImage = "/gardener-project/hyperkube" - - // this should be the final destination - newGardenerRegistry = "europe-docker.pkg.dev" - newHyperkubeImage = "/gardener-project/releases/hyperkube" -) - -func (m *mutator) mutateCloudConfigDownloaderHyperkubeImage(ctx context.Context, secret *corev1.Secret) error { - if secret.Labels["gardener.cloud/role"] != "cloud-config" { - return nil - } - - shootName, err := extractShootNameFromSecret(secret) - if err != nil { - return err - } - - cluster := &extensionsv1alpha1.Cluster{} - if err := m.client.Get(ctx, kutil.Key(shootName), cluster); err != nil { - return err - } - - shoot, err := extensionscontroller.ShootFromCluster(cluster) - if err != nil { - return fmt.Errorf("unable to decode cluster.Spec.Shoot.Raw %w", err) - } - - if len(shoot.Spec.Provider.Workers) == 0 { - m.logger.Info("workerless shoot, nothing to do here", "shoot", shootName) - return nil - } - - cloudProfile := &gardencorev1beta1.CloudProfile{} - err = helper.DecodeRawExtension(&cluster.Spec.CloudProfile, cloudProfile, m.decoder) - if err != nil { - return err - } - - cloudProfileConfig, err := helper.DecodeCloudProfileConfig(cloudProfile) - if err != nil { - return err - } - - infrastructureConfig := &metalv1alpha1.InfrastructureConfig{} - err = helper.DecodeRawExtension(shoot.Spec.Provider.InfrastructureConfig, infrastructureConfig, m.decoder) - if err != nil { - return err - } - - _, p, err := helper.FindMetalControlPlane(cloudProfileConfig, infrastructureConfig.PartitionID) - if err != nil { - return err - } - - controlPlaneConfig := &metalv1alpha1.ControlPlaneConfig{} - err = helper.DecodeRawExtension(shoot.Spec.Provider.ControlPlaneConfig, controlPlaneConfig, m.decoder) - if err != nil { - return err - } - - if controlPlaneConfig.NetworkAccessType == nil || *controlPlaneConfig.NetworkAccessType == metalv1alpha1.NetworkAccessBaseline { - // this shoot does not have networkaccesstype restricted or forbidden specified, nothing to do here - return nil - } - - if p.NetworkIsolation == nil || len(p.NetworkIsolation.RegistryMirrors) == 0 { - m.logger.Info("no registry mirrors specified in this shoot, nothing to do here", "shoot", shootName) - return nil - } - - var ( - networkIsolation = p.NetworkIsolation - destinationRegistry string - ) - - for _, registry := range networkIsolation.RegistryMirrors { - if slices.Contains(registry.MirrorOf, gardenerRegistry) { - parsed, err := url.Parse(registry.Endpoint) - if err != nil { - return fmt.Errorf("unable to parse registry endpoint:%w", err) - } - destinationRegistry = parsed.Host - break - } - } - if destinationRegistry == "" { - err := errors.New("no matching destination registry detected for the hyperkube image") - m.logger.Error(err, "please check the networkisolation configuration", "shoot", shootName) - return err - } - - m.logger.Info("mutate secret", "shoot", shootName, "secret", secret.Name) - - raw, ok := secret.Data[downloader.DataKeyScript] - if ok { - script := string(raw) - newScript := strings.ReplaceAll(script, gardenerRegistry+hyperkubeImage, destinationRegistry+hyperkubeImage) - newScript = strings.ReplaceAll(newScript, newGardenerRegistry+newHyperkubeImage, destinationRegistry+newHyperkubeImage) - secret.Data[downloader.DataKeyScript] = []byte(newScript) - secret.Annotations[downloader.AnnotationKeyChecksum] = utils.ComputeChecksum(newScript) - } - return nil -} - -func extractShootNameFromSecret(secret *corev1.Secret) (string, error) { - // resources.gardener.cloud/origin: shoot--test--fra-equ01-8fef639c-bbe4-4c6f-9656-617dc4a4efd8-gardener-soil-test:shoot--pjb9j2--forbidden/shoot-cloud-config-execution - origin, ok := secret.Annotations[resourcesv1alpha1.OriginAnnotation] - if !ok { - return "", fmt.Errorf("no matching annotation found to identify the shoot namespace") - } - - // does not work - // shootName, _, err := resourcesv1alpha1helper.SplitOrigin(origin) - // if err != nil { - // return "", fmt.Errorf("no matching content found in origin annotation to get shoot namespace %w", err) - // } - - // resources.gardener.cloud/origin: shoot--test--fra-equ01-8fef639c-bbe4-4c6f-9656-617dc4a4efd8-gardener-soil-test:shoot--pjb9j2--forbidden/shoot-cloud-config-execution - _, firstpart, found := strings.Cut(origin, ":") - if !found { - return "", fmt.Errorf("no matching content found in origin annotation to get shoot namespace") - } - shootName, _, found := strings.Cut(firstpart, "/") - if !found { - return "", fmt.Errorf("no matching content found in origin annotation to get shoot namespace") - } - if len(shootName) == 0 { - return "", fmt.Errorf("could not find shoot name for webhook request") - } - return shootName, nil -} diff --git a/pkg/webhook/shoot/mutator_test.go b/pkg/webhook/shoot/mutator_test.go deleted file mode 100644 index 55788ebe..00000000 --- a/pkg/webhook/shoot/mutator_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package shoot - -import ( - "testing" - - corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func Test_extractShootNameFromSecret(t *testing.T) { - tests := []struct { - name string - secret *corev1.Secret - want string - wantErr bool - }{ - { - name: "a simple test", - secret: &corev1.Secret{ - ObjectMeta: v1.ObjectMeta{ - Annotations: map[string]string{ - "resources.gardener.cloud/origin": "shoot--test--fra-equ01-8fef639c-bbe4-4c6f-9656-617dc4a4efd8-gardener-soil-test:shoot--pjb9j2--forbidden/shoot-cloud-config-execution", - }, - }, - }, - want: "shoot--pjb9j2--forbidden", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := extractShootNameFromSecret(tt.secret) - if (err != nil) != tt.wantErr { - t.Errorf("extractShootNameFromSecret() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("extractShootNameFromSecret() = %v, want %v", got, tt.want) - } - }) - } -}