Skip to content

Commit

Permalink
🚚 Move constraint templates to the Helm crds directory, for more reli…
Browse files Browse the repository at this point in the history
…able installs and uninstalls
  • Loading branch information
ndebuhr committed Jul 7, 2021
1 parent f839d72 commit e9e27f7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
50 changes: 50 additions & 0 deletions helm/crds/contraint-templates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: requiredlabels
spec:
crd:
spec:
names:
kind: RequiredLabels
validation:
openAPIV3Schema:
properties:
labels:
type: array
items: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package requiredlabels
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
provided := {label | input.review.object.metadata.labels[label]}
required := {label | label := input.parameters.labels[_]}
missing := required - provided
count(missing) > 0
msg := sprintf("you must provide labels: %v", [missing])
}
---
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: deploymentselector
spec:
crd:
spec:
names:
kind: DeploymentSelector
validation:
openAPIV3Schema:
properties:
selector:
type: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package deploymentselector
violation[{"msg": msg, "details": {"missing_selector": missing}}] {
not input.review.object.spec.selector.matchLabels[input.parameters.selector]
missing := input.parameters.selector
msg := sprintf("you must include the deployment label selector: %v", [input.parameters.selector])
}
50 changes: 0 additions & 50 deletions helm/templates/policy-app-labels.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: requiredlabels
spec:
crd:
spec:
names:
kind: RequiredLabels
validation:
openAPIV3Schema:
properties:
labels:
type: array
items: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package requiredlabels
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
provided := {label | input.review.object.metadata.labels[label]}
required := {label | label := input.parameters.labels[_]}
missing := required - provided
count(missing) > 0
msg := sprintf("you must provide labels: %v", [missing])
}
---
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: deploymentselector
spec:
crd:
spec:
names:
kind: DeploymentSelector
validation:
openAPIV3Schema:
properties:
selector:
type: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package deploymentselector
violation[{"msg": msg, "details": {"missing_selector": missing}}] {
not input.review.object.spec.selector.matchLabels[input.parameters.selector]
missing := input.parameters.selector
msg := sprintf("you must include the deployment label selector: %v", [input.parameters.selector])
}
---
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: RequiredLabels
Expand Down

0 comments on commit e9e27f7

Please sign in to comment.