Skip to content

Commit

Permalink
[release-1.1] SubscriptionSpec.Delivery is now mutable (#6258)
Browse files Browse the repository at this point in the history
* Make SubscriptionSpec.Delivery mutable

Just by creating a subscription in v0.24 and upgrading the cluster to
0.26, the webhook starts throwing errors like this:
```
admission webhook "validation.webhook.eventing.knative.dev" denied the request: validation failed: Immutable fields changed (-old +new): spec
{v1.SubscriptionSpec}.Delivery.DeadLetterSink.Ref.Namespace:
    -: ""
    +: "kc-broker-v1-dlq"
```

In addition, Subscription.Spec.Delivery wasn't meant to be immutable,
in fact, TriggerSpec.Spec.Delivery is mutable.

Signed-off-by: Pierangelo Di Pilato <[email protected]>

* Update subscription_validation_test.go

* code style

Co-authored-by: Pierangelo Di Pilato <[email protected]>
Co-authored-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
3 people authored Mar 15, 2022
1 parent 3459292 commit a2fffe2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/apis/messaging/v1/subscription_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *Subscription) CheckImmutableFields(ctx context.Context, original *Subsc
}

// Only Subscriber and Reply are mutable.
ignoreArguments := cmpopts.IgnoreFields(SubscriptionSpec{}, "Subscriber", "Reply")
ignoreArguments := cmpopts.IgnoreFields(SubscriptionSpec{}, "Subscriber", "Reply", "Delivery")
if diff, err := kmp.ShortDiff(original.Spec, s.Spec, ignoreArguments); err != nil {
return &apis.FieldError{
Message: "Failed to diff Subscription",
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/messaging/v1/subscription_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/google/go-cmp/cmp"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
pointer "knative.dev/pkg/ptr"

eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1"
"knative.dev/eventing/pkg/apis/feature"
Expand Down Expand Up @@ -528,6 +529,23 @@ func TestSubscriptionImmutable(t *testing.T) {
},
},
want: nil,
}, {
name: "valid, change delivery spec",
c: &Subscription{
Spec: SubscriptionSpec{
Channel: getValidChannelRef(),
Subscriber: getValidDestination(),
Delivery: &eventingduckv1.DeliverySpec{Retry: pointer.Int32(2)},
},
},
og: &Subscription{
Spec: SubscriptionSpec{
Channel: getValidChannelRef(),
Subscriber: getValidDestination(),
Delivery: &eventingduckv1.DeliverySpec{Retry: pointer.Int32(3)},
},
},
want: nil,
}, {
name: "Channel changed",
c: &Subscription{
Expand Down

0 comments on commit a2fffe2

Please sign in to comment.