travisghansen / argo-cd-helmfile

Integration between argo-cd and helmfile
MIT License
213 stars 55 forks source link

Not sure how to put the environment variable flag in helmfile #9

Closed cwusyscrest closed 3 years ago

cwusyscrest commented 3 years ago

Hi,

Thank you for developing such a great plugin for helmfile. I was wondering what I did wrong if I want to achieve something like helmfile --environment development apply.

Here is my application manifest:

spec:
  destination:
    namespace: default
    server: {{ .Values.spec.destination.server }}
  project: default
  source:
    path: {{ .Values.spec.source.path }}
    repoURL: {{ .Values.spec.source.repoURL }}
    targetRevision: {{ .Values.spec.source.targetRevision }}
    plugin:
      name: helmfile
      env:
      - name: HELMFILE_GLOBAL_OPTIONS
        value: '"--environment development"'
    helm:
      # Release name override (defaults to application name)
      releaseName: guestbook-{{ .Values.environment }}

      # Helm values files for overriding values in the helm chart
      # The path is relative to the spec.source.path directory defined above
      valueFiles:
        - values-{{ .Values.environment }}.yaml

Here is structure of the example project:

Screenshot 2021-03-26 at 14 51 17

So basically what I want to achieve here is that I want to specify --environment in order to tell helmfile which values.yaml to take when rendering the manifest. Thank you!

travisghansen commented 3 years ago

Glad it's helping out! What is the error you got? I'm guessing it's blowing up due to the quoting style you're using...remove either the single or double quotes but don't use both.

cwusyscrest commented 3 years ago

@travisghansen Thanks for your quick response. I tried to remove the single quotes and still the env variable wasn't there.

Screenshot 2021-03-26 at 17 01 43

But if I ran helmfile -e development template, the manifests were rendered correctly with the values specified in environments/development/values.yaml.

cwusyscrest commented 3 years ago

Ok so I tried to add the HELMFILE_GLOBAL_OPTIONS env variable from ArgoCD ui, and it worked. Screenshot 2021-03-26 at 17 14 26 Maybe it was due to the fact that my application.yaml wasn't put in the right place. Is there any way to set the environment variable just like --helm-set environment=something in argocd with helm?

travisghansen commented 3 years ago

That value in the image still looks incorrect no? Looks like you have an empty env var name with an empty value?

I'm not entirely sure I understand your question. Can you elaborate a bit more?

cwusyscrest commented 3 years ago

Sure so my question is rather simple.

I wanted to know if it is possible to set the env variable (e.g. HELMFILE_GLOBAL_OPTIONS) when I create an argocd app with argocd cli. For example, with helm we can do

argocd app create APPNAME --helm-set-string 'app=${ARGOCD_APP_NAME}'

Can we set the env variable like HELMFILE_GLOBAL_OPTIONS as helm does with argocd cli? At the moment, I think the only way is to write my own application manifest my-app.yaml for example, and then run kubectl apply -f my-app.yaml to deploy the argocd app. And I need to set HELMFILE_GLOBAL_OPTIONS in my-app.yaml.

travisghansen commented 3 years ago

Ah got ya! I’m not sure actually. I don’t use the cli but if not that’s certainly a case where a bug should be created. I’ll look at docs though and see what I can find.

travisghansen commented 3 years ago

Looking at the doc it appears so. The last example in the link shows creating an app using a custom plugin and then further down you’ll see doc for the plugin-env option.

cwusyscrest commented 3 years ago

Thanks @travisghansen I tried the plugin-env option, but it didn't work on my side. I will simply go for using kubectl apply on the application manifest. Thank you again for your help.

travisghansen commented 3 years ago

Figure out a solution?

cwusyscrest commented 3 years ago

At the time of writing no, but I will investigate further on the plugin-env option. If i have any solution, I will post it here again.