Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post render plugin doesn't seem to work #103

Open
perezjasonr opened this issue Aug 31, 2021 · 2 comments
Open

post render plugin doesn't seem to work #103

perezjasonr opened this issue Aug 31, 2021 · 2 comments

Comments

@perezjasonr
Copy link

perezjasonr commented Aug 31, 2021

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
Copy link
Author

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
Copy link

sathieu commented Dec 10, 2021

I also add a few problems with this example:

  • it doesn't use --include-crds
  • helm dependency build is done globaly (a temporary dir should be created instead)
  • helm repo add is missing

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants