apiVersion: v1
kind: Namespace
metadata:
  labels:
    downstream: "cpol-clone-create-on-trigger-deletion-manifest-ns"
  name: cpol-clone-create-on-trigger-deletion-trigger-ns
---
apiVersion: v1
kind: Namespace
metadata:
  name: cpol-clone-create-on-trigger-deletion-manifest-ns
---
apiVersion: v1
data:
  foo: YmFy
kind: Secret
metadata:
  name: cpol-clone-create-on-trigger-deletion-secret
  namespace: cpol-clone-create-on-trigger-deletion-manifest-ns
type: Opaque
---
apiVersion: kyverno.io/v2beta1
kind: ClusterPolicy
metadata:
  name: cpol-clone-create-on-trigger-deletion
spec:
  rules:
  - name: clone-secret
    match:
      any:
      - resources:
          kinds:
          - Namespace
    preconditions:
      any:
      - key: "{{ request.operation }}"
        operator: Equals
        value: DELETE
    generate:
      apiVersion: v1
      kind: Secret
      name: regcred
      namespace: "{{request.object.metadata.labels.downstream}}"
      synchronize: true
      clone:
        namespace: cpol-clone-create-on-trigger-deletion-manifest-ns
        name: regcred