1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-01-20 18:52:16 +00:00
kyverno/samples/RequireCertainLabels.md
2020-11-11 20:17:48 -05:00

1.1 KiB

Require certain labels

In many cases, you may require that at least a certain number of labels are assigned to each Pod from a select list of approved labels. This sample policy demonstrates the anyPattern option in a policy by requiring any of the two possible labels defined within. A pod must either have the label app.kubernetes.io/name or app.kubernetes.io/component defined.

Policy YAML

require_certain_labels.yaml

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: require-certain-labels
spec:
  validationFailureAction: audit
  rules:
  - name: validate-certain-labels
    match:
      resources:
        kinds:
        - Pod
    validate:
      message: "The label `app.kubernetes.io/name` or `app.kubernetes.io/component` is required."
      anyPattern:
      - metadata:
          labels:
            app.kubernetes.io/name: "?*"
      - metadata:
          labels:
            app.kubernetes.io/component: "?*"