Whats wrong with k8suniqueannotations logic inspired by k8suniquelabels #444
Replies: 1 comment 1 reply
-
Seems like I opened discussion in inaccurate category. closed and opened in Gatekeeper. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, Newbie in rego here.
Sample provided to create a namespace with unique labels works like a charm.
https://github.com/open-policy-agent/gatekeeper/blob/b7230e0bdc3479b867acd2fd0d7192b1182c59d4/demo/basic/templates/k8suniquelabel_template.yaml#L47
Provided example allows unique label to be configured across all namespaces. I tried to make similar change with few tweaks. Basically to allow unique annotation to be configured across all services.
Here is how my violation logic looks like in ConstraintTemplate:
And a change has been made in spec.crd.spec.validation.openAPIV3Schema.properties.annotation(instead of label) and corresponding change has been made in object that this template creates(snippet below) and config is created with audit cache enabled.
spec:
match:
kinds:
- apiGroups: [""]
kinds: ["Service"]
parameters:
annotation: external-dns.alpha.kubernetes.io/hostname
However, when I create a service 1 with annotation external-dns.alpha.kubernetes.io/hostname: mydomain.com and another service 2 with same annotation(key value pair). OPA doesn't deny it whereas the same logic works for labels for Namespace object. Any pointers that I could look into? Am more curious to know if the syntax used violation logic is right.
Beta Was this translation helpful? Give feedback.
All reactions