{{- if and (.Values.kyverno.enabled) (.Values.prometheus.enabled) }}
apiVersion: kyverno.io/v1
kind: Policy
metadata:
  name: prometheus-stack-default-dashboard-folder
  namespace: prometheus
spec:
  admission: true
  background: true
  mutateExistingOnPolicyUpdate: true
  rules:
  - match:
      any:
      - resources:
          kinds:
          - ConfigMap
          selector:
            matchLabels:
              app.kubernetes.io/part-of: kube-prometheus-stack
    mutate:
      patchStrategicMerge:
        metadata:
          annotations:
            grafana_folder: Prometheus-stack
      targets:
      - apiVersion: v1
        kind: ConfigMap        
        name: "{{`{{ request.object.metadata.name }}`}}"
    name: generate-dashboard-folder-annotation
    skipBackgroundRequests: true
  validationFailureAction: Audit
{{- end }}
