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

Don't rely on in-reconciler state to determine last-in-cluster. #33

Merged
merged 1 commit into from
Apr 28, 2020

Conversation

markusthoemmes
Copy link
Contributor

Proposed Changes

Trying to determine the last resource in the cluster via state kept in the reconciler is racy and error-prone. Ask the API instead.

Deployments should also be removed via the ownerRef. An explicit deletion shouldn't be necessary.

Release Note

NONE

/assign @houshengbo @jcrossley3 @aliok

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Apr 27, 2020
@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 27, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@markusthoemmes: 0 warnings.

In response to this:

Proposed Changes

Trying to determine the last resource in the cluster via state kept in the reconciler is racy and error-prone. Ask the API instead.

Deployments should also be removed via the ownerRef. An explicit deletion shouldn't be necessary.

Release Note

NONE

/assign @houshengbo @jcrossley3 @aliok

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.

@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 27, 2020
@knative-prow-robot
Copy link
Contributor

Hi @markusthoemmes. Thanks for your PR.

I'm waiting for a knative-sandbox member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

Copy link
Contributor

@jcrossley3 jcrossley3 left a comment

Choose a reason for hiding this comment

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

Looks good. Makes sense. Thanks! Just a couple questions.

return fmt.Errorf("failed to list all KnativeEventings: %w", err)
}

if len(kes.Items) == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious whether there's also a race condition here. Specifically, if the API server tells us there are 2 while both are being deleted, is it safe to rely on the other's reconcile loop to delete the cluster-scoped resources? I assume so, but just checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, you are right. I'll make this a little more bulletproof by checking if all items have a DeletionTimestamp set, i.e.: All resources are being deleted.

return fmt.Errorf("failed to list all KnativeServings: %w", err)
}

if len(kes.Items) == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question above applies, but also makes me wonder if we can factor this "delete the RBAC last" logic into a shared lib.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We probably can, yes. This is part of a larger refactor which I wanted to get through first before consolidating too much.

if allBeingDeleted {
// If the list has only one element, we're currently reconciling the last one and thus
// can go ahead and delete cluster-scoped resources.
manifest, err := r.transform(ctx, instance)
Copy link
Contributor

Choose a reason for hiding this comment

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

Along the line 263 before, you use r.transform(instance), but add ctx as another param here. Which one should be the correct one?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. they are two different functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both will eventually have a ctx once I land a followup of this that will use genreconciler for KnativeEventing as well.

It boils down to logger usage: We should always use the logger in the context, because it has all the... well... context already set to it.

@markusthoemmes
Copy link
Contributor Author

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 27, 2020
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 28, 2020
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 28, 2020
Copy link
Contributor

@houshengbo houshengbo left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 28, 2020
@houshengbo
Copy link
Contributor

/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: houshengbo, markusthoemmes

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-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 28, 2020
@houshengbo
Copy link
Contributor

/test pull-knative-sandbox-operator-integration-tests

@markusthoemmes
Copy link
Contributor Author

hmpf, rebase mistake.

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Apr 28, 2020
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 28, 2020
@houshengbo
Copy link
Contributor

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 28, 2020
@knative-prow-robot
Copy link
Contributor

@markusthoemmes: PR needs rebase.

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.

@houshengbo houshengbo removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 28, 2020
@knative-prow-robot knative-prow-robot merged commit e1d9ea9 into knative:master Apr 28, 2020
matzew added a commit to matzew/knative-operator that referenced this pull request Sep 10, 2020
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

6 participants