-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: validate unique names for monitors #666
base: main
Are you sure you want to change the base?
Conversation
…ent missing parameters in existing calls to makeMockReq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't had a chance to fully review the code yet but to fix the one CI failure you'll want to rename your PR title to follow a conventional commit syntax, something like fix: validate unique names for monitors
…or array to test mocks
const monitorName = sanitizeResourceName( | ||
monitor.description || `${Object.values(monitor.selector)}-${monitor.portName}`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realized in retrospect we could just import generateMonitorName
and use that here to ensure we keep this logic in sync with our name generation rather than duplicating.
// Ensure serviceMonitors use a unique description or selector/portName used for generating the resource name | ||
const monitorNames = new Set<string>(); | ||
|
||
for (const monitor of monitors) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't think about this before but I think there's another edge case where podmonitors and servicemonitors should be allowed to have overlapping names, but this would deny them. We may need separate sets per type and check the kind
in this loop.
return req.Deny( | ||
`A serviceMonitor resource generated from the Package, ${pkg.metadata?.name} contains a duplicate name, please provide a unique description for each item in the monitor array`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: might be good to align this with the wording we use for the VirtualService check, and make sure we are capturing kind
accurately here (pod vs svc monitor).
Description
Added a new piece to the pepr operator's validator function. The new functionality loops through the Package CR's monitor array, adding each description field (or a dummy string in the event of no provided description) to a set, failing given a duplicate.
The sanitizeResourceName() function was used in the validator since its also used downstream to create the ServiceMonitor resource name based on the string from the monitor.description field.
...
Related Issue
Fixes #656
Type of change
Checklist before merging