Skip to content

Commit

Permalink
Ease the restriction for Egress
Browse files Browse the repository at this point in the history
This commits eases the restriction for Egress to allow users to
change Destinations and FoU source port setting

Signed-off-by: Yusuke Suzuki <[email protected]>
  • Loading branch information
ysksuzuki committed Oct 1, 2023
1 parent 972b5cb commit 32dc538
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
12 changes: 2 additions & 10 deletions v2/api/v2/egress_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v2

import (
"net"
"reflect"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion v2/api/v2/egress_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions v2/api/v2/egress_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 32dc538

Please sign in to comment.