apiVersion : kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: disallow-latest-tag
  annotations:
    policies.kyverno.io/category: Workload Isolation
    policies.kyverno.io/description: The ':latest' tag is mutable and can lead to 
      unexpected errors if the image changes. A best practice is to use an immutable 
      tag that maps to a specific version of an application pod.
spec:
  rules:
  - name: require-image-tag
    match:
      resources:
        kinds:
        - Pod
    validate:
      message: "An image tag is required"  
      pattern:
        spec:
          containers:
          - image: "*:*"
  - name: validate-image-tag
    match:
      resources:
        kinds:
        - Pod
    validate:
      message: "Using a mutable image tag e.g. 'latest' is not allowed"
      pattern:
        spec:
          containers:
          - image: "!*:latest"


# apiVersion: kyverno.io/v1
# kind: ClusterPolicy
# metadata:
#   annotations:
#     pod-policies.kyverno.io/autogen-controllers: DaemonSet,Deployment,Job,StatefulSet
#     policies.kyverno.io/category: Workload Isolation
#     policies.kyverno.io/description: The ':latest' tag is mutable and can lead to
#       unexpected errors if the image changes. A best practice is to use an immutable
#       tag that maps to a specific version of an application pod.
#   creationTimestamp: "2020-07-08T05:38:37Z"
#   generation: 1
#   name: disallow-latest-tag
#   resourceVersion: "553391"
#   selfLink: /apis/kyverno.io/v1/clusterpolicies/disallow-latest-tag
#   uid: 29f583d5-63f8-4494-98f8-0c06d55cdfe9
# spec:
#   background: true
#   rules:
#   - match:
#       resources:
#         kinds:
#         - Pod
#     name: require-image-tag
#     validate:
#       message: An image tag is required
#       pattern:
#         spec:
#           containers:
#           - image: '*:*'
#   - match:
#       resources:
#         kinds:
#         - Pod
#     name: validate-image-tag
#     validate:
#       message: Using a mutable image tag e.g. 'latest' is not allowed
#       pattern:
#         spec:
#           containers:
#           - image: '!*:latest'
#   - match:
#       resources:
#         kinds:
#         - DaemonSet
#         - Deployment
#         - Job
#         - StatefulSet
#     name: autogen-require-image-tag
#     validate:
#       message: An image tag is required
#       pattern:
#         spec:
#           template:
#             spec:
#               containers:
#               - image: '*:*'
#   - match:
#       resources:
#         kinds:
#         - DaemonSet
#         - Deployment
#         - Job
#         - StatefulSet
#     name: autogen-validate-image-tag
#     validate:
#       message: Using a mutable image tag e.g. 'latest' is not allowed
#       pattern:
#         spec:
#           template:
#             spec:
#               containers:
#               - image: '!*:latest'
#   validationFailureAction: audit