Skip to content

Commit

Permalink
fix: pepr mutation annotation overwrite (#385)
Browse files Browse the repository at this point in the history
## Description
Fixes the overwriting of previous pepr mutation annotations by merging
them.

## Related Issue

Fixes #
<!-- or -->
Relates to #

## 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

- [x] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md)(https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
followed

Co-authored-by: Micah Nagel <micah.nagel@defenseunicorns.com>
  • Loading branch information
TristanHoladay and mjnagel authored May 3, 2024
1 parent d8ec278 commit 6e56b2a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pepr/policies/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,10 @@ export function annotateMutation<T extends KubernetesObject>(
request: PeprMutateRequest<T>,
policy: Policy,
) {
request.SetAnnotation(`uds-core.pepr.dev/mutated`, transform(policy));
const key = "uds-core.pepr.dev/mutated";
const annotations = request.Raw.metadata?.annotations ?? {};
const valStr = annotations[key];
const arr = JSON.parse(valStr || "[]");
arr.push(transform(policy));
request.SetAnnotation(key, JSON.stringify(arr));
}

0 comments on commit 6e56b2a

Please sign in to comment.