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

how to dynamically generate values? | advanced exec usage #1006

Closed
jurgenweber opened this issue Nov 29, 2019 · 6 comments
Closed

how to dynamically generate values? | advanced exec usage #1006

jurgenweber opened this issue Nov 29, 2019 · 6 comments

Comments

@jurgenweber
Copy link

jurgenweber commented Nov 29, 2019

Can a hook return something that can then be used in .Values?

so hook executes:

git ls-remote git@bitbucket.org:asdf/mysuperfunhappytimeapp.git | master | awk '{ print $1}' | head -c 8

.Values.hookname.return

the other way is a bash wrapperI suppose.

or execute bash inside the template...

@mumoshu
Copy link
Collaborator

mumoshu commented Nov 29, 2019

@jurgenweber Hey!

Just curious do you have a specific reason you want it to be in hooks?

If not, you can try this to dynamically generate values:

somekey: {{ exec "sh" (list "-c" "git ls-remote .... | grep maser | awk ...." )) }}

@jurgenweber
Copy link
Author

OMG that is amazing. Should add it to the tips and tricks thread. :)

@jurgenweber
Copy link
Author

jurgenweber commented Dec 5, 2019

using this; https://github.com/roboll/helmfile#importing-values-from-any-source

{{- $git_branch := env "GIT_BRANCH" | default "master" }}
 {{- $git_hash := exec "sh" (list "-c" "git ls-remote git@bitbucket.org:myrepo/myrepo.git `{{ $git_branch }}` | awk '{ print $1}' | head -c 8") }}

what env is in that exec?

that git_branch is ""

@jurgenweber
Copy link
Author

jurgenweber commented Feb 10, 2020

@mumoshu can you expand more on the pipeline example, please?

Or even with a pipeline:

mysetting: |
{{ yourinput | exec "./mycmd-consume-stdin" (list "arg1" "arg2") | indent 2 }}

does yourinput become an arg to the command? Can you make it an env var? Basically, what can you do with 'yourinput'?

I am trying to substitute a variable without success:

 {{- $exec_list = (list "-c" "git ls-remote git@bitbucket.org:asdf/asdf-api.git ${BRANCH} | awk '{print $1}' | head -c 8") }}
 {{- $git_hash := "export BRANCH=release" | exec "bash" $exec_list }}
  • edit; fix typos, add substitution issue.

@jurgenweber jurgenweber reopened this Feb 10, 2020
@jurgenweber jurgenweber changed the title can a hook return a value? advanced exec usage Feb 10, 2020
@jurgenweber jurgenweber changed the title advanced exec usage how to dynamically generate values | advanced exec usage Feb 10, 2020
@jurgenweber jurgenweber changed the title how to dynamically generate values | advanced exec usage how to dynamically generate values? | advanced exec usage Feb 10, 2020
@mumoshu
Copy link
Collaborator

mumoshu commented Feb 10, 2020

yourinput becomes the last argument to the template function after |. That's how go text/template works so everything explained in https://golang.org/pkg/text/template/ would help you find more advanced usages.

@jurgenweber
Copy link
Author

yeah, ok. I decided to just make a bash script in the end but ok, wondered if it was using golang exec.

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