-
Notifications
You must be signed in to change notification settings - Fork 593
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
Delete non used branch resources at Parallel #5775
Delete non used branch resources at Parallel #5775
Conversation
Hi @odacremolbap. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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/test-infra repository. |
/assign @devguyio |
Codecov Report
@@ Coverage Diff @@
## main #5775 +/- ##
==========================================
- Coverage 82.52% 82.39% -0.14%
==========================================
Files 203 204 +1
Lines 6376 6452 +76
==========================================
+ Hits 5262 5316 +54
- Misses 768 778 +10
- Partials 346 358 +12
Continue to review full report at Codecov.
|
bfa98e9
to
26d72a3
Compare
@@ -41,15 +42,14 @@ import ( | |||
parallelreconciler "knative.dev/eventing/pkg/client/injection/reconciler/flows/v1/parallel" | |||
listers "knative.dev/eventing/pkg/client/listers/flows/v1" | |||
messaginglisters "knative.dev/eventing/pkg/client/listers/messaging/v1" | |||
"knative.dev/eventing/pkg/duck" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import was duple of
ducklib "knative.dev/pkg/duck"
if p.DeletionTimestamp != nil { | ||
// Everything is cleaned up by the garbage collector. | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this. Reconciler generated code already checks for the object status and do not call ReconcileKind
when it is being deleted.
filterSubName := resources.ParallelFilterSubscriptionName(p.Name, branchNumber) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filterSubName
generates the same name that was used for filterExpected
. No need for that second call.
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
expected := resources.NewSubscription(branchNumber, p) | ||
subName := resources.ParallelSubscriptionName(p.Name, branchNumber) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subName
generates the same name that was used at expected
. No need for that second call.
func (r *Reconciler) reconcileSubscription(ctx context.Context, branchNumber int, expected *messagingv1.Subscription) (*messagingv1.Subscription, error) { | ||
sub, err := r.subscriptionLister.Subscriptions(expected.Namespace).Get(expected.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed subName
and ns
from the parameter list.
That data can be retrieved from the incoming subscription.
/ok-to-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sensible to me 👍
I'm a bit uncertain about these disconnected calls to the logger when we could wrap the entire error chain instead, but if that's the style in this package I'm happy to approve.
pkg/reconciler/parallel/parallel.go
Outdated
logging.FromContext(ctx).Errorw("Error getting lister for Channel", zap.Any("channelRef", channelObjRef), zap.Error(err)) | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of these calls to the logger inside this function, I think it would be helpful to wrap the error, e.g. with
return fmt.Errorf("error getting lister for Channel: %w", err)
and likewise wrap that inside ReconcileKind()
with
return fmt.Errorf("error removing unwanted channels: %w", err)
This way, when Knative finally logs the error, it contains the whole chain of events that occurred, instead of multiple logger calls which might be hard to relate to one another:
Failed reconciliation: error removing unwanted channels: error getting lister for Channel: <the actual error>
Unless channelRef
really needs its own field in the structured message. In that case, please ignore my suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/reconciler/parallel/parallel.go
Outdated
return err | ||
} | ||
|
||
exists, err := l.ByNamespace(p.GetNamespace()).List(labels.Everything()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: When I see exists
I immediately imagine a boolean value. Maybe that's just me 😄
Still, I think it would be more natural to call that variable channels
, allChannels
, or something in that direction. which IMO reads better in the range
just below:
for _, c := range channels { /* ... */ }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/reconciler/parallel/parallel.go
Outdated
for _, c := range exists { | ||
ch, err := kmeta.DeletionHandlingAccessor(c) | ||
if err != nil { | ||
logging.FromContext(ctx).Errorw("Failed to get channel", zap.Any("channel", c), zap.Error(err)) | ||
return err | ||
} | ||
|
||
if !ch.GetDeletionTimestamp().IsZero() || | ||
!metav1.IsControlledBy(ch, p) { | ||
continue | ||
} | ||
|
||
used := false | ||
for _, cw := range wanted { | ||
if cw.Name == ch.GetName() { | ||
used = true | ||
break | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general observation about this method:
It might be more efficient and clearer to just initialize two sets of Channel names:
- one with all the "wanted" ones
- one with the ones we "own"
Then delete all channels returned by owned.Difference(wanted)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antoineco thanks for the review. All comments should have been taken care of here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
nit: You use capitalized Subscription
in some errors, lowercase in others. Same for Channels
.
Approving with a hold in case you want to address, just unhold if you think it's not important.
/lgtm
/hold
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: antoineco, odacremolbap 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 |
The following is the coverage report on the affected files.
|
/lgtm |
/unhold |
Fixes #5757
Parallel reconciliation now checks for owned and not deleting channels and subscriptions:
See #5718 for the already merged Sequence counterpart
I also removed what seemed to be some not needed calls at the existing code. If reviewers ask to remove them from clarity I will happily remove them from here and take them to a new PR.
Proposed Changes
Pre-review Checklist
Release Note