Skip to content

Commit

Permalink
fix: don't add duplicate policy names to uds-core.pepr.dev/mutated
Browse files Browse the repository at this point in the history
…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 #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 <micah.nagel@defenseunicorns.com>
  • Loading branch information
noahpb and mjnagel authored Oct 16, 2024
1 parent bf23a89 commit 99d1c83
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/pepr/policies/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export function annotateMutation<T extends KubernetesObject>(
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));
}

0 comments on commit 99d1c83

Please sign in to comment.