Skip to content

Pass Array values through --set #1987

Closed

Description

@pluttrell

Please add the ability to pass Array values through --set.

For example, the stable/aws-cluster-autoscaler Chart must receive the following:

autoscalingGroups:
  - name: my-asg-name
    maxSize: 50
    minSize: 2

If this is already possible, please do tell.. And update the docs to show how.

Activity

  1. technosophos commented on Feb 16, 2017

    @technosophos
    Member

    Array values can be specified using curly braces: --set foo={a,b,c}. This will translate to the YAML:

    foo:
      - a
      - b
      - c

    Maps have to be passed like this: something.key=value,something.key2=value2, which will translate to the YAML:

    something:
      key: value
      key2: value2
    

    The full documentation for --set is buried in this document: https://github.com/kubernetes/helm/blob/master/docs/using_helm.md#the-format-and-limitations-of---set

  2. pluttrell commented on Feb 17, 2017

    @pluttrell
    Author

    @technosophos Many thanks for responding.

    After reading the referenced doc, I still don't see how to reference the following via --set:

    autoscalingGroups:
      - name: my-asg-name
        maxSize: 50
        minSize: 2
    

    Is there a way to do this?

  3. technosophos commented on Feb 17, 2017

    @technosophos
    Member

    I believe that the most straightforward way to do that would be to alter the structure of values.yaml into something like this:

    autoscalingGroups:
      "my-asg-name":
        maxSize: 50
        minSize: 2
      "my-other-asg":
        maxSize: 50
        minSize: 2
    

    That strategy will simply make it easier to reference them from --set, while also being pretty easy to work with in templates.

    As you probably noticed from the documentation, there is no way in the current --set syntax to access an array value by index. So working with arrays is sort of a pain.

  4. JeanMertz commented on Apr 22, 2017

    @JeanMertz

    So working with arrays is sort of a pain.

    I'm looking for ways to set an array using set, but it's unclear to me what the above statement means? Is it possible to set an array with set, or isn't it? If it's sort of a pain, then I don't mind, but I'd like to find out how to do it.

    I know I can convert the array to a map, but that's not really what I'm looking for, as the user experience (for an internal company-wide chart) degrades to work around a technical issue.

    I'm not saying this should be possible, but if it's not, we should probably mention this clearly in the documentation. (and if it already is, then I'm sorry, I must have missed it)

  5. bacongobbler commented on Apr 22, 2017

    @bacongobbler
    Member

    From the documentation:

    Lists can be expressed by enclosing values in { and }. For example, --set name={a, b, c} translates to:

    name:
      - a
      - b
      - c
    
  6. cabrinoob commented on Aug 23, 2017

    @cabrinoob

    @pluttrell : Maybe

    --set autoscalingGroups[0].name=my-asg-name --set autoscalingGroups[0].maxSize=50 --set autoscalingGroups[0].minSize=2

  7. yanhongwang commented on Jun 26, 2018

    @yanhongwang

    Hello all,

    Do you know how about this structure of 'affinity'.
    P.S: The indents unfortunately disappear when shown in Github web page.

    ###################################################
    affinity:
    podAntiAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
    - labelSelector:
    matchExpressions:
    - key: app
    operator: In
    values:
    - mongodb-replicaset
    topologyKey: kubernetes.io/hostname
    ##################################################

    Should I write in
    --set=affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.labelSelector.matchExpressions.key=app,affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.labelSelector.matchExpressions.operator=In,affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.labelSelector.matchExpressions.values=mongodb-replicaset,affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.topologyKey=kubernetes.io/hostname

    Or some other correct syntax?
    Thanks very much.

    Hong

  8. cabrinoob commented on Jun 27, 2018

    @cabrinoob

    I think that when you have to apply complexe modifications like these, you'd better have to put them in a file intead of using --set.

  9. yanhongwang commented on Jun 27, 2018

    @yanhongwang

    Hello @cabrinoob

    Thanks for your recommendation.

    That's true that I used --values=values.yaml to adapt appropriated value.
    So there is no syntax to express affinity syntax by --set, right?

    Thanks very much.

    Hong

  10. cabrinoob commented on Jun 27, 2018

    @cabrinoob

    You do not have to have the same structure in your values.yaml file than in your deployment.yaml resource.

    You can have a relatively "flat" structure in values.yaml that makes usage of --set more simple.

  11. yanhongwang commented on Jun 27, 2018

    @yanhongwang

    Hello @cabrinoob

    Thanks for your comments.

    But, I saw the most of charts application in https://github.com/kubernetes/charts/tree/master/stable

    For example:
    #############################################
    values.yaml
    affinity: {}

    deployment.yaml
    {{- with .Values.affinity }}
    affinity:
    {{ toYaml . | indent 8 }}
    {{- end }}
    ############################################

    Is that mean that deployment file needed to be patched when desired?
    Thanks.

    BR
    Hong

  12. cabrinoob commented on Jun 27, 2018

    @cabrinoob
  13. yanhongwang commented on Jun 28, 2018

    @yanhongwang

    @cabrinoob
    Thanks for suggestion.

  14. 1 remaining item

  15. jugatsu commented on Jan 6, 2020

    @jugatsu
    Contributor

    If someone googles how to pass imagePullSecrets via --set flag, here is the command:

    For example, helm template with imagePullSecrets like this one:

    spec:
        {{- with .Values.imagePullSecrets }}
          imagePullSecrets:
            {{- toYaml . | nindent 8 }}
        {{- end }}

    command:

    --set 'imagePullSecrets[0].name=regcred'
  16. pkaramol commented on Jan 21, 2020

    @pkaramol

    According to this suggestion bt @technosophos , I should be able to run the following:

    helm upgrade --force --tls --install --set master.installPlugins={'kubernetes:1.21.2', 'workflow-job:2.36'} --set master.tag=lts --set agent.tag=3.27-1 -f /org_files/tmp/myenv-jenkins/jenkins-values.yaml --namespace jenkins jenkins-myenv stable/jenkins
    

    However this fails:

    Error: This command needs 2 arguments: release name, chart path

    Have tried enclosing the element lists to single, double and no quotes.

    $ helm version --tls
    Client: &version.Version{SemVer:"v2.11.0", GitCommit:"2e55dbe1fdb5fdb96b75ff144a339489417b146b", GitTreeState:"clean"}
    Server: &version.Version{SemVer:"v2.11.0", GitCommit:"2e55dbe1fdb5fdb96b75ff144a339489417b146b", GitTreeState:"clean"}
    

    Any suggestions?

  17. HartS commented on Feb 22, 2020

    @HartS

    @pkaramol I hope you already figured this out, but since the master.installPlugin value you're passing isn't quoted, it treats your argument to --set as master.installPlugins={kubernetes:1.21.2, , and then attempts to parse workflow-job:2.36} as your next argument. You need to remove the space between list items as that space would be treated literally if the curly braces were properly quoted, but if you remove the space and are using a shell which would attempt to expand {1,2,3} (such as bash), you will also need to quote the outside of the curly braces (which also means you want to remove the single quotes from your array element values, unless the values should be strings which include literal quotes)

  18. davidwindell commented on Jun 24, 2020

    @davidwindell

    @intellix re Gitlab, I also stumbled across the need to pass an arbitrary number of environment variables to our helm chart whilst using set. I ended up with this hacky CSV to array solution but I'd be interested if you or anyone else had a better suggestion:

    --set app.extraEnv="ENVVAR1=foo\,ENVVAR2=bar\,ENVVAR3=bat"

    env:
    {{- range (split "," .Values.app.extraEnv) }}
      - name: {{ (split "=" .)._0 }}
        value: {{ (split "=" .)._1 | quote }}
    {{- end }}
  19. weironz commented on Aug 28, 2020

    @weironz

    values.yaml示例

    master:
        initContainerEnv:
          - name: http_proxy
            value: "http://192.168.64.1:3128"
    

    变量配置方式

    helm install jenkins-blueocean \
      --set master.initContainerEnv[0].name="JENKINS_UC" \
      --set master.initContainerEnv[0].value="https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json/" \
      --set master.initContainerEnv[1].name="JENKINS_UC_DOWNLOAD" \
      --set master.initContainerEnv[1].value="https://mirrors.tuna.tsinghua.edu.cn/jenkins/" \
      stable/jenkins
    
  20. gargabhay1999 commented on Aug 31, 2020

    @gargabhay1999

    values.yaml示例

    master:
        initContainerEnv:
          - name: http_proxy
            value: "http://192.168.64.1:3128"
    

    变量配置方式

    helm install jenkins-blueocean \
      --set master.initContainerEnv[0].name="JENKINS_UC" \
      --set master.initContainerEnv[0].value="https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json/" \
      --set master.initContainerEnv[1].name="JENKINS_UC_DOWNLOAD" \
      --set master.initContainerEnv[1].value="https://mirrors.tuna.tsinghua.edu.cn/jenkins/" \
      stable/jenkins
    

    Thanks @willzhang . Your solution made by day <3

  21. hari4147 commented on Aug 26, 2022

    @hari4147

    set using an array list destroy the values yaml structure

    1. I have powershell script to set a collection of values to a single key in values.yaml
      image

    But when I execute the The script result like this.
    image
    Actually I want the values like this, But i got this structure only use the set flag like this helm upgrade testing testconfig --set "KeyvautCollection={may0,may1}"
    image
    I want to pass a dynamic array along with --set flag

  22. madrisan commented on Aug 26, 2022

    @madrisan

    @hari4147 stackoverflow.com is a way better site for this type of questions.

  23. hari4147 commented on Aug 26, 2022

    @hari4147
  24. nyurik commented on Apr 28, 2024

    @nyurik

    In case when a value could be either a single string, or multiple strings, using toStrings in a template makes it much easier to override. In the following setup, it is possible to use --set foo.mylist=bar to override a,b,c list with a single value bar, while still treating it as a list.

    values.yaml

    foo:
      mylist: ["a", "b", "c"]

    templates/foo.yaml

    {{- range $val := .Values.foo.mylist | toStrings }}
      {{- $val }}
    {{- end }}
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions