Skip to content

Fix nondeterministic NonNamespaced annotations in register generator#10

Merged
skevetter merged 1 commit into
mainfrom
fix/nonnamespaced-template
Apr 18, 2026
Merged

Fix nondeterministic NonNamespaced annotations in register generator#10
skevetter merged 1 commit into
mainfrom
fix/nonnamespaced-template

Conversation

@skevetter

@skevetter skevetter commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Remove next.Resource != nil gate on NonNamespaced detection in parse.go. Types encountered first as subtypes (via map iteration with nondeterministic order) had Resource=nil, causing NonNamespaced to remain false even for nonNamespaced resources.
  • Fix template to only emit // +genclient:nonNamespaced when NonNamespaced is true, instead of emitting a duplicate // +genclient line when false.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of non-namespaced resources in API client code generation to correctly apply markers based on resource type configurations.

@coderabbitai

coderabbitai Bot commented Apr 18, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

These changes refactor how non-namespaced status is determined and communicated in API code generation. The parsing logic now unconditionally computes non-namespaced status for all types, while template generation restricts the :nonNamespaced suffix emission to cases where both client generation and non-namespaced status are enabled.

Changes

Cohort / File(s) Summary
Non-namespaced Status Generation
pkg/generate/parse.go, pkg/generate/unversioned_generator.go
Modified conditional logic for computing and emitting non-namespaced status. Parsing now unconditionally sets non-namespaced status based on type properties; template generation now requires both GenClient and NonNamespaced flags to emit the :nonNamespaced suffix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 hops with joy
Non-namespaced types now shine so bright,
Computed for all, no conditions in sight,
The templates emit with dual-flag delight,
Generation logic flows cleaner and right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix nondeterministic NonNamespaced annotations in register generator' directly and clearly describes the main change: fixing nondeterministic behavior in NonNamespaced annotation generation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nonnamespaced-template

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Two bugs caused nondeterministic NonNamespaced annotations in generated
register files:

1. parse.go gated NonNamespaced detection behind next.Resource != nil,
   but types can be encountered first as subtypes (Resource=nil) via
   map iteration. Since processed types are skipped on re-encounter,
   the Resource version never runs, leaving NonNamespaced=false.

2. The template unconditionally emitted "// +genclient" on one line,
   then conditionally emitted "// +genclient:nonNamespaced" or a
   duplicate "// +genclient" on the next. Now the second line only
   emits when NonNamespaced is true.
@skevetter
skevetter force-pushed the fix/nonnamespaced-template branch from ad09207 to 6ab2d5b Compare April 18, 2026 21:21
@skevetter
skevetter enabled auto-merge (squash) April 18, 2026 21:22
@skevetter
skevetter merged commit 04607d0 into main Apr 18, 2026
5 checks passed
@skevetter
skevetter deleted the fix/nonnamespaced-template branch April 18, 2026 21:25
@devsy-app devsy-app Bot mentioned this pull request Apr 18, 2026
@skevetter
skevetter restored the fix/nonnamespaced-template branch April 18, 2026 22:14
@skevetter
skevetter deleted the fix/nonnamespaced-template branch April 18, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant