argoproj / argocd-example-apps

Example Apps to Demonstrate Argo CD
1.54k stars 7k forks source link

post render plugin doesn't seem to work #103

Open perezjasonr opened 3 years ago

perezjasonr commented 3 years ago

I am trying to follow the post-render example using kustomize. I am pointing directly to this online repo:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: kustomized-helm-ex
  namespace: argocd
spec:
  destination:
    namespace: default
    server: https://kubernetes.default.svc
  project: default
  source:
    repoURL: https://github.com/argoproj/argocd-example-apps
    targetRevision: master
    path: plugins/kustomized-helm
    plugin:
      name: kustomized-helm
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
    - CreateNamespace=true

I get:

status:
  conditions:
  - lastTransitionTime: "2021-08-31T15:30:07Z"
    message: 'rpc error: code = Unknown desc = Manifest generation error (cached):
      `sh -c helm template --release-name $ARGOCD_APP_NAME --namespace $ARGOCD_APP_NAMESPACE
      --include-crds . > all.yaml && kustomize build` failed exit status 1: Error:
      no matches for OriginalId apps_v1_Deployment|~X|release-name-helm-guestbook;
      no matches for CurrentId apps_v1_Deployment|~X|release-name-helm-guestbook;
      failed to find unique target for patch apps_v1_Deployment|release-name-helm-guestbook'

I did some research, and found that someone else who got this says it means the patch is targeting something that doesn't exist (in this case, release-name-helmguestbook deployment). But why would that be? we don't need to separately deploy the helm chart right? we cannot do both helm and plugin in the same app object.

unless the example readme is leaving out a step i would think you can use it "as is".

I think the plugin installed successfully, since it is indeed trying to run the provided generate command (helm template --args)

perezjasonr commented 3 years ago

ok so i got this to work by taking the original chart and including it, then putting kustomize and its patch yaml alongside it. this example looks like it references the helm-guestbook chart as a dependency, but I don't know exactly how thats supposed to work.

basically i had to take the helm-guestbook chart (not this plugin chart), and add kustomize/patch files to it.

is this example supposed to work by only referencing it? or are there prereq steps being assumed in it like I've done?

sathieu commented 2 years ago

I also add a few problems with this example:

I've done a few hacks to make this work, and behave a bit like flux:

In argocd-cm:

data:
    configManagementPlugins: |
      - name: kustomized-helm
        init:
          command: ["/bin/sh", "-c"]
          args:
          - KUBITUS_TMP="$(mktemp -d)" &&
            export XDG_CACHE_HOME="$KUBITUS_TMP/cache" &&
            export XDG_CONFIG_HOME="$KUBITUS_TMP/config" &&
            export XDG_DATA_HOME="$KUBITUS_TMP/data" &&
            export HELM_HOME="$KUBITUS_TMP" &&
            [ -z "$HELM_REPOSITORY_URLS" ] || helm repo add "$HELM_REPOSITORY_NAMES" "$HELM_REPOSITORY_URLS" &&
            helm dependency build &&
            rm -r "$KUBITUS_TMP"
        generate:
          command: [sh, -c]
          args:
          - helm template --release-name "$ARGOCD_APP_NAME" --namespace "$ARGOCD_APP_NAMESPACE" . > all.yaml &&
            kustomize build

In application:

apiVersion: argoproj.io/v1alpha1
kind: Application

metadata:
  name: "prometheus-stack"
  namespace: argocd
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  source:
    repoURL: "https://gitlab.example.org/gitops/infra.git"
    targetRevision: main
    path: "prometheus-stack"
    plugin:
      name: kustomized-helm
      env:
      - name: HELM_REPOSITORY_NAMES
        value: "kube-prometheus-stack"
      - name: HELM_REPOSITORY_URLS
        value: "https://prometheus-community.github.io/helm-charts"

  destination:
    name: ''
    namespace: "prometheus-stack"
    server: 'https://kubernetes.default.svc'

In the repo:

$ cat prometheus-stack/kustomization.yaml
resources:
- ./all.yaml

patchesStrategicMerge:
- |-
  apiVersion: apiextensions.k8s.io/v1
  kind: CustomResourceDefinition
  metadata:
    annotations:
      argocd.argoproj.io/sync-options: Replace=true
    name: prometheuses.monitoring.coreos.com

Relevant bug and commits in the kubitus-installer repo: