Skip to content

🐛 (for all generators): fix being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work - #1387

Open
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:fix-ignore

Conversation

@camilamacedo86

@camilamacedo86 camilamacedo86 commented Apr 21, 2026

Copy link
Copy Markdown
Member

Package-level markers like +kubebuilder:rbac, +kubebuilder:webhook, +groupName, etc. were silently ignored when placed directly above

Both styles now work (backward compatible):

  • With blank line (already worked)
  • Without blank line (now fixed)

Closes #551

Assisted-by: Claude

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 21, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: camilamacedo86
Once this PR has been reviewed and has the lgtm label, please assign alvaroaleman for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 21, 2026
@camilamacedo86
camilamacedo86 force-pushed the fix-ignore branch 3 times, most recently from db6eb15 to 63f65f3 Compare April 21, 2026 05:43
@camilamacedo86 camilamacedo86 changed the title WIP: fix(package-level markers;RBAC, webhook, CRD, deepcopy, applyconfiguration) being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work WIP: fix being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work Apr 21, 2026
@camilamacedo86 camilamacedo86 changed the title WIP: fix being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work 🐛 fix being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work Apr 21, 2026
@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 Apr 21, 2026
@camilamacedo86 camilamacedo86 changed the title 🐛 fix being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work 🐛 (for all generators) fix being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work Apr 21, 2026
@camilamacedo86 camilamacedo86 changed the title 🐛 (for all generators) fix being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work 🐛 (for all generators): fix being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work Apr 21, 2026
// +testing:typelvl="here on type"
// normal godoc
type Foo struct {
// +testing:pkglvl="not here in struct"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This implies to me that at some point there was a deliberate choice to not support what this bug fix is now supporting. What kind of impact might an end user expect from this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch. That assertion verifies a separate behavior (removed by mistake). I've added it back to show the two are unrelated.

@JoelSpeed

Copy link
Copy Markdown
Contributor

This feels like a relatively risky change, since it has the potential to cause huge diffs in the generation for folks who haven't noticed that their markers aren't being observed.

What about a warning when the markers are being ignored instead of suddenly observing them?

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: camilamacedo86
Once this PR has been reviewed and has the lgtm label, please assign alvaroaleman for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

…ration) being silently ignored when placed directly above var/const/func declarations without a blank line. Both with and without blank line styles now work
@camilamacedo86

Copy link
Copy Markdown
Member Author

Hi @JoelSpeed,

I'm not sure I follow the concern. If someone explicitly adds a marker, I'd expect it to take effect. Silently ignoring it feels more surprising.

POV, the current behavior is the bug. This PR fixes that by making the marker behave as documented, rather than introducing a new behavior. If the concern is unexpected diffs, those diffs would only happen because users had already added the marker but weren't getting the expected result. So, why someone would add the marker if does not want the behaviour of the mark at all?

Also, this is limited to package-level markers (such as RBAC and webhook markers). Type and field markers already work without requiring a blank line.

For example, on main today, both of these work without a blank line:

// +kubebuilder:default={}
DefaultedEmptyMap map[string]string `json:"defaultedEmptyMap"`

// +kubebuilder:validation:Required
ExplicitlyRequiredKubebuilder string `json:"...,omitempty"`

The inconsistency is that package-level markers placed the same way are silently ignored. To me, that's confusing. This PR just makes package-level markers behave consistently with the rest of the marker system.

This also matches #436, where this behavior was reported as unexpected rather than intentional.

@camilamacedo86
camilamacedo86 requested a review from JoelSpeed June 28, 2026 17:48
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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Marker comment ignored if immediately followed by anything other than newline

3 participants