Skip to content

Conversation

@wazery
Copy link
Contributor

@wazery wazery commented Sep 1, 2025

This PR introduces an e2e test to validate webhook conversion between versions, as part of the multiversion tutorial e2e tests.

Fixes: #4255

@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 Sep 1, 2025
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 1, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @wazery. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

@wazery wazery force-pushed the w-webhook-conversion-e2e-test branch 2 times, most recently from 2fda561 to 681bf43 Compare September 1, 2025 19:56
@wazery wazery marked this pull request as ready for review September 1, 2025 22:16
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 1, 2025
@wazery wazery force-pushed the w-webhook-conversion-e2e-test branch from 681bf43 to d65d418 Compare September 2, 2025 13:19
@k8s-ci-robot k8s-ci-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 Sep 2, 2025
@wazery wazery force-pushed the w-webhook-conversion-e2e-test branch 2 times, most recently from effbdb8 to 6d31a62 Compare September 2, 2025 13:42
@wazery wazery force-pushed the w-webhook-conversion-e2e-test branch 2 times, most recently from 9fab9f8 to 6d8d9f7 Compare September 2, 2025 15:35
@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 Sep 2, 2025
@wazery wazery force-pushed the w-webhook-conversion-e2e-test branch 3 times, most recently from e79777c to 941df82 Compare September 9, 2025 12:03
@camilamacedo86
Copy link
Member

camilamacedo86 commented Sep 13, 2025

/ok-to-test

Thank you for the contirbution 🥇
But it is not really checking the conversion yet.
See how we do the same in our e2e tests, https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/e2e/v4/plugin_cluster_test.go#L389-L432

We would need to do something very similar to that.

@wazery wazery force-pushed the w-webhook-conversion-e2e-test branch from 1361e7e to 2891ee8 Compare October 26, 2025 21:14
@camilamacedo86
Copy link
Member

/override pull-kubebuilder-e2e-k8s-1-34-0

@k8s-ci-robot
Copy link
Contributor

@camilamacedo86: Overrode contexts on behalf of camilamacedo86: pull-kubebuilder-e2e-k8s-1-34-0

In response to this:

/override pull-kubebuilder-e2e-k8s-1-34-0

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.

@wazery wazery force-pushed the w-webhook-conversion-e2e-test branch from 2891ee8 to 5921329 Compare October 27, 2025 12:56
@wazery
Copy link
Contributor Author

wazery commented Oct 27, 2025

/override pull-kubebuilder-e2e-k8s-1-34-1

@k8s-ci-robot
Copy link
Contributor

@wazery: wazery unauthorized: /override is restricted to Repo administrators.

In response to this:

/override pull-kubebuilder-e2e-k8s-1-34-1

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.

@wazery wazery force-pushed the w-webhook-conversion-e2e-test branch from 5921329 to e7a133f Compare October 27, 2025 19:00
@wazery wazery requested a review from camilamacedo86 October 27, 2025 19:37
@wazery
Copy link
Contributor Author

wazery commented Oct 27, 2025

@camilamacedo86 I just fixed the failing test, hope the PR is ready now for merge.

@camilamacedo86
Copy link
Member

/override pull-kubebuilder-e2e-k8s-1-34-1

/override pull-kubebuilder-e2e-k8s-1-34-0

@k8s-ci-robot
Copy link
Contributor

@camilamacedo86: /override requires failed status contexts, check run or a prowjob name to operate on.
The following unknown contexts/checkruns were given:

  • pull-kubebuilder-e2e-k8s-1-34-1

Only the following failed contexts/checkruns were expected:

  • EasyCLA
  • netlify/kubebuilder/deploy-preview
  • pull-kubebuilder-e2e-k8s-1-32-0
  • pull-kubebuilder-e2e-k8s-1-33-0
  • pull-kubebuilder-e2e-k8s-1-34-0
  • pull-kubebuilder-test
  • tide

If you are trying to override a checkrun that has a space in it, you must put a double quote on the context.

In response to this:

/override pull-kubebuilder-e2e-k8s-1-34-1

/override pull-kubebuilder-e2e-k8s-1-34-0

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.

@camilamacedo86
Copy link
Member

/override pull-kubebuilder-e2e-k8s-1-34-0

@k8s-ci-robot
Copy link
Contributor

@camilamacedo86: Overrode contexts on behalf of camilamacedo86: pull-kubebuilder-e2e-k8s-1-34-0

In response to this:

/override pull-kubebuilder-e2e-k8s-1-34-0

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.

- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure`

newTextV1 := ` template:
Copy link
Member

Choose a reason for hiding this comment

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

We should instead update the places where those values are defined instead
See: https://github.com/kubernetes-sigs/kubebuilder/blob/master/hack/docs/internal/cronjob-tutorial/sample.go#L19-L34

We can replace all this implementation and just update the const.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just addressed it, many thanks for the pointer.

