apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
  name: openshift-gitops-policygenerator
spec:
  remediationAction: inform
  disabled: false
  policy-templates:
    - objectDefinition:
        apiVersion: policy.open-cluster-management.io/v1
        kind: ConfigurationPolicy
        metadata:
          name: openshift-gitops-policygenerator
        spec:
          remediationAction: inform
          severity: medium
          object-templates:
            - complianceType: musthave
              objectDefinition:
                apiVersion: argoproj.io/v1alpha1
                kind: ArgoCD
                metadata:
                  name: openshift-gitops
                  namespace: openshift-gitops
                spec:
                  repo:
                    env:
                    - name: KUSTOMIZE_PLUGIN_HOME
                      value: /etc/kustomize/plugin
                    - name: POLICY_GEN_ENABLE_HELM
                      value: "true"
                    initContainers:
                    - args:
                      - -c
                      - tar -xvzf /acm-cli/PolicyGenerator.tar.gz -C /tmp
                      command:
                      - /bin/bash
                      image: registry.redhat.io/rhacm2/acm-cli-rhel9:v{{ (lookup "operator.open-cluster-management.io/v1" "MultiClusterHub" "open-cluster-management" "multiclusterhub").status.currentVersion }}
                      name: policy-generator-install
                      volumeMounts:
                      - mountPath: /tmp
                        name: policy-generator
                    volumeMounts:
                    - mountPath: /etc/kustomize/plugin/policy.open-cluster-management.io/v1/policygenerator
                      name: policy-generator
                    volumes:
                    - emptyDir: {}
                      name: policy-generator
                  kustomizeBuildOptions: --enable-alpha-plugins
            - complianceType: musthave
              objectDefinition:
                kind: ClusterRole
                apiVersion: rbac.authorization.k8s.io/v1
                metadata:
                  name: openshift-gitops-policy-admin
                rules:
                  - verbs:
                      - get
                      - list
                      - watch
                      - create
                      - update
                      - patch
                      - delete
                    apiGroups:
                      - policy.open-cluster-management.io
                    resources:
                      - policies
                      - policysets
                      - placementbindings
                  - verbs:
                      - get
                      - list
                      - watch
                      - create
                      - update
                      - patch
                      - delete
                    apiGroups:
                      - apps.open-cluster-management.io
                    resources:
                      - placementrules
                  - verbs:
                      - get
                      - list
                      - watch
                      - create
                      - update
                      - patch
                      - delete
                    apiGroups:
                      - cluster.open-cluster-management.io
                    resources:
                      - placements
                      - placements/status
                      - placementdecisions
                      - placementdecisions/status
            - complianceType: musthave
              objectDefinition:
                kind: ClusterRoleBinding
                apiVersion: rbac.authorization.k8s.io/v1
                metadata:
                  name: openshift-gitops-policy-admin
                subjects:
                  - kind: ServiceAccount
                    name: openshift-gitops-argocd-application-controller
                    namespace: openshift-gitops
                roleRef:
                  apiGroup: rbac.authorization.k8s.io
                  kind: ClusterRole
                  name: openshift-gitops-policy-admin
