github.com/rakanixu/helm@v2.8.2+incompatible/docs/chart_best_practices/values.md (about)

     1  # Values
     2  
     3  This part of the best practices guide covers using values. In this part of the
     4  guide, we provide recommendations on how you should structure and use your
     5  values, with focus on designing a chart's `values.yaml` file.
     6  
     7  ## Naming Conventions
     8  
     9  Variables names should begin with a lowercase letter, and words should be
    10  separated with camelcase:
    11  
    12  Correct:
    13  
    14  ```yaml
    15  chicken: true
    16  chickenNoodleSoup: true
    17  ```
    18  
    19  Incorrect:
    20  
    21  ```yaml
    22  Chicken: true  # initial caps may conflict with built-ins
    23  chicken-noodle-soup: true # do not use hyphens in the name
    24  ```
    25  
    26  Note that all of Helm's built-in variables begin with an uppercase letter to
    27  easily distinguish them from user-defined values: `.Release.Name`,
    28  `.Capabilities.KubeVersion`.
    29  
    30  ## Flat or Nested Values
    31  
    32  YAML is a flexible format, and values may be nested deeply or flattened.
    33  
    34  Nested:
    35  
    36  ```yaml
    37  server:
    38    name: nginx
    39    port: 80
    40  ```
    41  
    42  Flat:
    43  
    44  ```yaml
    45  serverName: nginx
    46  serverPort: 80
    47  ```
    48  
    49  In most cases, flat should be favored over nested. The reason for this is that
    50  it is simpler for template developers and users.
    51  
    52  
    53  For optimal safety, a nested value must be checked at every level:
    54  
    55  ```
    56  {{ if .Values.server }}
    57    {{ default "none" .Values.server.name }}
    58  {{ end }}
    59  ```
    60  
    61  For every layer of nesting, an existence check must be done. But for flat
    62  configuration, such checks can be skipped, making the template easier to read
    63  and use.
    64  
    65  ```
    66  {{ default "none" .Values.serverName }}
    67  ```
    68  
    69  When there are a large number of related variables, and at least one of them
    70  is non-optional, nested values may be used to improve readability.
    71  
    72  ## Make Types Clear
    73  
    74  YAML's type coercion rules are sometimes counterintuitive. For example,
    75  `foo: false` is not the same as `foo: "false"`. Large integers like `foo: 12345678`
    76  will get converted to scientific notation in some cases.
    77  
    78  The easiest way to avoid type conversion errors is to be explicit about strings,
    79  and implicit about everything else. Or, in short, _quote all strings_.
    80  
    81  Often, to avoid the integer casting issues, it is advantageous to store your
    82  integers as strings as well, and use `{{ int $value }}` in the template to convert
    83  from a string back to an integer.
    84  
    85  In most cases, explicit type tags are respected, so `foo: !!string 1234` should
    86  treat `1234` as a string. _However_, the YAML parser consumes tags, so the type
    87  data is lost after one parse.
    88  
    89  ## Consider How Users Will Use Your Values
    90  
    91  There are three potential sources of values:
    92  
    93  - A chart's `values.yaml` file
    94  - A values file supplied by `helm install -f` or `helm upgrade -f`
    95  - The values passed to a `--set` flag on `helm install` or `helm upgrade`
    96  
    97  When designing the structure of your values, keep in mind that users of your
    98  chart may want to override them via either the `-f` flag or with the `--set`
    99  option.
   100  
   101  Since `--set` is more limited in expressiveness, the first guidelines for writing
   102  your `values.yaml` file is _make it easy to override from `--set`_.
   103  
   104  For this reason, it's often better to structure your values file using maps.
   105  
   106  Difficult to use with `--set`:
   107  
   108  ```yaml
   109  servers:
   110    - name: foo
   111      port: 80
   112    - name: bar
   113      port: 81
   114  ```
   115  
   116  The above cannot be expressed with `--set` in Helm `<=2.4`. In Helm 2.5, the
   117  accessing the port on foo is `--set servers[0].port=80`. Not only is it harder
   118  for the user to figure out, but it is prone to errors if at some later time the
   119  order of the `servers` is changed.
   120  
   121  Easy to use:
   122  
   123  ```yaml
   124  servers:
   125    foo:
   126      port: 80
   127    bar:
   128      port: 81
   129  ```
   130  
   131  Accessing foo's port is much more obvious: `--set servers.foo.port=80`.
   132  
   133  ## Document 'values.yaml'
   134  
   135  Every defined property in 'values.yaml' should be documented. The documentation string should begin with the name of the property that it describes, and then give at least a one-sentence description.
   136  
   137  Incorrect:
   138  
   139  ```
   140  # the host name for the webserver
   141  serverHost = example
   142  serverPort = 9191
   143  ```
   144  
   145  Correct:
   146  
   147  ```
   148  # serverHost is the host name for the webserver
   149  serverHost = example
   150  # serverPort is the HTTP listener port for the webserver
   151  serverPort = 9191
   152  
   153  ```
   154  
   155  Beginning each comment with the name of the parameter it documents makes it easy to grep out documentation, and will enable documentation tools to reliably correlate doc strings with the parameters they describe.