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

🐛Check errors for IsNotFound after patching spec and status #10787

Merged

Conversation

troy0820
Copy link
Member

@troy0820 troy0820 commented Jun 21, 2024

What this PR does / why we need it:
This allows the patch helper to ignore patching the status when creating a patch.

The solution for the issue below was to check the object if the finalizers are removed and if the DeletionTimeStamp was not nil and the error after patching the status/spec was IsNotFound. This will cut down on noise as well as achieve with not exposing the internals of the patch helper.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

Fixes #10786

/area util

@k8s-ci-robot k8s-ci-robot added area/util Issues or PRs related to utils cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 21, 2024
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 21, 2024
@troy0820 troy0820 force-pushed the troy0820/patch-ignore-option branch from 2d389a3 to d6ac4de Compare June 21, 2024 15:42
util/patch/options.go Outdated Show resolved Hide resolved
util/patch/patch_test.go Outdated Show resolved Hide resolved
util/patch/patch_test.go Outdated Show resolved Hide resolved
@troy0820 troy0820 force-pushed the troy0820/patch-ignore-option branch from d6ac4de to 13dba33 Compare June 21, 2024 17:16
@k8s-ci-robot k8s-ci-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 Jun 21, 2024
@troy0820 troy0820 force-pushed the troy0820/patch-ignore-option branch 2 times, most recently from 0b48a19 to 42fa16e Compare June 21, 2024 22:15
@vincepri
Copy link
Member

/hold

going to comment on the issue on the reasoning for the hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 24, 2024
@troy0820 troy0820 force-pushed the troy0820/patch-ignore-option branch from 42fa16e to 1a51016 Compare July 11, 2024 13:39
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 11, 2024
@troy0820 troy0820 changed the title ✨Create StatusIgnore helper option for PatchHelper 🐛Check errors for IsNotFound after patching spec and status Jul 11, 2024
util/patch/patch.go Outdated Show resolved Hide resolved
@troy0820
Copy link
Member Author

/assign @sbueringer

@sbueringer
Copy link
Member

/test pull-cluster-api-e2e-main

if err := h.patchStatus(ctx, obj); err != nil {
errs = append(errs, err)
if !apierrors.IsNotFound(err) && !obj.GetDeletionTimestamp().IsZero() && len(obj.GetFinalizers()) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I think the if is not entirely correct

See

	if err := h.patchStatus(ctx, obj); err != nil {
		if !(apierrors.IsNotFound(err) && !obj.GetDeletionTimestamp().IsZero() && len(obj.GetFinalizers()) == 0) {
			errs = append(errs, err)
		}
	}
```

Copy link
Member Author

Choose a reason for hiding this comment

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

How did I forget the ( and the ) 🤦🏽‍♂️

This should be good to go now.

Copy link
Member

Choose a reason for hiding this comment

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

No worries, that's why we do reviews :)

Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
@troy0820 troy0820 force-pushed the troy0820/patch-ignore-option branch from 120874b to c8ae301 Compare July 15, 2024 13:10
@sbueringer
Copy link
Member

Thank you very much!!

/lgtm
/approve

/hold cancel

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jul 15, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: af7e5f0dfb22f0b35f80444857a1ed1c786d67b5

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 15, 2024
@sbueringer sbueringer added this to the v1.8 milestone Jul 15, 2024
@k8s-ci-robot k8s-ci-robot merged commit 6f06154 into kubernetes-sigs:main Jul 15, 2024
20 checks passed
if err := h.patchStatus(ctx, obj); err != nil {
errs = append(errs, err)
if !(apierrors.IsNotFound(err) && !obj.GetDeletionTimestamp().IsZero() && len(obj.GetFinalizers()) == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a test?

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 can add a test for this and submit a new PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

PR with the test #10866

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. area/util Issues or PRs related to utils cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding Patch Option to the patch helper to ignore patching the status
5 participants