From 99d1c83a64904f4af373e4618172d05f0d8c7151 Mon Sep 17 00:00:00 2001 From: Noah <40781376+noahpb@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:55:27 -0400 Subject: [PATCH] fix: don't add duplicate policy names to `uds-core.pepr.dev/mutated` annotation (#916) ## Description Adds a check to the `annotateMutation` function that prevents duplicate values (policy names) from being added to the `uds-core.pepr.dev/mutated` key ## Related Issue Fixes https://github.com/defenseunicorns/uds-core/issues/717 ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [ ] Test, docs, adr added or updated as needed - [ ] [Contributor Guide](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md) followed --------- Co-authored-by: Micah Nagel --- src/pepr/policies/common.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pepr/policies/common.ts b/src/pepr/policies/common.ts index fb7a91331..7945ef2aa 100644 --- a/src/pepr/policies/common.ts +++ b/src/pepr/policies/common.ts @@ -112,6 +112,9 @@ export function annotateMutation( const annotations = request.Raw.metadata?.annotations ?? {}; const valStr = annotations[key]; const arr = JSON.parse(valStr || "[]"); - arr.push(transform(policy)); + const safePolicyName = transform(policy); + if (!arr.includes(safePolicyName)) { + arr.push(safePolicyName); + } request.SetAnnotation(key, JSON.stringify(arr)); }