|
| 1 | +# Common Helm Chart |
| 2 | + |
| 3 | +[](https://opensource.org/licenses/Apache-2.0)   |
| 4 | + |
| 5 | +# Common Chart |
| 6 | + |
| 7 | +A Helm library chart providing a framework for generating Kubernetes resources with advanced templating and layered value inheritance for single and multi-component charts. |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +This library chart enables: |
| 12 | +- Component-based resource generation |
| 13 | +- Layered value inheritance |
| 14 | +- Advanced template processing |
| 15 | +- Generalized ability to override-anything |
| 16 | +- Automatic map-to-list transformations for more conveniet values interfaces |
| 17 | +- Standardized resource generation patterns |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### 1. Include it as Dependency |
| 22 | + |
| 23 | +```yaml |
| 24 | +# Chart.yaml |
| 25 | +dependencies: |
| 26 | + - name: common |
| 27 | +``` |
| 28 | +
|
| 29 | +### 2. Configure Components |
| 30 | +
|
| 31 | +Configuation is done by creating a file named `_common.config.yaml` in the root of your chart. |
| 32 | +Components can be configured in three modes: |
| 33 | + |
| 34 | +#### Single Component |
| 35 | + |
| 36 | +```yaml |
| 37 | +# _common.config.yaml |
| 38 | +dynamicComponents: false |
| 39 | +
|
| 40 | +components: |
| 41 | + - myComponent |
| 42 | +
|
| 43 | +componentLayering: |
| 44 | + myComponent: [] |
| 45 | +``` |
| 46 | + |
| 47 | +which decleares a top level key `myComponent` for a single component, and no keys from which to inherit defaults. |
| 48 | +Even for a single component, you may wish to have a separate key from which to inherit defaults just to leave the main top level key a bit cleaner for the user, i.e.: |
| 49 | + |
| 50 | +```yaml |
| 51 | +# _common.config.yaml |
| 52 | +dynamicComponents: false |
| 53 | +
|
| 54 | +components: |
| 55 | + - myComponent |
| 56 | +
|
| 57 | +componentLayering: |
| 58 | + myComponent: |
| 59 | + - myComponentDefaults |
| 60 | +``` |
| 61 | + |
| 62 | +#### Multiple Static Components |
| 63 | + |
| 64 | +```yaml |
| 65 | +# _common.config.yaml |
| 66 | +dynamicComponents: false |
| 67 | +
|
| 68 | +components: |
| 69 | + - statefulNode |
| 70 | + - rpcdaemon |
| 71 | +
|
| 72 | +componentLayering: |
| 73 | + statefulNode: |
| 74 | + - erigonDefaults |
| 75 | + rpcdaemon: |
| 76 | + - erigonDefaults |
| 77 | +
|
| 78 | +``` |
| 79 | + |
| 80 | +This defines two separate components, `statefulNode` and `rpcdaemon`, both of which inherit common defaults from an `erigonDefaults` key. |
| 81 | + |
| 82 | +#### Dynamic Components |
| 83 | + |
| 84 | +```yaml |
| 85 | +# _common.config.yaml |
| 86 | +dynamicComponents: true |
| 87 | +
|
| 88 | +componentsKey: <Top Level key expected to have components as subkeys> |
| 89 | +
|
| 90 | +componentLayering: '{{ Templating Logic that generates componentLayering based dinamically }} |
| 91 | +``` |
| 92 | + |
| 93 | +### 3. Define Values |
| 94 | + |
| 95 | +Structure your values in layers that match your inheritance configuration: |
| 96 | + |
| 97 | +```yaml |
| 98 | +# values.yaml |
| 99 | +defaults: |
| 100 | + resources: |
| 101 | +``` |
| 102 | + |
| 103 | +### 4. Template References |
| 104 | + |
| 105 | +Components can reference values from other components using `@needs` directive: |
| 106 | + |
| 107 | +```yaml |
| 108 | +rpcdaemon: |
| 109 | + config: | |
| 110 | + @needs(ComponentValues.statefulnode.ports[0].containerPort as nodePort) |
| 111 | +``` |
| 112 | + |
| 113 | +## Architecture |
| 114 | + |
| 115 | +The chart processes resources through several phases: |
| 116 | + |
| 117 | +1. **Initialization** |
| 118 | + - Processes component configuration and inheritance stacks |
| 119 | + - Merges values according to defined layers |
| 120 | + - Setup Templating Context |
| 121 | + - Template resolution on values, with preprocessor directives (@needs, @type, ...) |
| 122 | + |
| 123 | +2. **Per-Component Resource Generation** |
| 124 | + - Starts with base resource templates |
| 125 | + - Overlays component-specific values |
| 126 | + - Does an intermediate render with resolved context |
| 127 | + - Applies resource transformations (convert back maps to lists) |
| 128 | + - Prunes output of internal or disabled fields |
| 129 | + - Prints final resources render |
| 130 | + |
| 131 | +```mermaid |
| 132 | +flowchart TB |
| 133 | + %% Input Configuration |
| 134 | + A([Chart Layout Config + Values]) --> B |
| 135 | +
|
| 136 | + subgraph Init["Initialization Phase"] |
| 137 | + direction TB |
| 138 | + B["Process Layout Config</br><i>(component keys and values inheritance stack)</i>"] |
| 139 | + B --> C["Merge Values Stacks></br><i>(per component)</i>"] |
| 140 | + C --> D[Setup Templating Context] |
| 141 | + D --> E["Template Resolution<br/><i>(process @needs/@type directives and executes templates)</i>"] |
| 142 | + end |
| 143 | +
|
| 144 | + E --> R1[(Base: Service YAML)] |
| 145 | + E --> R2[(Base: ConfigMap YAML)] |
| 146 | +
|
| 147 | + subgraph CompA["Component A: StatefulNode"] |
| 148 | + subgraph ResA["Per Resource Type Pipeline"] |
| 149 | + R1 --> H1[Merge Resource Values] |
| 150 | + H1 --> M1["Intermediate Render"] |
| 151 | + M1 --> I1["Transforms<br/><i>(convert maps to lists)</i>"] |
| 152 | + I1 --> J1["Prune Output<br/><i>(clean internal fields)</i>"] |
| 153 | + end |
| 154 | + end |
| 155 | +
|
| 156 | + subgraph CompB["Component B: rpcdaemon"] |
| 157 | + subgraph ResB["Per Resource Type Pipeline"] |
| 158 | + R2 --> H2[Overlay Resource Values] |
| 159 | + H2 --> M2["Intermediate Render"] |
| 160 | + M2 --> I2["Transforms<br/><i>(convert maps to lists)</i>"] |
| 161 | + I2 --> J2["Prune Output<br/><i>(clean internal fields)</i>"] |
| 162 | + end |
| 163 | + end |
| 164 | +
|
| 165 | + J1 --> K{Output Final Kubernetes<br/>Resources} |
| 166 | + J2 --> K |
| 167 | +``` |
| 168 | + |
| 169 | +## Upgrading |
| 170 | + |
| 171 | +We recommend that you pin the version of the Chart that you deploy. You can use the `--version` flag with `helm install` and `helm upgrade` to specify a chart version constraint. |
| 172 | + |
| 173 | +This project uses [Semantic Versioning](https://semver.org/). Changes to the version of the application (the `appVersion`) that the Chart deploys will generally result in a patch version bump for the Chart. Breaking changes to the Chart or its `values.yaml` interface will be reflected with a major version bump. |
| 174 | + |
| 175 | +We do not recommend that you upgrade the application by overriding `image.tag`. Instead, use the version of the Chart that is built for your desired `appVersion`. |
| 176 | + |
| 177 | +## Contributing |
| 178 | + |
| 179 | +We welcome and appreciate your contributions! Please see the [Contributor Guide](/CONTRIBUTING.md), [Code Of Conduct](/CODE_OF_CONDUCT.md) and [Security Notes](/SECURITY.md) for this repository. |
0 commit comments