-
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?
Changes from all commits
b7fe919
ee3b54f
6a30f21
7b57f2e
cd1f9c3
9523745
2fd8ede
8f5fcbc
c9db9e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,5 +141,24 @@ export async function validator(req: PeprValidateRequest<UDSPackage>) { | |
} | ||
} | ||
|
||
const monitors = pkg.spec?.monitor ?? []; | ||
|
||
// 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) { | ||
const monitorName = sanitizeResourceName( | ||
monitor.description || `${Object.values(monitor.selector)}-${monitor.portName}`, | ||
); | ||
Comment on lines
+150
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Realized in retrospect we could just import |
||
|
||
if (monitorNames.has(monitorName)) { | ||
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`, | ||
); | ||
Comment on lines
+155
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
monitorNames.add(monitorName); | ||
} | ||
|
||
return req.Approve(); | ||
} |
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.