Skip to content

Commit

Permalink
Fix panic, when overlay config is empty in old shoot. (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
axel7born committed Nov 9, 2023
1 parent f912118 commit 6ec8d96
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/admission/mutator/shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions pkg/admission/mutator/shoot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}`),
Expand All @@ -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")
Expand Down

0 comments on commit 6ec8d96

Please sign in to comment.