Skip to content

Commit

Permalink
fix: update monitor mutation to not overwrite explicitly defined scra…
Browse files Browse the repository at this point in the history
…pe class (#582)

## Description

- Updates the behavior of the monitor mutation to not overwrite and
explicitly defined scrapeClass

## 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
- [x] [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
zachariahmiller and mjnagel authored Jul 19, 2024
1 parent db081fa commit 7e550d3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pepr/prometheus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ServiceMonitorEndpoint,
ServiceMonitorScheme,
} from "../operator/crd";

// configure subproject logger
const log = setupLogger(Component.PROMETHEUS);

Expand All @@ -25,7 +24,7 @@ const { When } = prometheus;
When(PrometheusServiceMonitor)
.IsCreatedOrUpdated()
.Mutate(async sm => {
if (sm.Raw.spec === undefined) {
if (sm.Raw.spec === undefined || sm.Raw.spec.scrapeClass != undefined) {
return;
}

Expand All @@ -39,6 +38,7 @@ When(PrometheusServiceMonitor)
`Mutating scrapeClass to exempt ServiceMonitor ${sm.Raw.metadata?.name} from default scrapeClass mTLS config`,
);
sm.Raw.spec.scrapeClass = "exempt";

return;
} else {
log.info(`Patching service monitor ${sm.Raw.metadata?.name} for mTLS metrics`);
Expand All @@ -64,7 +64,7 @@ When(PrometheusServiceMonitor)
When(PrometheusPodMonitor)
.IsCreatedOrUpdated()
.Mutate(async pm => {
if (pm.Raw.spec === undefined) {
if (pm.Raw.spec === undefined || pm.Raw.spec.scrapeClass != undefined) {
return;
}

Expand All @@ -74,6 +74,7 @@ When(PrometheusPodMonitor)
`Mutating scrapeClass to exempt PodMonitor ${pm.Raw.metadata?.name} from default scrapeClass mTLS config`,
);
pm.Raw.spec.scrapeClass = "exempt";

return;
} else {
log.info(`Patching pod monitor ${pm.Raw.metadata?.name} for mTLS metrics`);
Expand Down Expand Up @@ -102,5 +103,6 @@ async function isIstioInjected(monitor: PrometheusServiceMonitor | PrometheusPod
return true;
}
}

return false;
}

0 comments on commit 7e550d3

Please sign in to comment.