Skip to content

Conversation

@JustinKuli
Copy link
Member

@JustinKuli JustinKuli commented Nov 12, 2025

Previously, if labels or annotations inside an objectTemplate used values that were not strings, the ConfigurationPolicy might try to remove all labels or annotations on that object. That behavior was potentially destructive, and it was easy for a policy author to accidentally trigger by getting some quotes wrong in their template, or by using yes as a value (which is interpreted by some parsers as a boolean true).

Now, the ConfigurationPolicy will emit a special error if the input object template has invalid labels or annotations.

Refs:

@JustinKuli
Copy link
Member Author

JustinKuli commented Nov 12, 2025

An updated "mismatch" test was a good demonstration of the old behavior. Here's what the test would require with the old behavior, when the policy has invalid labels and annotations:

# Diffs:
v1 Pod managed/nginx-pod-e2e-10:
--- managed/nginx-pod-e2e-10 : existing
+++ managed/nginx-pod-e2e-10 : updated
@@ -1,13 +1,8 @@
 apiVersion: v1
 kind: Pod
 metadata:
-  annotations:
-    test: e2e10
-  labels:
-    bar: fail
-    test: e2e10
   name: nginx-pod-e2e-10
   namespace: managed
 spec:
   containers:
   - image: nginx:1.7.9
# Compliance messages:
NonCompliant; violation - pods [nginx-pod-e2e-10] found but not as specified in namespace managed

And it's clear that if the policy was enforced, it would delete the labels and annotations.

Previously, if labels or annotations inside an objectTemplate used
values that were not strings, the ConfigurationPolicy might try to
remove all labels or annotations on that object. That behavior was
potentially destructive, and it was easy for a policy author to
accidentally trigger by getting some quotes wrong in their template, or
by using `yes` as a value (which is interpreted by some parsers as a
boolean `true`).

Now, the ConfigurationPolicy will emit a special error if the input
object template has invalid labels or annotations.

Refs:
 - https://issues.redhat.com/browse/ACM-26186

Signed-off-by: Justin Kulikauskas <[email protected]>
@JustinKuli JustinKuli force-pushed the 26186-convert-invalid-metadata branch from 217a12b to c806d02 Compare November 12, 2025 20:55
@JustinKuli JustinKuli changed the title Convert non-string labels and annotations Handle non-string labels and annotations Nov 12, 2025
Copy link
Member

@dhaiducek dhaiducek left a comment

Choose a reason for hiding this comment

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

This looks great to me! Thanks for working it out!


# Compliance messages:
NonCompliant; violation - pods [nginx-pod-e2e-10] found but not as specified in namespace managed
NonCompliant; violation - invalid annotation, error: contains non-string value in the map under key "case": 10 is of the type int64, expected string
Copy link
Member

Choose a reason for hiding this comment

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

This error is so clearly written it makes me want to cry 🥹

Copy link
Member Author

Choose a reason for hiding this comment

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

It is pretty nice :D

@openshift-ci
Copy link

openshift-ci bot commented Nov 12, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dhaiducek, JustinKuli

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JustinKuli,dhaiducek]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit c20f555 into open-cluster-management-io:main Nov 13, 2025
27 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants