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

Skip ownership check for resources with exists annotation #522

Merged
merged 1 commit into from
Jun 14, 2022

Conversation

praveenrewar
Copy link
Member

@praveenrewar praveenrewar commented Jun 2, 2022

What this PR does / why we need it:

Skip ownership check for resources with kapp.k14s.io/exists and kapp.k14s.io/noop annotations as these resources could be created by another kapp app.

Which issue(s) this PR fixes:

Fixes #457

Does this PR introduce a user-facing change?

NONE

Additional Notes for your reviewer:

Review Checklist:
  • Follows the developer guidelines
  • Relevant tests are added or updated
  • Relevant docs in this repo added or updated
  • Relevant carvel.dev docs added or updated in a separate PR and there's
    a link to that PR
  • Code is at least as readable and maintainable as it was before this
    change

Additional documentation e.g., Proposal, usage docs, etc.:


@praveenrewar praveenrewar marked this pull request as ready for review June 3, 2022 15:03
@praveenrewar praveenrewar requested review from a team and cppforlife June 3, 2022 15:03
Copy link
Contributor

@100mik 100mik left a comment

Choose a reason for hiding this comment

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

Much TDD 😆
LGTM!

@@ -144,7 +149,9 @@ func (a *LabeledResources) checkResourceOwnership(resources []Resource, opts All
var errs []error

for _, res := range resources {
if val, found := res.Labels()[expectedLabelKey]; found {
val, hasExpectedLabelKey := res.Labels()[expectedLabelKey]
_, hasExistsAnnotation := res.Annotations()[ExistsAnnKey]
Copy link
Member Author

Choose a reason for hiding this comment

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

I just realised that the res over here is an existing resource and not a new resource. The test case is passing because the exists ann is also added to the resource deployed via kubectl. I will make relevant changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Skip ownership check for resources with kapp.k14s.io/exists annotation and kapp.k14s.io/noop annotation
@@ -135,6 +143,28 @@ func (a *LabeledResources) AllAndMatching(newResources []Resource, opts AllAndMa
return resources, nil
}

func (a *LabeledResources) resourcesForOwnershipCheck(newResources []Resource, nonLabeledResources []Resource) []Resource {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can drop receiver name a

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

Comment on lines +159 to +163
for _, res := range nonLabeledResources {
if !resourcesToBeSkipped[NewUniqueResourceKey(res).String()] {
resources = append(resources, res)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

dont we actually want to verify the ownership of non-new resources as well? or is this not how it works today since because we only find non labeled resources based on new resources?

Copy link
Member Author

Choose a reason for hiding this comment

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

(I have read it a few times, but I am still not sure if I have understood it properly 😅 )

or is this not how it works today since because we only find non labeled resources based on new resources?

Yeah, we find the non labeled resources based on the new resources and the labeled resources.
https://github.com/vmware-tanzu/carvel-kapp/blob/31e7abfc48f00ab81fda9ca0235062e9e33ca7c1/pkg/kapp/resources/labeled_resources.go#L213

@cppforlife cppforlife merged commit dab63af into develop Jun 14, 2022
@praveenrewar praveenrewar deleted the exists-annotation branch March 28, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting ownership error when using exists annotation for resources created by kapp-controller App CRs
4 participants