Skip to content

Conversation

@Jaisheesh-2006
Copy link
Contributor

Description

This PR implements strict validation for metadata.annotations values during the live apply pipeline.

Previously, the Go unmarshaler silently discarded non-string values (e.g., unquoted booleans like true or integers like 123) because they did not match the expected map[string]string schema. This resulted in annotations being dropped from the applied resource without warning.

This change adds a validation step that inspects the raw YAML tags of RNodes. It now returns a strict error if any annotation value is not a string, while correctly accepting quoted strings (e.g., "true").

Motivation

To prevent silent data loss and configuration drift.

Users frequently mistake YAML types (e.g., writing enabled: true instead of enabled: "true"). Currently, kpt ignores these fields silently. This fix ensures the user receives immediate feedback:

New Error Output:
Error: annotation "example.com/enabled" must be a string, got boolean

Which issue does this PR fix?

Fixes #3784

Previously, invalid annotation types (like unquoted booleans) were
silently dropped during apply. This adds a validation step to reject
non-string values with a clear error message.

Fixes kptdev#3784

Signed-off-by: Jaisheesh-2006 <jaicodes2006@gmail.com>
Copilot AI review requested due to automatic review settings February 2, 2026 17:31
@netlify
Copy link

netlify bot commented Feb 2, 2026

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit 86a8a35
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/6982cb5d9af57a000853dbed
😎 Deploy Preview https://deploy-preview-4371--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

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

This PR implements strict validation for metadata.annotations values during the live apply pipeline to prevent silent data loss. Previously, non-string annotation values (e.g., unquoted booleans or integers) were silently discarded by the Go unmarshaler, resulting in annotations being dropped without warning.

Changes:

  • Adds annotation value type validation in the live apply pipeline that inspects raw YAML tags
  • Introduces comprehensive unit tests for annotation validation logic
  • Adds integration tests to existing test suites to ensure validation is enforced in both path and stream readers

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkg/live/rgpath.go Implements validateAnnotationTypes and yamlTagToType functions, integrates validation into kyamlNodeToUnstructured
pkg/live/validate_annotation_test.go Comprehensive unit tests covering valid strings, invalid types (boolean, integer, float, null), edge cases, and error messages
pkg/live/rgstream_test.go Adds integration test case for bad annotation type rejection in stream reader
pkg/live/rgpath_test.go Adds integration test case for bad annotation type rejection in path reader
pkg/live/helpers_test.go Defines configMapWithBadAnnotation test fixture used by integration tests
e2e/testdata/live-apply/invalid-annotation-type/config.yaml E2E test configuration for invalid annotation type scenario

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

Signed-off-by: Jaisheesh-2006 <jaicodes2006@gmail.com>
@Jaisheesh-2006 Jaisheesh-2006 force-pushed the fix/3784-validate-annotations branch from 5d17292 to a0b112d Compare February 2, 2026 17:54
- Rename validateAnnotationTypes to validateMetadataStringMaps
- Add validateStringMap helper function for reusability
- Validate both annotations AND labels for non-string types
- Add proper GoDoc comments to all functions
- Create comprehensive test file validate_metadata_test.go
- Fix E2E test expected error message prefix

Fixes kptdev#3784

Signed-off-by: Jaisheesh-2006 <jaicodes2006@gmail.com>
Copilot AI review requested due to automatic review settings February 2, 2026 18:05
Add resourcegroup.yaml to migrate from Kptfile-based inventory
to ResourceGroup-based inventory, eliminating the warning message
about using Kptfile for inventory information.

Signed-off-by: Jaisheesh-2006 <jaicodes2006@gmail.com>
Copy link

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

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


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

Remove the inventory section from Kptfile since ResourceGroup is
now used for inventory. Having both causes an inventory conflict error.

Signed-off-by: Jaisheesh-2006 <jaicodes2006@gmail.com>
Copilot AI review requested due to automatic review settings February 2, 2026 18:19
Copy link

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

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


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

Copy link

@mozesl-nokia mozesl-nokia left a comment

Choose a reason for hiding this comment

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

There should probably be an E2E test added for the label validation as well.

Signed-off-by: Jaisheesh-2006 <jaicodes2006@gmail.com>
@dosubot dosubot bot added the lgtm label Feb 10, 2026
@liamfallon liamfallon merged commit f1d2a47 into kptdev:main Feb 10, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kpt live silently fails to apply annotations with errors

3 participants