# Ah yes, the lovely, undocumented, and not-at-all-irrationally-difficult-to-understand ArgoCD method of chart customisation - plugins...

# If you are struggling to install the "lovely" plugin (or any plugin for that matter) with the ArgoCD Helm chart, this Gist could help you.
# Include this values config file as part of a Helm/Helmfile values argument to include the "lovely" plugin in your ArgoCD deployment.
# "Lovely" includes several popular tools for helm chart management, including the brilliant Helmfile, which itself includes
# "Vals" for secrets management.

---
argo-cd:
  configs:
    # ConfigMap for Config Management Plugins
    # Ref: https://argo-cd.readthedocs.io/en/stable/operator-manual/config-management-plugins/
    cmp:
      # -- Create the argocd-cmp-cm configmap
      create: true

      # -- Annotations to be added to argocd-cmp-cm configmap
      annotations: {}

      # -- Plugin yaml files to be added to argocd-cmp-cm
      plugins:
        argocd-lovely-plugin:
          name: argocd-lovely-plugin
          init:
            command: [sh]
            args: [-c, 'echo "Initializing lovely plugin..."']
          generate:
            # I have no idea if this is correct, but the plugin seems to work regardless
            command: [sh, -c]
            args:
              - |
                helm secrets --evaluate-templates template --namespace $ARGOCD_APP_NAMESPACE $ARGOCD_APP_NAME .

          discover:
            fileName: "./values.yaml"
            # find:
            #   glob: "**/Chart.yaml"
            #   command: [sh, -c, find . -name env.yaml]
          parameters:
            static:
              - name: values-files
                title: VALUES FILES
                collectionType: array
          # dynamic:
          #   command: [sh, /var/run/argocd/helm-plugin/get-parameters.sh]

  repoServer:
    volumes:
      - name: argocd-cmp-cm
        configMap:
          name: argocd-cmp-cm
      - name: lovely-tmp
        emptyDir: {}
    volumeMounts:
      # Works
      - mountPath: /home/argocd/cmp-server/config/plugin.yaml
        subPath: argocd-lovely-plugin.yaml
        name: argocd-cmp-cm

    # -- Additional containers to be added to the repo server pod
    ## Ref: https://argo-cd.readthedocs.io/en/stable/user-guide/config-management-plugins/
    ## Note: Supports use of custom Helm templates
    extraContainers:
      - name: lovely-plugin
        # Choose your image here - this one has the Argo CD Vault plugin in it. See https://github.com/crumbhole/argocd-lovely-plugin/blob/main/doc/variations.md
        # image: ghcr.io/crumbhole/lovely-vault-plugin:1.0.1
        image: ghcr.io/crumbhole/lovely:1.0.1
        # Here we are configuring default environment for every app - in this case vault
        # envFrom:
        #   - secretRef:
        #       name: vault-env
        securityContext:
          runAsNonRoot: true
          runAsUser: 999
        volumeMounts:
            # Import the repo-server's plugin binary
          - mountPath: /var/run/argocd
            name: var-files
          - mountPath: /home/argocd/cmp-server/plugins
            name: plugins
            # Starting with v2.4, do NOT mount the same tmp volume as the repo-server container. The filesystem separation helps
            # mitigate path traversal attacks.
          - mountPath: /tmp
            name: lovely-tmp

    # -- Init containers to add to the repo server pods
    initContainers: []