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

Error aggregation for Validation Webhooks #154

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

k-keiichi-rh
Copy link
Contributor

Why we need this PR

Refactoring for Validation Webhooks with error aggregation
This is suggested here.

Changes made

Run all validations and return an aggregated error

Copy link
Contributor

openshift-ci bot commented Aug 29, 2024

Hi @k-keiichi-rh. Thanks for your PR.

I'm waiting for a medik8s 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-sigs/prow repository.

@razo7
Copy link
Member

razo7 commented Aug 29, 2024

/ok-to-test

@razo7
Copy link
Member

razo7 commented Sep 1, 2024

/retest

validateStrategy(farSpec.RemediationStrategy),
})

return nil, aggregated
Copy link
Member

@razo7 razo7 Sep 7, 2024

Choose a reason for hiding this comment

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

NIT: unrelated to this change but it would be clearer to return an empty warning instead of a nil.

Suggested change
return nil, aggregated
return admission.Warnings{}, aggregated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion. I will fix it as you mentioned.
After applying this change, I got the following error in the unit tests:

  > Enter [It] should be denied - /home/kii/git/kii/fence-agents-remediation/api/v1alpha1/fenceagentsremediation_webhook_test.go:50 @ 09/22/24 09:23:38.584
  2024-09-22T09:23:38-04:00     INFO    fenceagentsremediation-resource validate create {"name": "test-fence_ipmilan"}
  [FAILED] Unexpected non-nil/non-zero argument at index 0:
        <admission.Warnings>: admission.Warnings{}
  In [It] at: /home/kii/git/kii/fence-agents-remediation/vendor/github.com/onsi/gomega/internal/assertion.go:62 @ 09/22/24 09:23:38.584

I can simply avoid this error with the following:
[Before]

Expect(outOfServiceStrategy.ValidateCreate()).Error().To(MatchError(ContainSubstring(outOfServiceTaintUnsupportedMsg)))

[After]

_, err := outOfServiceStrategy.ValidateCreate()
Expect(err).To(MatchError(ContainSubstring(outOfServiceTaintUnsupportedMsg)))

But I think it's not a smart fix to avoid this error. Is there another good way to fix?

Copy link
Member

Choose a reason for hiding this comment

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

Is there another good way to fix?

We can simply test whether the admission warning is empty

warnings, err := outOfServiceStrategy.ValidateCreate()
ExpectWithOffset(1, warnings).To(BeEmpty())
Expect(err).To(MatchError(ContainSubstring(outOfServiceTaintUnsupportedMsg)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the comment. I fixed it as you suggested.

@razo7
Copy link
Member

razo7 commented Sep 27, 2024

/approve
/retest

Copy link
Contributor

openshift-ci bot commented Sep 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: k-keiichi-rh, razo7

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

@razo7
Copy link
Member

razo7 commented Sep 27, 2024

/retest

@k-keiichi-rh
Copy link
Contributor Author

/test 4.16-openshift-e2e
/test 4.17-openshift-e2e

@razo7
Copy link
Member

razo7 commented Sep 30, 2024

/retest

@k-keiichi-rh
Copy link
Contributor Author

/test 4.16-openshift-e2e
/test 4.17-openshift-e2e

@razo7
Copy link
Member

razo7 commented Oct 8, 2024

/test 4.16-openshift-e2e

2 similar comments
@k-keiichi-rh
Copy link
Contributor Author

/test 4.16-openshift-e2e

@k-keiichi-rh
Copy link
Contributor Author

/test 4.16-openshift-e2e

@razo7
Copy link
Member

razo7 commented Nov 15, 2024

/retest

@razo7
Copy link
Member

razo7 commented Nov 15, 2024

Trying again after #159 changes

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.

2 participants