-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
34 changed files
with
444 additions
and
29 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.idea | ||
assets/**/charts | ||
Chart.lock |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v2 | ||
name: step2 | ||
type: application | ||
version: 0.1.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
name = input.metadata.name | ||
|
||
is_deployment { | ||
input.kind = "Deployment" | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
not name == "fancy" | ||
msg = sprintf("your deployment should have name %s and not %s ", ["fancy", name]) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ required "need to set some name for deployment" .Values.name }} | ||
annotations: | ||
chart: {{ default .Chart.Name .Values.nameOverride }} | ||
labels: | ||
app: nginx |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v2 | ||
name: step3 | ||
type: application | ||
version: 0.1.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
name = input.metadata.name | ||
|
||
is_deployment { | ||
input.kind = "Deployment" | ||
} | ||
|
||
required_labels { | ||
input.metadata.labels["env"] | ||
input.metadata.labels["team"] | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
not required_labels | ||
msg = sprintf("deployment %s must have labels env and team", [name]) | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
label := input.metadata.labels["env"] | ||
not label == "prod" | ||
msg = sprintf("label %s must have value %s but found %s", ["env", "prod", label]) | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
label := input.metadata.labels["team"] | ||
not label == "dev" | ||
msg = sprintf("label %s must have value %s but has value %s", ["team", "dev", label]) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx | ||
annotations: | ||
chart: {{ default .Chart.Name .Values.nameOverride }} | ||
labels: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
customLabels: | ||
- name: env | ||
value: "prod" | ||
- name: team | ||
value: "dev" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v2 | ||
name: step4 | ||
type: application | ||
version: 0.1.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
name = input.metadata.name | ||
|
||
required_deployment_labels { | ||
input.metadata.labels["app"] | ||
input.metadata.labels["addon"] | ||
input.metadata.labels["triple"] | ||
} | ||
|
||
is_deployment { | ||
input.kind = "Deployment" | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
not required_deployment_labels | ||
msg = sprintf("deployment %s must have labels app, addon and triple", [name]) | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
label := input.metadata.labels["app"] | ||
not label = "nginx-trace-addon" | ||
msg = sprintf("label %s must have value %s but have %s", ["app", "nginx-trace-addon", label]) | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
label := input.metadata.labels["addon"] | ||
not label = "TRACE-ADDON" | ||
msg = sprintf("label %s must have value %s but have %s", ["addon", "TRACE-ADDON", label]) | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
not input.metadata.labels["triple"] = "nginx-trace-addonnginx-trace-addonnginx-trace-addon" | ||
msg = sprintf("label %s must have value %s", ["triple", "nginx-trace-addonnginx-trace-addonnginx-trace-addon"]) | ||
} |
10 changes: 10 additions & 0 deletions
10
helm-template-basic/assets/step4/templates/deployment.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx2 | ||
annotations: | ||
chart: {{ default .Chart.Name .Values.nameOverride }} | ||
labels: | ||
app: {{ .Values.app.name }} | ||
addon: {{ .Values.app.name }} | ||
triple: {{ .Values.app.name }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
app: | ||
name: "nginx-trace-addon" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: v2 | ||
name: step5 | ||
type: application | ||
version: 0.1.0 | ||
dependencies: | ||
- name: step2 | ||
alias: steps2 | ||
version: 0.1.0 | ||
repository: file://../step2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
name = input.metadata.name | ||
chart = input.metadata.annotations.chart | ||
manifest = input[_] | ||
|
||
is_deployment { | ||
input.kind = "Deployment" | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
name = "nginx" | ||
chart != "frontend" | ||
msg = sprintf("Expected alias frontend for step 3 chart but found %s", [chart]) | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
name = "nginx2" | ||
chart != "backend" | ||
msg = sprintf("Expected alias backend for step 4 chart but found %s", [chart]) | ||
} | ||
|
||
deny[msg] { | ||
is_deployment | ||
name = "nginx2" | ||
label := input.metadata.labels["app"] | ||
label != "umbrella" | ||
msg = sprintf("Expected value app.name of step4 chart to be equal to umbrella but found %s", [label]) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx3 | ||
annotations: | ||
chart: {{ default .Chart.Name .Values.nameOverride }} |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -x # to test stderr output in /var/log/killercoda | ||
|
||
echo starting... # to test stdout output in /var/log/killercoda | ||
|
||
sleep 3 # add some time to wait for IDE | ||
|
||
touch /tmp/finished |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
echo "waiting for IDE..." | ||
while [ ! -f /tmp/finished ]; do sleep 1; done | ||
echo DONE |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"title": "Basic Helm Templating", | ||
"description": "Train to work with helm templates", | ||
"details": { | ||
"intro": { | ||
"text": "intro.md", | ||
"foreground": "foreground.sh", | ||
"background": "background.sh" | ||
}, | ||
"steps": [ | ||
{ | ||
"title": "Install Helm", | ||
"foreground": "step1/foreground.sh", | ||
"text": "step1/instruction.md", | ||
"verify": "step1/verify.sh" | ||
}, | ||
{ | ||
"title": "Umbrella Chart", | ||
"text": "step5/instruction.md", | ||
"verify": "step5/verify.sh" | ||
} | ||
], | ||
"assets": { | ||
"host01": [ | ||
{"file": "**", "target": "/app", "chmod": "+w"} | ||
] | ||
} | ||
}, | ||
"backend": { | ||
"imageid": "ubuntu" | ||
}, | ||
"interface": { | ||
"layout": "ide" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Helm template demo | ||
|
||
Please wait for IDE to finish loading before starting. |
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
command -v helm | ||
helm plugin ls | grep "conftest" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
### Create Values Files | ||
|
||
First create a file values.yaml in chart directory. | ||
`touch /app/step2/values.yaml`{{exec}} | ||
|
||
Add the key `name` with the value `fancy` to created file. | ||
|
||
You can read more in [official helm documentation](https://helm.sh/docs/chart_template_guide/values_files/) | ||
|
||
### Verify | ||
|
||
Move to helm chart dir. | ||
`cd /app/step2`{{exec}} | ||
|
||
Check if you can render helm template correctly. | ||
`helm template .`{{exec}} | ||
|
||
Check if you have passed the task. | ||
`helm conftest .`{{exec}} | ||
|
||
See error and result log in | ||
`cat /tmp/results.log`{{exec}} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
rm -rf /tmp/results.log | ||
cd /app/step2 | ||
helm conftest . > /tmp/results.log 2>&1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
### Loops | ||
|
||
Fix the chart of step 3 `cd /app/step3`{{exec}} | ||
|
||
The goal is to add all labels defined in `customLabels` in `values.yaml` by using a loop. | ||
|
||
The result helm template should look like this: | ||
```yaml | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx | ||
labels: | ||
env: prod | ||
team: dev | ||
``` | ||
You can read more about control structures in [helm docu](https://helm.sh/docs/chart_template_guide/control_structures/#looping-with-the-range-action) | ||
You can loop over a list of values | ||
```yaml | ||
toppings: |- | ||
{{- range .Values.pizzaToppings }} | ||
- {{ . | title | quote }} | ||
{{- end }} | ||
``` | ||
You can loop over a key-value map by | ||
```yaml | ||
toppings: |- | ||
{{- range .Values.pizzaToppings }} | ||
{{ .name }}: {{ .value }} | ||
{{- end }} | ||
``` | ||
If you are inside the loop you are in the scope of the object. You have access to attributes with `.`{{}}. | ||
But in order to reference other values, you need to prepend `$`{{}} e.g. `$.Values.otherValue`{{}} | ||
|
||
### Verify | ||
|
||
Move to helm chart dir. | ||
`cd /app/step3`{{exec}} | ||
|
||
Check if you can render helm template correctly. | ||
`helm template .`{{exec}} | ||
|
||
Check if you have passed the task. | ||
`helm conftest .`{{exec}} | ||
|
||
See error and result log in | ||
`cat /tmp/results.log`{{exec}} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
rm -rf /tmp/results.log | ||
cd /app/step3 | ||
helm conftest . > /tmp/results.log 2>&1 |
Oops, something went wrong.