Sometimes a policy should be active or inactive based on a time window determined as part of the policy. Whether the policy should come into play should be dependent on that time. This policy illustrates how to time-bound any policy by using preconditions with JMESPath time filters. In this case, the policy enforces that label `foo` be required on all ConfigMaps during the hours of 8am-5pm EST (expressed in UTC). Additional, similar preconditions may be added to perform other time checks, for example a range of days.
apiVersion: kyverno.io/v2beta1kind: ClusterPolicymetadata:name: time-bound-policyannotations:policies.kyverno.io/title: Time-Bound Policypolicies.kyverno.io/category: Otherpolicies.kyverno.io/minversion: 1.9.0kyverno.io/kyverno-version: 1.9.0kyverno.io/kubernetes-version: "1.24"policies.kyverno.io/subject: ConfigMappolicies.kyverno.io/description: Sometimes a policy should be active or inactive based on a time window determined as part of the policy. Whether the policy should come into play should be dependent on that time. This policy illustrates how to time-bound any policy by using preconditions with JMESPath time filters. In this case, the policy enforces that label `foo` be required on all ConfigMaps during the hours of 8am-5pm EST (expressed in UTC). Additional, similar preconditions may be added to perform other time checks, for example a range of days.spec:validationFailureAction: Auditbackground: falserules:- name: require-foo-on-configmapsmatch:any:- resources:kinds:- ConfigMappreconditions:all:- key: "{{ time_now_utc().time_to_cron(@).split(@,' ') | [1].to_number(@) }}"operator: AnyInvalue: 13-22validate:message: The foo label must be set.pattern:metadata:labels:foo: "?*"
This policy performs some best practices validation on Application fields. Path or chart must be specified but never both. And destination.name or destination.server must be specified but never both.
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.