Learn KOP - Part 3 - Test OPA Policy - Rafay Product Documentation

Part 3: Test

This is Part 3 of a multi-part, self-paced quick start exercise.


What Will You Do

In part 3, you will create and attempt to publish a workload on the cluster that will violate the OPA constraints that are currently enforced by OPA Gatekeeper on the cluster.


Step 1: Create Namespace

In this step, we will create a namespace for our workload.


Step 2: Create Workload

In this step, we will create a test workload in order to test the OPA constraints in the OPA policy running on the cluster.

apiVersion: v1
kind: Pod
metadata:
  name: opa-disallowed
  labels:
    owner: me.agilebank.demo
spec:
  containers:
    - name: opa
      image: openpolicyagent/opa:0.9.2
      args:
        - "run"
        - "--server"
        - "--addr=localhost:8080"
      resources:
        limits:
          cpu: "100m"
          memory: "2Gi"

The workload is now attempting to be published on the cluster. OPA Gatekeeper is acting as the admission controller, validating the workload specification against the applied OPA constraints. The workload should be denied by the admission controller as it violates the applied OPA constraints.

Important
Our workload has defined "resource limits" over the allowed limit and therefore should be blocked on the cluster.


Recap

In this part, you created a workload and attempted to publish it to the cluster. You saw that the workload could not be published as it violated a constraint.

You are now ready to use any of the turnkey OPA policies provided in this guide within your environment.