The context-aware-test-policy is a specialized Kubewarden policy designed specifically for use in policy-evaluator integration tests. It validates complex relationships between Kubernetes objects, such as matching labels between a Deployment and its Namespace, and ensuring the existence of specific peer components (like databases or frontends) within the same namespace.
When a Deployment with the label app.kubernetes.io/component: "api" is created or updated, this policy enforces the following constraints:
- Service Account Restrictions: The ServiceAccount used by the object is prohibited from creating pods in the
kube-system namespace. - Label Requirements: The Deployment must have a
customer-id label. - Namespace Alignment: The value of the
customer-id label on the Deployment must match the customer-id label on the Namespace where it is being deployed. - Component Presence: The namespace must contain existing Deployments with the following labels:
app.kubernetes.io/component: databaseapp.kubernetes.io/component: frontend
- Service Dependency: The namespace must contain a Service named
api-auth-service with the label app.kubernetes.io/part-of: api.