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

[WIP] 🌱 Enable webhook envtests #5722

Closed

Conversation

sbueringer
Copy link
Member

@sbueringer sbueringer commented Nov 23, 2021

What this PR does / why we need it:

WIP => currently mostly a PoC to discuss if we want to address the issue this way.

DOES NOT WORK RIGHT NOW

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 #5721

Signed-off-by: Stefan Büringer [email protected]
Signed-off-by: Stefan Büringer [email protected]
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 23, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign cecilerobertmichon after the PR has been reviewed.
You can assign the PR to them by writing /assign @cecilerobertmichon in a comment when ready.

The full list of commands accepted by this bot can be found 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 23, 2021
)

// SetupWebhooksWithManager sets up all webhooks of the current package.
func SetupWebhooksWithManager(mgr ctrl.Manager) error {
Copy link
Member Author

@sbueringer sbueringer Nov 23, 2021

Choose a reason for hiding this comment

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

We don't necessarily need the package level functions to avoid the circular dependencies, but they would avoid some repetition (otherwise we would have to inline those funcs, aka we would need the full list of resources in all those cases)

@@ -216,18 +216,10 @@ func setupWebhooks(mgr ctrl.Manager) {
setupLog.Error(err, "unable to create webhook", "webhook", "KubeadmConfig")
os.Exit(1)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have to register those webhooks (we don't register any other List webhooks)

@@ -69,6 +68,9 @@ func init() {
klog.SetOutput(ginkgo.GinkgoWriter)

// Calculate the scheme.
// FIXME(tbd): if we want to enable envtests in those packages too we
Copy link
Member Author

Choose a reason for hiding this comment

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

TBD

)

// AllWebhooksWithManager sets up all webhooks.
func AllWebhooksWithManager(mgr ctrl.Manager) {
Copy link
Member Author

Choose a reason for hiding this comment

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

In theory we also don't need this helper to avoid circular dependencies, but the alternative would be to inline it and have the list of webhooks redundantly

ctx = ctrl.SetupSignalHandler()
)

// FIXME(sbueringer): just part of this PR to prove that it works.
Copy link
Member Author

Choose a reason for hiding this comment

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

Just to prove the concept works, should be removed before merge

return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
// SetupWebhooksWithManager sets up all webhooks of the current package.
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: that github diff is really weird (it's just a new file)

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Nov 23, 2021

@sbueringer: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-apidiff-main 3cff8d2 link false /test pull-cluster-api-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@sbueringer
Copy link
Member Author

@killianmuldoon @fabriziopandini This PR is meant as a starting point for the discussion on how the solve the issue.

tl;dr is

  • we can't just register all webhooks in the envtest package because then envtest won't be usable in webhook envtests
    • => so we have to move them out of there
  • naive solution would be to just register all webhooks in the suite_test.go files.
    • => To avoid the redundancy I added two layers of helper, which both are not strictly necessary to avoid the circular dependency but avoid a lot of repetition.
      • Tests which require all webhooks can just use the setup func
      • webhook envtests have to individually register the required webhooks (because they cannot use the helper func because this would introduce a circular dependency)

P.S. apidiff would be fixed via deprecation if we want

@sbueringer
Copy link
Member Author

sbueringer commented Nov 23, 2021

I've discussed the issue with Fabrizio and we would simply implement the webhooks integration test in a package like internal/webhooks/integration instead of refactoring envtest like proposed in this PR.

The problem with this PR is that it distributes the webhook setup all over the place vs. currently webhooks will just work out of the box when using envtest.

Let's continue the discussion on the issue

@sbueringer
Copy link
Member Author

/close

@k8s-ci-robot
Copy link
Contributor

@sbueringer: Closed this PR.

In response to this:

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable envtest-based unit tests for webhooks
2 participants