diff --git a/pkg/admission/mutator/shoot.go b/pkg/admission/mutator/shoot.go index 2e65cbb10..219fd38e9 100644 --- a/pkg/admission/mutator/shoot.go +++ b/pkg/admission/mutator/shoot.go @@ -120,7 +120,10 @@ func (s *shoot) Mutate(_ context.Context, newObj, oldObj client.Object) error { } } - overlayConfig, _ = networkConfig["overlay"].(map[string]interface{}) + if currentOverlayConfig, ok := networkConfig["overlay"].(map[string]interface{}); ok { + overlayConfig = currentOverlayConfig + } + if !overlayConfig["enabled"].(bool) && overlayConfig[createPodRoutesKey] == nil { overlayConfig[createPodRoutesKey] = true networkConfig[overlayKey] = overlayConfig diff --git a/pkg/admission/mutator/shoot_test.go b/pkg/admission/mutator/shoot_test.go index 2808542a0..4a86b89d3 100644 --- a/pkg/admission/mutator/shoot_test.go +++ b/pkg/admission/mutator/shoot_test.go @@ -171,6 +171,17 @@ var _ = Describe("Shoot mutator", func() { Expect(networkConfig).To(DeepEqual(expectedConfig)) }) + It("should disable overlay for a new shoot non empty network config", func() { + shoot.Spec.Networking.ProviderConfig = &runtime.RawExtension{ + Raw: []byte(`{"foo":{"enabled":true}}`), + } + err := shootMutator.Mutate(ctx, shoot, nil) + Expect(err).NotTo(HaveOccurred()) + Expect(shoot.Spec.Networking.ProviderConfig).To(Equal(&runtime.RawExtension{ + Raw: []byte(`{"foo":{"enabled":true},"overlay":{"createPodRoutes":true,"enabled":false}}`), + })) + }) + It("should take overlay field value from old shoot when unspecified in new shoot", func() { oldShoot.Spec.Networking.ProviderConfig = &runtime.RawExtension{ Raw: []byte(`{"overlay":{"enabled":true}}`), @@ -183,6 +194,14 @@ var _ = Describe("Shoot mutator", func() { }) }) + It("should disable overlay for a new shoot when unspecified in new and old shoot", func() { + err := shootMutator.Mutate(ctx, shoot, oldShoot) + Expect(err).NotTo(HaveOccurred()) + Expect(shoot.Spec.Networking.ProviderConfig).To(Equal(&runtime.RawExtension{ + Raw: []byte(`{"overlay":{"createPodRoutes":true,"enabled":false}}`), + })) + }) + Context("Mutate shoot networking providerconfig for type cilium", func() { BeforeEach(func() { shoot.Spec.Networking.Type = pointer.String("cilium")