@wazery wazery force-pushed the w-webhook-conversion-e2e-test branch from e7a133f to a305b10 Compare October 27, 2025 20:08
@wazery wazery requested a review from camilamacedo86 October 27, 2025 20:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances security for Kubernetes CronJob samples across tutorials and adds comprehensive end-to-end tests for webhook conversion functionality. The changes add security contexts at both pod and container levels following Kubernetes security best practices.

  • Adds pod-level and container-level security contexts to all CronJob sample YAML files
  • Implements new e2e test for webhook conversion between v1 and v2 CronJob versions
  • Updates test infrastructure to include proper cleanup of test resources

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
hack/docs/internal/multiversion-tutorial/samples.go Updates the v2 sample code template to include security contexts
hack/docs/internal/cronjob-tutorial/sample.go Updates the cronjob sample code template to include security contexts
hack/docs/internal/multiversion-tutorial/generate_multiversion.go Adds new function to inject webhook conversion e2e test and test cleanup
docs/book/src/multiversion-tutorial/testdata/project/test/e2e/e2e_test.go Adds webhook conversion test and resource cleanup in AfterEach hook
docs/book/src/multiversion-tutorial/testdata/project/config/samples/batch_v2_cronjob.yaml Adds security contexts to the v2 CronJob sample
docs/book/src/multiversion-tutorial/testdata/project/config/samples/batch_v1_cronjob.yaml Adds security contexts to the v1 CronJob sample
docs/book/src/cronjob-tutorial/testdata/project/config/samples/batch_v1_cronjob.yaml Adds security contexts to the cronjob tutorial sample

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred(), "Failed to create v1 CronJob")

By("waiting for the v1 CronJob to be created")
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation: this By statement uses tabs instead of the expected tab+spaces pattern. It should be indented with three tabs to align with the surrounding code within the It block.

Suggested change
By("waiting for the v1 CronJob to be created")
By("waiting for the v1 CronJob to be created")

Copilot uses AI. Check for mistakes.
Comment on lines +371 to +376
cmd = exec.Command("kubectl", "get", "cronjob.v1.batch.tutorial.kubebuilder.io", "cronjob-sample",
"-n", namespace, "-o", "jsonpath={.spec.schedule}")
v1Schedule, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred(), "Failed to get v1 CronJob schedule")
Expect(strings.TrimSpace(v1Schedule)).To(Equal("*/1 * * * *"),
"v1 schedule should be in cron format")
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation: lines 371-376 use an extra level of indentation. The code following the By statement should be indented with three tabs, not three tabs plus spaces.

Suggested change
cmd = exec.Command("kubectl", "get", "cronjob.v1.batch.tutorial.kubebuilder.io", "cronjob-sample",
"-n", namespace, "-o", "jsonpath={.spec.schedule}")
v1Schedule, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred(), "Failed to get v1 CronJob schedule")
Expect(strings.TrimSpace(v1Schedule)).To(Equal("*/1 * * * *"),
"v1 schedule should be in cron format")
cmd = exec.Command("kubectl", "get", "cronjob.v1.batch.tutorial.kubebuilder.io", "cronjob-sample",
"-n", namespace, "-o", "jsonpath={.spec.schedule}")
v1Schedule, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred(), "Failed to get v1 CronJob schedule")
Expect(strings.TrimSpace(v1Schedule)).To(Equal("*/1 * * * *"),
"v1 schedule should be in cron format")

Copilot uses AI. Check for mistakes.
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred(), "Failed to create v1 CronJob")
By("waiting for the v1 CronJob to be created")
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation in the generated test template: this By statement should be indented with three tabs to align with the surrounding code within the It block.

Suggested change
By("waiting for the v1 CronJob to be created")
By("waiting for the v1 CronJob to be created")

Copilot uses AI. Check for mistakes.
Comment on lines +826 to +831
cmd = exec.Command("kubectl", "get", "cronjob.v1.batch.tutorial.kubebuilder.io", "cronjob-sample",
"-n", namespace, "-o", "jsonpath={.spec.schedule}")
v1Schedule, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred(), "Failed to get v1 CronJob schedule")
Expect(strings.TrimSpace(v1Schedule)).To(Equal("*/1 * * * *"),
"v1 schedule should be in cron format")
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation in the generated test template: lines 826-831 use an extra level of indentation. The code following the By statement should be indented with three tabs, matching the pattern used in other By blocks.

Suggested change
cmd = exec.Command("kubectl", "get", "cronjob.v1.batch.tutorial.kubebuilder.io", "cronjob-sample",
"-n", namespace, "-o", "jsonpath={.spec.schedule}")
v1Schedule, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred(), "Failed to get v1 CronJob schedule")
Expect(strings.TrimSpace(v1Schedule)).To(Equal("*/1 * * * *"),
"v1 schedule should be in cron format")
cmd = exec.Command("kubectl", "get", "cronjob.v1.batch.tutorial.kubebuilder.io", "cronjob-sample",
"-n", namespace, "-o", "jsonpath={.spec.schedule}")
v1Schedule, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred(), "Failed to get v1 CronJob schedule")
Expect(strings.TrimSpace(v1Schedule)).To(Equal("*/1 * * * *"),
"v1 schedule should be in cron format")

Copilot uses AI. Check for mistakes.
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm

I think we can fix the spaces in a follow up.
Thank you 🥇

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 2, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, wazery

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 Nov 2, 2025
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Nov 2, 2025

@wazery: 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-kubebuilder-e2e-k8s-1-34-1 1361e7e link true /test pull-kubebuilder-e2e-k8s-1-34-1

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

@camilamacedo86
Copy link
Member

/test pull-kubebuilder-e2e-k8s-1-32-0

@k8s-ci-robot k8s-ci-robot merged commit 78fbec7 into kubernetes-sigs:master Nov 2, 2025
70 of 76 checks passed
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. 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Add e2e test to validate webhook conversion from one version to another

3 participants