Skip to content

Commit a56428e

Browse files
committed
add jsonnet examples
1 parent 5aa3624 commit a56428e

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

chapter-03/jsonnet/advanced.jsonnet

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function(prod=false) { # A, B
2+
"apiVersion": "apps/v1",
3+
"kind": "Deployment",
4+
"metadata": {
5+
"name": "nginx"
6+
},
7+
"spec": {
8+
"selector": {
9+
"matchLabels": {
10+
"app": $.metadata.name # C
11+
}
12+
},
13+
"replicas": if prod then 10 else 1, # D
14+
"template": {
15+
"metadata": {
16+
"labels": {
17+
"app": $.metadata.name
18+
}
19+
},
20+
"spec": {
21+
"containers": [
22+
{
23+
"name": $.metadata.name,
24+
"image": "nginx:1.14.2",
25+
"ports": [
26+
{
27+
"containerPort": 80
28+
}
29+
]
30+
}
31+
]
32+
}
33+
}
34+
}
35+
}

chapter-03/jsonnet/basic.jsonnet

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
// Look! It's JSON with comments!
3+
"apiVersion": "apps/v1",
4+
"kind": "Deployment",
5+
"metadata": {
6+
"name": "nginx"
7+
},
8+
"spec": {
9+
"selector": {
10+
"matchLabels": {
11+
"app": "nginx"
12+
}
13+
},
14+
"replicas": 2,
15+
"template": {
16+
"metadata": {
17+
"labels": {
18+
"app": "nginx"
19+
}
20+
},
21+
"spec": {
22+
"containers": [
23+
{
24+
"name": "nginx",
25+
"image": "nginx:1.14.2",
26+
"ports": [
27+
{
28+
"containerPort": 80
29+
}
30+
]
31+
}
32+
]
33+
}
34+
}
35+
}
36+
}

chapter-03/jsonnet/variables.jsonnet

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
local name = "nginx";
2+
local version = "1.14.2";
3+
local replicas = 2;
4+
{
5+
"apiVersion": "apps/v1",
6+
"kind": "Deployment",
7+
"metadata": {
8+
"name": name
9+
},
10+
"spec": {
11+
"selector": {
12+
"matchLabels": {
13+
"app": name
14+
}
15+
},
16+
"replicas": replicas,
17+
"template": {
18+
"metadata": {
19+
"labels": {
20+
"app": name
21+
}
22+
},
23+
"spec": {
24+
"containers": [
25+
{
26+
"name": name,
27+
"image": "nginx:" + version,
28+
"ports": [
29+
{
30+
"containerPort": 80
31+
}
32+
]
33+
}
34+
]
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)