Kubecost can use labels assigned to Pods in order to track and display cost allocation in a granular way. These labels, which can be customized, can be used to organize and group workloads in different ways. This policy requires that the labels `owner`, `team`, `department`, `app`, and `env` are all defined on Pods. With Kyverno autogen enabled (absence of the annotation `pod-policies.kyverno.io/autogen-controllers=none`), these labels will also be required for all Pod controllers.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: require-kubecost-labelsannotations:policies.kyverno.io/title: Require Kubecost Labels in CEL expressionspolicies.kyverno.io/category: Kubecost in CELpolicies.kyverno.io/severity: mediumpolicies.kyverno.io/subject: Pod, Labelkyverno.io/kyverno-version: 1.11.0kyverno.io/kubernetes-version: 1.26-1.27policies.kyverno.io/description: Kubecost can use labels assigned to Pods in order to track and display cost allocation in a granular way. These labels, which can be customized, can be used to organize and group workloads in different ways. This policy requires that the labels `owner`, `team`, `department`, `app`, and `env` are all defined on Pods. With Kyverno autogen enabled (absence of the annotation `pod-policies.kyverno.io/autogen-controllers=none`), these labels will also be required for all Pod controllers.spec:validationFailureAction: Auditbackground: truerules:- name: require-labelsmatch:any:- resources:kinds:- Podoperations:- CREATE- UPDATEvalidate:cel:expressions:- expression: object.metadata.?labels.?owner.orValue('') != '' && object.metadata.?labels.?team.orValue('') != '' && object.metadata.?labels.?department.orValue('') != '' && object.metadata.?labels.?app.orValue('') != '' && object.metadata.?labels.?env.orValue('') != ''message: The Kubecost labels `owner`, `team`, `department`, `app`, and `env` are all required for Pods.
This policy prevents the use of the default project in an Application.
This policy prevents updates to the project field after an Application is created.
This policy ensures that the name of the ApplicationSet is the same value provided in the project.