This is a response to: https://stackoverflow.com/questions/75115089/ytt-append-array-items-together-but-remove-duplicates
_
This is a response to: https://stackoverflow.com/questions/75115089/ytt-append-array-items-together-but-remove-duplicates
_
| apiVersion: kapp.k14s.io/v1alpha1 | |
| kind: Config | |
| rebaseRules: | |
| - path: [data] | |
| type: copy | |
| sources: [existing, new] | |
| resourceMatchers: | |
| - kindNamespaceNameMatcher: {kind: ConfigMap, namespace: kube-system, name: antrea-ca} |
| load("@ytt:struct", "struct") | |
| load("@ytt:yaml", "yaml") | |
| # `raw_yaml()` makes an editable copy of `node` | |
| # warning: all nodes are scrubbed of attached annotations and code. | |
| def raw_yaml(node): | |
| return yaml.decode(yaml.encode(node)) | |
| end | |
| def key_or_index(target, part): |
| #!/usr/bin/env bash | |
| KIND=$(yq --raw-output '.kind' <(cat $1)) | |
| case ${KIND} in | |
| "Config") | |
| read -r -d '' TEMPLATE <<'EOF' | |
| #@ load("@ytt:data", "data") | |
| --- | |
| apiVersion: imgpkg.k14s.io/v1alpha1 |
| // on classpath: https://repo1.maven.org/maven2/org/yaml/snakeyaml/1.27/snakeyaml-1.27.jar | |
| package emptynode; | |
| import org.yaml.snakeyaml.Yaml; | |
| import java.util.Map; | |
| public class ParseYaml { | |
| public static void main(String[] args) { | |
| Yaml yaml = new Yaml(); | |
| Map<String, Object> obj = yaml.load("---\nfoo: #@ data.value\n"); |
| #@ load("@ytt:data", "data") | |
| apps: | |
| #@ for app in data.values.traefik.ingress_routes: | |
| - #@ app | |
| #@ end |
| load("@ytt:overlay", "overlay") | |
| # `k8s_resource` yields matcher function that returns subset matching the Kubernetes resource parameters. | |
| def k8s_resource(apiVersion, kind, name): | |
| return overlay.subset({"apiVersion": apiVersion, "kind": kind, "metadata": {"name": name}}) | |
| end | |
| # `shape` yields matcher function that returns True when the structure of `right` matches that of `left` | |
| # (ignoring leaves). | |
| # exactly :: when `True`, array items in `left` must match exactly in the order they appear in `right` |
| #@overlay/match by=lambda i,l,r: True | |
| --- | |
| metadata: | |
| namespace: foos |
| --- | |
| clients: | |
| - client1: | |
| secret: blah1 | |
| - client2: | |
| secret: blah2 | |
| #@ load("@ytt:overlay", "overlay") | |
| #@overlay/match by=overlay.all | |
| --- |
Create a starter test
package main
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega")