apiVersion: v1
kind: Namespace
metadata:
  name: mutate-jmespath
---
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: mutate-policy
spec:
  rules:
  - name: gen-role
    match:
      any:
      - resources:
          kinds:
            - ConfigMap
    context:
    - name: labelValue
      apiCall:
        urlPath: "/api/v1/namespaces/{{ request.object.metadata.namespace }}/configmaps"
        jmesPath: "items[*]"
    mutate:
      patchStrategicMerge:
        metadata:
          labels:
            +(kyverno.key/copy-me): "{{ labelValue[?metadata.name == 'source'].metadata.labels.\"kyverno.key/copy-me\" | [0] }}"
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: source
  namespace: mutate-jmespath
  labels:
    kyverno.key/copy-me: sample-value
data:
  data.yaml: |
    some: data
