Created
October 17, 2022 23:21
-
-
Save pivotaljohn/575b030ab09c07d535c4acdf4ba12d93 to your computer and use it in GitHub Desktop.
Generate ConfigMaps with layered environment-specific configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ load("@ytt:data", "data") | |
#@ load("@ytt:overlay", "overlay") | |
#@ for app_name in dir(data.values.configmaps): | |
#! first, instantiate a ConfigMap for the app with empty data... | |
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
labels: | |
label1: value1 | |
name: #@ app_name | |
data: {} | |
#! then, for each environment, generate an overlay that merges the configuration... | |
#@ for env in ["all-envs", "dev"]: | |
#@ if hasattr(data.values.configmaps[app_name], env): | |
#@overlay/match by=overlay.subset({"kind": "ConfigMap", "metadata": {"name": app_name}}) | |
--- | |
#@overlay/match-child-defaults missing_ok=True | |
data: #@ data.values.configmaps[app_name][env] | |
#@ end | |
#@ end | |
#@ end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@data/values-schema | |
--- | |
configmaps: | |
service1: | |
all-envs: | |
PVC: "false" | |
ENDPOINT: http://internal-api:8080/api/v1/scan | |
PATH: /test1 | |
dev: | |
DB_HOST: 192.168.1.1 | |
DB_USER: service1_dev | |
service2: | |
dev: | |
DB_HOST: 192.168.1.2 | |
DB_USER: service2_dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment