Skip to content

Fix create-setters matching setter values in internal kpt annotations#1229

Merged
efiacor merged 1 commit intokptdev:mainfrom
Nordix:fix-create-setters-to-exclude-internal-annotations
Apr 13, 2026
Merged

Fix create-setters matching setter values in internal kpt annotations#1229
efiacor merged 1 commit intokptdev:mainfrom
Nordix:fix-create-setters-to-exclude-internal-annotations

Conversation

@aravindtga
Copy link
Copy Markdown
Contributor

Fixes kptdev/kpt#4462

Summary

The create-setters function was incorrectly creating setter comments on internal.config.kubernetes.io/* and config.kubernetes.io/* annotations. These are kpt runtime metadata injected during fn render (e.g. filesystem paths) and are not user-authored resource content. When a setter value like 4 appeared as a substring in a temp directory path, the function would produce spurious and non-deterministic results.

Changes

functions/go/create-setters/createsetters/create_setters.go:

  • Added a path check in visitScalar() to skip fields under internal.config.kubernetes.io and `config.kubernetes.io annotations

functions/go/create-setters/createsetters/create_setters_test.go:

  • Added test case skip internal kpt annotations verifying that:
    • internal.config.kubernetes.io/package-path containing the setter value is not matched
    • config.kubernetes.io/local-config` is not matched
    • Regular fields like spec.replicas still correctly receive setter comments

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 2, 2026

Deploy Preview for krm-function-catalog canceled.

Name Link
🔨 Latest commit fe096cc
🔍 Latest deploy log https://app.netlify.com/projects/krm-function-catalog/deploys/69dca9f8b159a100086eeb29

@aravindtga aravindtga force-pushed the fix-create-setters-to-exclude-internal-annotations branch from 99b0337 to bb6af3d Compare April 2, 2026 16:52
@aravindtga
Copy link
Copy Markdown
Contributor Author

This should be rebased once #1227 is merged.

@aravindtga aravindtga marked this pull request as ready for review April 2, 2026 16:56
Copilot AI review requested due to automatic review settings April 2, 2026 16:56
Copy link
Copy Markdown
Contributor

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

Fixes non-deterministic setter comment generation by preventing create-setters from matching and annotating kpt runtime metadata stored in internal.config.kubernetes.io/* and config.kubernetes.io/* annotations.

Changes:

  • Skip scalar nodes whose field path is under metadata.annotations.internal.config.kubernetes.io/* or metadata.annotations.config.kubernetes.io/*.
  • Add a regression test ensuring annotation values containing a setter substring are ignored while normal fields (e.g. spec.replicas) still get kpt-set comments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
functions/go/create-setters/createsetters/create_setters.go Adds a path-based guard in visitScalar to avoid generating setter comments for internal/config kpt annotations.
functions/go/create-setters/createsetters/create_setters_test.go Adds a test case validating internal/config kpt annotations are skipped while regular fields continue to be annotated.

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

Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
@aravindtga aravindtga force-pushed the fix-create-setters-to-exclude-internal-annotations branch from bb6af3d to fe096cc Compare April 13, 2026 08:31
@efiacor efiacor merged commit b3dc57d into kptdev:main Apr 13, 2026
11 checks passed
@efiacor efiacor deleted the fix-create-setters-to-exclude-internal-annotations branch April 13, 2026 12:52
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.

Create setters KRM function incorrectly matches setter values in internal.config.kubernetes.io annotations

5 participants