Skip to content

Commit

Permalink
add an example of serialized structures used in config map
Browse files Browse the repository at this point in the history
  • Loading branch information
cppforlife committed Jul 11, 2019
1 parent 21fd25d commit 7b7e5d7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/k8s-config-map-files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This example was created to show how to include YAML structures into k8s ConfigMap as YAML serialized files. We use functions to group configuration that is later serialized via `yaml.encode`.

[slack thread](https://kubernetes.slack.com/archives/CH8KCCKA5/p1562863952459400)
14 changes: 14 additions & 0 deletions examples/k8s-config-map-files/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#@ load("@ytt:yaml", "yaml")
#@ load("@ytt:json", "json")
#@ load("config1.lib.yml", "config1")
#@ load("config2.lib.yml", "config2")

---
kind: ConfigMap
apiVersion: v1
metadata:
name: configs
data:
config1.yml: #@ yaml.encode(config1())
config2.yml: #@ yaml.encode(config2())
config3.json: #@ json.encode(config2())
7 changes: 7 additions & 0 deletions examples/k8s-config-map-files/config1.lib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#@ def config1():
---
config1a: config1a
config1b: config1b
---
config1c: config1c
#@ end
9 changes: 9 additions & 0 deletions examples/k8s-config-map-files/config2.lib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#@ def config2():
rules2a: 123
rules2b: #@ config2sub()
#@ end

---
#@ def config2sub():
[a, b, c]
#@ end
17 changes: 17 additions & 0 deletions examples/k8s-config-map-files/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: configs
data:
config1.yml: |
config1a: config1a
config1b: config1b
---
config1c: config1c
config2.yml: |
rules2a: 123
rules2b:
- a
- b
- c
config3.json: '{"rules2a":123,"rules2b":["a","b","c"]}'
1 change: 1 addition & 0 deletions hack/test-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ done
diff <(./ytt -f examples/k8s-adjust-rbac-version) examples/k8s-adjust-rbac-version/expected.txt
diff <(./ytt -f examples/k8s-docker-secret) examples/k8s-docker-secret/expected.txt
diff <(./ytt -f examples/k8s-relative-rolling-update) examples/k8s-relative-rolling-update/expected.txt
diff <(./ytt -f examples/k8s-config-map-files) examples/k8s-config-map-files/expected.txt
diff <(./ytt -f examples/concourse-overlay) examples/concourse-overlay/expected.txt

echo E2E SUCCESS

0 comments on commit 7b7e5d7

Please sign in to comment.