Skip to content

📖 (docs): Show webhook configuration in cronjob tutorial #5257

Merged
k8s-ci-robot merged 1 commit intokubernetes-sigs:masterfrom
BadisLaffet1:docs-fix-webhook-config-collapse-main
Dec 9, 2025
Merged

📖 (docs): Show webhook configuration in cronjob tutorial #5257
k8s-ci-robot merged 1 commit intokubernetes-sigs:masterfrom
BadisLaffet1:docs-fix-webhook-config-collapse-main

Conversation

@BadisLaffet1
Copy link
Contributor

📖 (docs): Show webhook configuration in cronjob tutorial

Fixes #5238

Problem

The webhook setup code in cmd/main.go was hidden in the cronjob tutorial's main-revisited page.

Root Cause

The cronjob tutorial generator was adding a collapse marker at the end of cmd/main.go (lines 371-380), which collapsed everything after the controller setup, including the webhook configuration that users needed to see.

Discovery: Multiversion Dependency

Found that multiversion tutorial has interdependent code:

Line 79 in generate_multiversion.go:

cmd := exec.Command("cp", "./../../../cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go", ...)

The multiversion tutorial copies files from cronjob, then has logic expecting certain markers to exist. This dependency required changes to both files.

Changes Made

File 1: hack/docs/internal/cronjob-tutorial/generate_cronjob.go

Function: updateMain()
Lines deleted: 371-380

Code removed:

err = pluginutil.InsertCode(
    filepath.Join(sp.ctx.Dir, "cmd/main.go"),
    `setupLog.Error(err, "problem running manager")
    os.Exit(1)
}
}`, `
// +kubebuilder:docs-gen:collapse=Remaining code from main.go`)
hackutils.CheckError("fixing main.go", err)

Why: This code was inserting a collapse marker at the end of main.go:

// +kubebuilder:docs-gen:collapse=Remaining code from main.go

This marker collapsed everything from controller setup to the end of file, hiding the webhook configuration (issue 5238).


File 2: hack/docs/internal/multiversion-tutorial/generate_multiversion.go

Function: updateMain()
Lines deleted: 686-703 (two blocks)

Block 1 (lines 686-694)

Code removed:

err = pluginutil.InsertCode(
    filepath.Join(sp.ctx.Dir, path),
    `setupLog.Error(err, "problem running manager")
    os.Exit(1)
}
}`, `
// +kubebuilder:docs-gen:collapse=Remaining code from main.go`,
)
hackutils.CheckError("update main.go with final collapse marker", err)

What it did: Added the same collapse marker in multiversion's main.go

Block 2 (lines 696-703)

Code removed:

err = pluginutil.ReplaceInFile(
    filepath.Join(sp.ctx.Dir, path),
    `// +kubebuilder:docs-gen:collapse=Remaining code from main.go

// +kubebuilder:docs-gen:collapse=Remaining code from main.go`, ``,
)
hackutils.CheckError("update main.go to remove final collapses", err)

What it did: Searched for and removed duplicate collapse markers (two consecutive identical markers)


Why Both Multiversion Blocks Were Removed

The problem: Block 2 expected to find duplicate markers (one from cronjob, one from Block 1). After removing the cronjob marker, this pattern no longer exists, causing build error: "unable to find the content to be replaced"

Three options considered:

  1. Keep both blocks → Fixes the issue but build fails (Block 2 can't find duplicates).
  2. Remove only Block 2 →Fixes the issue but block 1 hides webhooks in multiversion .
  3. Remove both blocks → Fixes the issue and prevent changes on multiversion.

Result

The webhook configuration is now visible in main-revisited page :
Multiversion tutorial remains unchanged

Screenshot showing webhook configuration now visible

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 7, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @BadisLaffet1. Thanks for your PR.

I'm waiting for a github.com 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.

Details

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.

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
/approved

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 9, 2025
@camilamacedo86
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 9, 2025
Copy link
Contributor

@vitorfloriano vitorfloriano left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BadisLaffet1, camilamacedo86, vitorfloriano

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 merged commit fe57ef9 into kubernetes-sigs:master Dec 9, 2025
25 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/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: Webhook config should not be collapsed

4 participants