Conversation
Gatekeeper testingThis document describes how to test set up and test Gatekeeper manually. Gatekeeper setupThe Gatekeeper operator can be installed by running the following command in the root of the cnf-features-deploy repo: FEATURES=gatekeeper make feature-deployOnce the operator is running, set up a Gatekeeper instance by running the following command: cat << EOF | oc create -f -
apiVersion: operator.gatekeeper.sh/v1alpha1
kind: Gatekeeper
metadata:
name: gatekeeper
spec:
audit:
replicas: 1
mutatingWebhook: "Enabled"
webhook:
failurePolicy: "Ignore"
EOFCheck if the gatekeeper deployments are running by executing the following command: oc get deployment -n gatekeeper-systemThe output should show the following deployments to be ready:
for example: NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/gatekeeper-audit 1/1 1 1 12s
deployment.apps/gatekeeper-controller-manager 1/1 1 1 12sTesting Gatekeeper constraintsSample constraint templates and constraints can be found in To apply these please run: oc create -f feature-configs/demo/gatekeeper/00_ConstraintTemplates.yaml
oc create -f feature-configs/demo/gatekeeper/10_Constraints.yaml "NOTE:" please wait a few seconds between the commands to allow gatekeeper to process them. With the constraints in place, create some pods to validate that the constraints are applied properly. Create such a namespace by executing: oc create -f feature-configs/demo/gatekeeper/20_DemoNamespace.yamlCreate a basic pod passing validationCreate the following pod: cat << EOF | oc create -f -
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
containers:
- name: main
image: centos
command: ["/bin/bash", "-c", "sleep INF"]
EOF The pod should be created successfully. Create a pod failing validationCreate the following pods: Pod with a specific tolerationcat << EOF | oc create -f -
apiVersion: v1
kind: Pod
metadata:
name: pod2
namespace: gatekeeper-demo
spec:
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
operator: Exists
containers:
- name: main
image: centos
command: ["/bin/bash", "-c", "sleep INF"]
EOFGatekeeper will reject this pod with a message similar to the one below: This pod was rejected by the deny-master-no-schedule-toleration constraint of type k8srestrictspecifictoleration.constraints.gatekeeper.sh Pod with a global taintcat << EOF | oc create -f -
apiVersion: v1
kind: Pod
metadata:
name: pod4
namespace: gatekeeper-demo
spec:
tolerations:
- operator: "Exists"
containers:
- name: podexample
image: centos
command: ["/bin/bash", "-c", "sleep INF"]
EOFGatekeeper will reject this pod with a message similar to the one below: This pod was rejected by the deny-global-tolerations constraint of type k8srestrictglobaltoleration.constraints.gatekeeper.sh |
Why:
Closes:
What's being changed (if available, include any code snippets, screenshots, or gifs):
Check off the following:
I have reviewed my changes in staging, available via the View deployment link in this PR's timeline (this link will be available after opening the PR).
datadirectory.For content changes, I have completed the self-review checklist.