Skip to content

✨feat: add non-fatal warning system for code generation diagnostics#1416

Open
mattsu2020 wants to merge 1 commit into
kubernetes-sigs:mainfrom
mattsu2020:fix_434
Open

✨feat: add non-fatal warning system for code generation diagnostics#1416
mattsu2020 wants to merge 1 commit into
kubernetes-sigs:mainfrom
mattsu2020:fix_434

Conversation

@mattsu2020

Copy link
Copy Markdown

Summary

This PR implements the warning system requested in #434 by adding a non-fatal warning infrastructure that mirrors the existing error reporting system.

  • Add Package.Warnings field and AddWarning() method to pkg/loader, following the same error type dispatch pattern as AddError()
  • Add PrintWarnings() and VisitPackages() helper functions to pkg/loader
  • Add Runtime.PrintWarnings() method to pkg/genall and call it after successful generation in controller-gen
  • Emit a warning when pointers are used as map values in CRD schemas (map[string]*string), which is supported but not recommended per Kubernetes API conventions
  • Add tests verifying that pointer map values produce a warning and non-pointer map values do not

Test plan

  • go build ./... passes
  • go test ./pkg/loader/... — 11/11 passed
  • go test ./pkg/crd/... — all passed (including new Test_Schema_PointerMapValue_Warning and Test_Schema_NonPointerMapValue_NoWarning)
  • Manual test: run controller-gen against a type with map[string]*string and verify warning output on stderr

Closes: #434

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 22, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Welcome @mattsu2020!

It looks like this is your first PR to kubernetes-sigs/controller-tools 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 22, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Hi @mattsu2020. 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.

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 22, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mattsu2020
Once this PR has been reviewed and has the lgtm label, please assign joelspeed 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 22, 2026
@sbueringer

Copy link
Copy Markdown
Member

I wonder if producing findings like this should be rather implemented in kube-api-linter

@JoelSpeed WDYT?

@mattsu2020

mattsu2020 commented May 22, 2026

Copy link
Copy Markdown
Author

Thanks

I looked into kube-api-linter and I agree this check fits better there than in controller-tools. There is already a nomaps linter that inspects map types and enforces Kubernetes API design guidance around maps, so I think the closest implementation path would be to extend that linter with an option to report map types whose value type is a pointer, e.g. map[string]*string.

I can move the actual API-convention check to kube-api-linter, likely as a nomaps configuration such as disallowPointerValues, and keep this controller-tools PR closed unless maintainers still want a generic non-fatal warning mechanism here.

@mattsu2020 mattsu2020 changed the title feat: add non-fatal warning system for code generation diagnostics 🐛feat: add non-fatal warning system for code generation diagnostics May 23, 2026
@mattsu2020 mattsu2020 changed the title 🐛feat: add non-fatal warning system for code generation diagnostics ✨feat: add non-fatal warning system for code generation diagnostics May 23, 2026
Add a warning infrastructure that mirrors the existing error reporting
system but is non-fatal. The first use case is warning about pointers
as map values, which is supported but not recommended per Kubernetes
API conventions.

- Add Package.Warnings field and AddWarning method to pkg/loader
- Add PrintWarnings and VisitPackages helper functions
- Add Runtime.PrintWarnings method to pkg/genall
- Call PrintWarnings after successful generation in controller-gen
- Emit warning when pointers are used as map values in CRD schemas
- Add tests for pointer map value warning and non-warning cases
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 23, 2026
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. needs-ok-to-test Indicates a PR that requires an org member to verify it 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.

Warn about things that we strongly recommend avoiding

3 participants