Last active
March 15, 2021 06:43
-
-
Save sparkprime/60027c4665eb19796fe2ba43ffe033d5 to your computer and use it in GitHub Desktop.
Example of string templating within Jsonnet
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
{ | |
template: (importstr "template.yaml") % { | |
name: "rabbitmq", | |
image: "whatever", | |
cookie: "XXXX", | |
data_volume: std.toString({ name: "thing", foo: [1, 2, 3] }), | |
nodes: std.toString(['rabbit@rabbitmq-%s' % shard_name for shard_name in [1, 2, 3]]), | |
}, | |
} |
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
{ | |
"template": "---\napiVersion: v1\nkind: ReplicationController\nmetadata:\n labels:\n k8s-app: rabbitmq\n name: rabbitmq\nspec:\n replicas: 1\n selector:\n k8s-app: rabbitmq\n shard: \"rabbitmq\"\n template:\n metadata:\n labels:\n k8s-app: rabbitmq\n shard: \"rabbitmq\"\n spec:\n containers:\n - image: \"whatever\"\n name: rabbitmq\n ports:\n - containerPort: 5672\n name: rmq\n - containerPort: 15672\n name: dash\n - containerPort: 4369\n name: erlang\n - containerPort: 25672\n name: cluster\n resources:\n limits:\n cpu: 500m\n memory: 2G\n env:\n - name: RABBITMQ_CLUSTER_NODES\n value: \"[\"rabbit@rabbitmq-1\", \"rabbit@rabbitmq-2\", \"rabbit@rabbitmq-3\"]\"\n - name: RABBITMQ_ERLANG_COOKIE\n value: \"XXXX\"\n - name: RABBITMQ_HOSTNAME\n value: \"rabbitmq-rabbitmq\"\n - name: RABBITMQ_NODENAME\n value: \"rabbit@rabbitmq-rabbitmq\"\n volumeMounts:\n - mountPath: '/var/lib/rabbitmq'\n name: 'varlibrabbitmq'\n volumes:\n - {\"foo\": [1, 2, 3], \"name\": \"thing\"}\n\n" | |
} |
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
--- | |
apiVersion: v1 | |
kind: ReplicationController | |
metadata: | |
labels: | |
k8s-app: rabbitmq | |
name: rabbitmq | |
spec: | |
replicas: 1 | |
selector: | |
k8s-app: rabbitmq | |
shard: "%(name)s" | |
template: | |
metadata: | |
labels: | |
k8s-app: rabbitmq | |
shard: "%(name)s" | |
spec: | |
containers: | |
- image: "%(image)s" | |
name: rabbitmq | |
ports: | |
- containerPort: 5672 | |
name: rmq | |
- containerPort: 15672 | |
name: dash | |
- containerPort: 4369 | |
name: erlang | |
- containerPort: 25672 | |
name: cluster | |
resources: | |
limits: | |
cpu: 500m | |
memory: 2G | |
env: | |
- name: RABBITMQ_CLUSTER_NODES | |
value: %(nodes)s | |
- name: RABBITMQ_ERLANG_COOKIE | |
value: "%(cookie)s" | |
- name: RABBITMQ_HOSTNAME | |
value: "rabbitmq-%(name)s" | |
- name: RABBITMQ_NODENAME | |
value: "rabbit@rabbitmq-%(name)s" | |
volumeMounts: | |
- mountPath: '/var/lib/rabbitmq' | |
name: 'varlibrabbitmq' | |
volumes: | |
- %(data_volume)s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment