|
| 1 | +# reclass-rs Extensions |
| 2 | + |
| 3 | +Initially, reclass-rs only implemented features present in [kapicorp-reclass], including extensions introduced by kapicorp-reclass. |
| 4 | +This document covers extensions that are currently unique to reclass-rs. |
| 5 | + |
| 6 | +## Non-compatible `compose_node_name` option |
| 7 | + |
| 8 | +Reclass-rs supports the `compose_node_name` option. |
| 9 | +By default, in contrast to kapicorp-reclass, reclass-rs preserves literal dots in composed node names. |
| 10 | +For example, given the following inventory, the node's internal path is parsed as `['path', 'to', 'the.node']`: |
| 11 | + |
| 12 | +``` |
| 13 | +. |
| 14 | +├── classes |
| 15 | +│ ├── cls1.yml |
| 16 | +│ └── cls2.yml |
| 17 | +└── nodes |
| 18 | + └── path |
| 19 | + └── to |
| 20 | + └── the.node.yml |
| 21 | +``` |
| 22 | + |
| 23 | +However, optionally, reclass-rs can be configured to handle `compose_node_name` the same way that kapicorp-reclass does, by naively splitting node names on each dot. |
| 24 | +To enable this compatibility mode, set `compat_flags: ['ComposeNodeNameLiteralDots']` in your inventory's `reclass-config.yml`. |
| 25 | +In compatibility mode, the node's internal path for the previous inventory is `['path', 'to', 'the', 'node']`. |
| 26 | + |
| 27 | +## Default values for references |
| 28 | + |
| 29 | +> [!IMPORTANT] |
| 30 | +> This feature is currently experimental and may change at any time. |
| 31 | +
|
| 32 | +Reclass-rs supports specifying default (fallback) values for references. |
| 33 | +The format for specifying a default value is `${some:reference:path::the_default_value}`. |
| 34 | + |
| 35 | +We chose `::` as the separator between the reference path and the default value, because `::` can't appear in references in valid kapicorp-reclass inventories (due to [kapicorp/kapitan#1171](https://github.com/kapicorp/kapitan/issues/1171)). |
| 36 | + |
| 37 | +Reclass-rs first resolves nested references in the reference path and default value and then splits the reference contents into the path and default value. |
| 38 | +References with default values can be used everywhere that references are supported, including class includes. |
| 39 | + |
| 40 | +> [!NOTE] |
| 41 | +> Currently, default values are only applied once all nested references have been successfully resolved. |
| 42 | +> A missing nested reference without its own default value will result in an error even if the top-level reference specifies a default value. |
| 43 | +
|
| 44 | +For further processing, the default value is parsed as YAML. |
| 45 | +Incomplete YAML flow values always raise an error (also for existing references that specify an incomplete YAML default value). |
| 46 | + |
| 47 | +> [!NOTE] |
| 48 | +> While it's generally possible to specify arbitrarily complex YAML default values inline, we recommend specifying complex default values through a nested reference. |
| 49 | +> When providing complex default values inline, it may be necessary to carefully escape characters of the YAML value in order to ensure the reference parser keeps the YAML value intact. |
| 50 | +
|
| 51 | +### Example |
| 52 | + |
| 53 | +``` |
| 54 | +# nodes/test.yml |
| 55 | +classes: |
| 56 | + - class1 |
| 57 | + - class2 |
| 58 | +
|
| 59 | +parameters: |
| 60 | + _base_directory: /tmp |
| 61 | +``` |
| 62 | + |
| 63 | +``` |
| 64 | +# classes/class1.yml |
| 65 | +parameters: |
| 66 | + helm_values: |
| 67 | + a: a |
| 68 | + b: b |
| 69 | +``` |
| 70 | + |
| 71 | +``` |
| 72 | +# classes/class2.yml |
| 73 | +parameters: |
| 74 | + _compile: |
| 75 | + jsonnet: |
| 76 | + - input_paths: |
| 77 | + - ${_base_directory}/foo.jsonnet |
| 78 | + type: jsonnet |
| 79 | + output_path: foo |
| 80 | + helm: |
| 81 | + - input_paths: |
| 82 | + - ${_base_directory}/charts/foo |
| 83 | + type: helm |
| 84 | + helm_values: ${helm_values} |
| 85 | + output_path: foo |
| 86 | + kustomize: |
| 87 | + - input_paths: |
| 88 | + - ${_base_directory}/kustomization.jsonnet |
| 89 | + type: jsonnet |
| 90 | + output_path: ${_base_directory}/kustomizations/foo |
| 91 | + - input_paths: |
| 92 | + - ${_base_directory}/kustomizations/foo/ |
| 93 | + type: kustomize |
| 94 | + output_path: foo |
| 95 | +
|
| 96 | + # Fall back to jsonnet rendering if method isn't configured |
| 97 | + compile: ${_compile:${method::jsonnet}} |
| 98 | +``` |
| 99 | + |
| 100 | +The rendered parameters for node `test` shown above: |
| 101 | + |
| 102 | +``` |
| 103 | +parameters: |
| 104 | + _reclass_: |
| 105 | + environment: base |
| 106 | + name: |
| 107 | + full: test |
| 108 | + parts: |
| 109 | + - test |
| 110 | + path: test |
| 111 | + short: test |
| 112 | + _base_directory: /tmp |
| 113 | + _compile: |
| 114 | + helm: |
| 115 | + - helm_values: |
| 116 | + a: a |
| 117 | + b: b |
| 118 | + input_paths: |
| 119 | + - /tmp/charts/foo |
| 120 | + output_path: foo |
| 121 | + type: helm |
| 122 | + jsonnet: |
| 123 | + - input_paths: |
| 124 | + - /tmp/foo.jsonnet |
| 125 | + output_path: foo |
| 126 | + type: jsonnet |
| 127 | + kustomize: |
| 128 | + - input_paths: |
| 129 | + - /tmp/kustomization.jsonnet |
| 130 | + output_path: /tmp/kustomizations/foo |
| 131 | + type: jsonnet |
| 132 | + - input_paths: |
| 133 | + - /tmp/kustomizations/foo/ |
| 134 | + output_path: foo |
| 135 | + type: kustomize |
| 136 | + compile: |
| 137 | + - input_paths: |
| 138 | + - /tmp/foo.jsonnet |
| 139 | + output_path: foo |
| 140 | + type: jsonnet |
| 141 | + helm_values: |
| 142 | + a: a |
| 143 | + b: b |
| 144 | +``` |
| 145 | + |
| 146 | +> [!TIP] |
| 147 | +> This example can also be found as node `n9` and classes `component.defaults` and `component.component` in this repository's `tests/inventory-reference-default-values`. |
| 148 | +
|
| 149 | +[kapicorp-reclass]: https://github.com/kapicorp/reclass |
0 commit comments