-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This ensures that students are running the correct jupyter image and resource sizes
- Loading branch information
1 parent
a98da6f
commit 0afb333
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
policy/overlays/nerc-ocp-prod/validate-ope-pods-constraint.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: constraints.gatekeeper.sh/v1beta1 | ||
kind: K8sRequiredOPEPod | ||
metadata: | ||
name: validate-ope-pods | ||
spec: | ||
match: | ||
kinds: | ||
- apiGroups: [""] | ||
kinds: ["Pod"] | ||
namespaces: ["rhods-notebooks", "ope-rhods-testing-1fef2f"] | ||
parameters: | ||
image: "image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/ucsls-nerc-rhoai:latest" |
52 changes: 52 additions & 0 deletions
52
policy/overlays/nerc-ocp-prod/validate-ope-pods-constrainttemplate.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
apiVersion: templates.gatekeeper.sh/v1beta1 | ||
kind: ConstraintTemplate | ||
metadata: | ||
name: k8srequiredopepod | ||
spec: | ||
crd: | ||
spec: | ||
names: | ||
kind: K8sRequiredOPEPod | ||
validation: | ||
openAPIV3Schema: | ||
properties: | ||
image: | ||
type: string | ||
targets: | ||
- target: admission.k8s.gatekeeper.sh | ||
rego: | | ||
package K8sRequiredOPEPod | ||
# Verify running class image | ||
violation[{"msg": msg}] { | ||
container := input.review.object.spec.containers[_] | ||
env_var := container.env[_] | ||
env_var.name == "JUPYTER_IMAGE" | ||
provided := env_var.value | ||
required := input.parameters.image | ||
provided != required | ||
msg := sprintf("Jupyter image %v is not allowed. Must use %v.", [provided, required]) | ||
} | ||
# Verify XSmall resource size | ||
violation[{"msg": msg}] { | ||
requiredCpuLimit := "1" | ||
requiredMemoryLimit := "4Gi" | ||
requiredCpuRequest := "100m" | ||
requiredMemoryRequest := "1Gi" | ||
container := input.review.object.spec.containers[0] | ||
cpuLimit := container.resources.limits.cpu | ||
memLimit := container.resources.limits.memory | ||
cpuRequest := container.resources.requests.cpu | ||
memRequest := container.resources.requests.memory | ||
requiredCpuLimit != cpuLimit | ||
requiredMemoryLimit != memLimit | ||
requiredCpuRequest != cpuRequest | ||
requiredMemoryRequest != memRequest | ||
msg := "Selected wrong container size. You must use XSmall container size" | ||
} |