Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sequence updates subscription where possible, instead of recreating it #7948

Conversation

Cali0707
Copy link
Member

Fixes #7939

Proposed Changes

  • Check if the changed fields in a subscription are mutable or immutable, and update or recreate accordingly
  • Update unit tests to watch for updates where appropriate

Release Note

sequences now update subscriptions instead of recreating them, where possible

…mmutable fields

Signed-off-by: Calum Murray <cmurray@redhat.com>
…iptions

Signed-off-by: Calum Murray <cmurray@redhat.com>
@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 28, 2024
@Cali0707
Copy link
Member Author

/cc @pierDipi @creydr

@knative-prow knative-prow bot requested a review from creydr May 28, 2024 18:14
@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 28, 2024
@knative-prow knative-prow bot requested a review from pierDipi May 28, 2024 18:14
Copy link

codecov bot commented May 28, 2024

Codecov Report

Attention: Patch coverage is 42.85714% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 69.55%. Comparing base (abdbf14) to head (924f7a6).
Report is 9 commits behind head on main.

Files Patch % Lines
pkg/reconciler/sequence/sequence.go 42.85% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7948      +/-   ##
==========================================
+ Coverage   69.51%   69.55%   +0.03%     
==========================================
  Files         344      344              
  Lines       15994    16055      +61     
==========================================
+ Hits        11119    11167      +48     
- Misses       4189     4199      +10     
- Partials      686      689       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Cali0707
Copy link
Member Author

Once this fix is in, I think implementing the same change for Parallels would be a good first issue

@@ -190,7 +192,7 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, step int, p *v1.
// TODO: Send events here, or elsewhere?
//r.Recorder.Eventf(p, corev1.EventTypeWarning, subscriptionCreateFailed, "Create Sequences's subscription failed: %v", err)
return nil, fmt.Errorf("failed to get subscription: %s", err)
} else if !equality.Semantic.DeepDerivative(expected.Spec, sub.Spec) {
} else if equal, err := kmp.SafeEqual(sub.Spec, expected.Spec, ignoreArguments); !equal || err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As only .spec.channel is relevant here, we could also compare only these fields (instead of using ignoreArguments). So this might be a bit more self speaking directly 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is spec.channel the only immutable field? I just took this check from the validation webhook to make sure that the change is allowable. Maybe we cold just refactor that into its own function and call it here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had it from the comment Given that spec.channel is immutable.... Also in the SubscriptionSpec this is the only one marked as immutable:

type SubscriptionSpec struct {
// Reference to a channel that will be used to create the subscription
// You can specify only the following fields of the KReference:
// - Kind
// - APIVersion
// - Name
// - Namespace
// The resource pointed by this KReference must meet the
// contract to the ChannelableSpec duck type. If the resource does not
// meet this contract it will be reflected in the Subscription's status.
//
// This field is immutable. We have no good answer on what happens to
// the events that are currently in the channel being consumed from
// and what the semantics there should be. For now, you can always
// delete the Subscription and recreate it to point to a different
// channel, giving the user more control over what semantics should
// be used (drain the channel first, possibly have events dropped,
// etc.)
Channel duckv1.KReference `json:"channel"`
// Subscriber is reference to function for processing events.
// Events from the Channel will be delivered here and replies are
// sent to a Destination as specified by the Reply.
Subscriber *duckv1.Destination `json:"subscriber,omitempty"`
// Reply specifies (optionally) how to handle events returned from
// the Subscriber target.
// +optional
Reply *duckv1.Destination `json:"reply,omitempty"`
// Delivery configuration
// +optional
Delivery *eventingduckv1.DeliverySpec `json:"delivery,omitempty"`
}

But aligning with the webhook code (via function call) makes sense to me

Signed-off-by: Calum Murray <cmurray@redhat.com>
@Cali0707
Copy link
Member Author

/cc @creydr

@knative-prow knative-prow bot requested a review from creydr May 30, 2024 17:22
Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jun 3, 2024
Copy link

knative-prow bot commented Jun 3, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Cali0707, pierDipi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot merged commit 3ee2400 into knative:main Jun 3, 2024
33 of 36 checks passed
@Cali0707
Copy link
Member Author

Cali0707 commented Jun 3, 2024

/cherry-pick release-1.13

@Cali0707
Copy link
Member Author

Cali0707 commented Jun 3, 2024

/cherry-pick release-1.14

@knative-prow-robot
Copy link
Contributor

@Cali0707: new pull request created: #7959

In response to this:

/cherry-pick release-1.13

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow-robot
Copy link
Contributor

@Cali0707: new pull request created: #7960

In response to this:

/cherry-pick release-1.14

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not re-create subscription on sequence update
4 participants