From 32dc538940318d5daef2577be54a250894217fa0 Mon Sep 17 00:00:00 2001 From: Yusuke Suzuki Date: Sun, 1 Oct 2023 21:08:19 +0900 Subject: [PATCH] Ease the restriction for Egress This commits eases the restriction for Egress to allow users to change Destinations and FoU source port setting Signed-off-by: Yusuke Suzuki --- v2/api/v2/egress_types.go | 12 ++---------- v2/api/v2/egress_webhook.go | 2 +- v2/api/v2/egress_webhook_test.go | 4 ++-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/v2/api/v2/egress_types.go b/v2/api/v2/egress_types.go index a4ea0ef3..d58ce55a 100644 --- a/v2/api/v2/egress_types.go +++ b/v2/api/v2/egress_types.go @@ -2,7 +2,6 @@ package v2 import ( "net" - "reflect" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -123,15 +122,8 @@ func (es EgressSpec) validate() field.ErrorList { return allErrs } -func (es EgressSpec) validateUpdate(old EgressSpec) field.ErrorList { - allErrs := es.validate() - p := field.NewPath("spec") - - if !reflect.DeepEqual(es.Destinations, old.Destinations) { - allErrs = append(allErrs, field.Forbidden(p.Child("destinations"), "unchangeable")) - } - - return allErrs +func (es EgressSpec) validateUpdate() field.ErrorList { + return es.validate() } // EgressStatus defines the observed state of Egress diff --git a/v2/api/v2/egress_webhook.go b/v2/api/v2/egress_webhook.go index 13d61db8..fc7f3990 100644 --- a/v2/api/v2/egress_webhook.go +++ b/v2/api/v2/egress_webhook.go @@ -54,7 +54,7 @@ func (r *Egress) ValidateCreate() error { // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type func (r *Egress) ValidateUpdate(old runtime.Object) error { - errs := r.Spec.validateUpdate(old.(*Egress).Spec) + errs := r.Spec.validateUpdate() if len(errs) == 0 { return nil } diff --git a/v2/api/v2/egress_webhook_test.go b/v2/api/v2/egress_webhook_test.go index 079e8fe8..3d4f09c0 100644 --- a/v2/api/v2/egress_webhook_test.go +++ b/v2/api/v2/egress_webhook_test.go @@ -145,14 +145,14 @@ var _ = Describe("Egress Webhook", func() { Expect(err).NotTo(HaveOccurred()) }) - It("should deny updating destinations", func() { + It("should allow updating destinations", func() { r := makeEgress() err := k8sClient.Create(ctx, r) Expect(err).NotTo(HaveOccurred()) r.Spec.Destinations = append(r.Spec.Destinations, "10.10.0.0/24") err = k8sClient.Update(ctx, r) - Expect(err).To(HaveOccurred()) + Expect(err).NotTo(HaveOccurred()) }) It("should deny invalid fields on update", func() {