Add functions enabling one to insert complex values in a dictionnary at a specific path
What it does
This code was written in the SylvaWorkloadCluster operator. As the present operator is expected to do the same as in workload-cluster-operator!315 (comment 2631686888) this code is moved here.
Tests
- Unit tests can be found in the common packages. They are green in the pipeline
- Helm parsing tests
- Present MR tests
Comparison to FluxCD and Helm
FluxCD is only allowing plain data. It uses the Helm parser strvals.ParseInto to transform a string like "a.b[1].c=foo" into the correct object. See https://github.com/fluxcd/pkg/blob/d07717ff225741ef8164097fe88d9192e71731f0/chartutil/values.go#L239
a:
b:
- null
- c: foo
The present MR uses the same parser to put a fake value markerLeaf (equal to "marker-leaf-substitute-here"). Relying on the Helm parser enables the code to support the same rune set and the same syntax for the path
a:
b:
- null
- c: marker-leaf-substitute-here
Then the object is unmarshaled and parsed by a recursive function until markerLeafis found. Then the ConfigMap / Secret / ExternalSecret values is inserted
{"c": "marker-leaf-substitute-here"} --> {"c": map[string]any{...}}
Finally the final result is marshaled.