Skip to content

Commit

Permalink
feat: add initContainer support
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloHiro committed Nov 17, 2023
1 parent 0220ab2 commit bc57444
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
4 changes: 4 additions & 0 deletions templates/deployment-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ spec:
app.kubernetes.io/component: registry
spec:
serviceAccountName: {{ include "apicurio-registry.name" . }}
{{- with .Values.registry.initContainers }}
initContainers:
{{- toYaml . | nindent 10 }}
{{- end }}
containers:
- name: registry
image: {{ include "apicurio-registry.image" .Values.registry }}
Expand Down
4 changes: 4 additions & 0 deletions templates/deployment-sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ spec:
app.kubernetes.io/component: sync
spec:
serviceAccountName: {{ include "apicurio-registry.name" . }}
{{- with .Values.sync.initContainers }}
initContainers:
{{- toYaml . | nindent 10 }}
{{- end }}
containers:
- name: sync
image: {{ .Values.sync.image.registry }}/{{ .Values.sync.image.repository }}:{{ .Values.sync.image.tag }}
Expand Down
20 changes: 20 additions & 0 deletions test/linter/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ if [ $? -ne 0 ]; then
exit 1
fi

helm lint . --strict --set registry.initContainers[0].image=foo
if [ $? -ne 0 ]; then
exit 1
fi

helm lint . --strict --set sync.initContainers[0].image=foo
if [ $? -ne 0 ]; then
exit 1
fi

helm lint . --strict --set registry.initContainers.name=foo
if [ $? -eq 0 ]; then
exit 1
fi

helm lint . --strict --set sync.initContainers.name=foo
if [ $? -eq 0 ]; then
exit 1
fi

echo "=================================================================================="
echo " LINT PASSED"
echo "=================================================================================="
44 changes: 44 additions & 0 deletions test/unit/initcontainer_registry_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
suite: test registry init container
templates:
- deployment-registry.yaml
tests:
- it: empty init container
asserts:
- notExists:
path: spec.template.spec.initContainers
- it: dummy init container
set:
registry:
initContainers:
- name: hello-world
image: dummy
command:
- /bin/sh
- -c
- echo "hello world"
volumeMounts:
- name: foo
mountPath: /bar
env:
- name: ENV_VAR
value: VALUE
asserts:
- equal:
path: spec.template.spec.initContainers[0].name
value: hello-world
- equal:
path: spec.template.spec.initContainers[0].command
value: [/bin/sh, -c, echo "hello world"]
- equal:
path: spec.template.spec.initContainers[0].volumeMounts[0].name
value: foo
- equal:
path: spec.template.spec.initContainers[0].volumeMounts[0].mountPath
value: /bar
- equal:
path: spec.template.spec.initContainers[0].env[0].name
value: ENV_VAR
- equal:
path: spec.template.spec.initContainers[0].env[0].value
value: VALUE
47 changes: 47 additions & 0 deletions test/unit/initcontainer_sync_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
suite: test sync init container
templates:
- deployment-sync.yaml
tests:
- it: empty init container
asserts:
- notExists:
path: spec.template.spec.initContainers
- it: dummy init container
set:
sync:
initContainers:
- name: hello-world
image: dummy
command:
- /bin/sh
- -c
- echo "hello world"
volumeMounts:
- name: foo
mountPath: /bar
env:
- name: ENV_VAR
value: VALUE
asserts:
- equal:
path: spec.template.spec.initContainers[0].name
value: hello-world
- equal:
path: spec.template.spec.initContainers[0].image
value: dummy
- equal:
path: spec.template.spec.initContainers[0].command
value: [/bin/sh, -c, echo "hello world"]
- equal:
path: spec.template.spec.initContainers[0].volumeMounts[0].name
value: foo
- equal:
path: spec.template.spec.initContainers[0].volumeMounts[0].mountPath
value: /bar
- equal:
path: spec.template.spec.initContainers[0].env[0].name
value: ENV_VAR
- equal:
path: spec.template.spec.initContainers[0].env[0].value
value: VALUE
5 changes: 5 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"value": {"type": "string"}
}
},
"initContainers": {
"type": "array", "default": []
},
"ingress": {
"type": "object", "title": "ingress resource for registry",
"required": ["enabled", "host", "path"],
Expand All @@ -80,6 +83,7 @@
"enabled": {"$ref": "#/definitions/isEnabled"},
"image": {"$ref": "#/definitions/dockerImage"},
"nodeSelector": {"type": "object", "title": "node selector for registry"},
"initContainers": {"$ref": "#/definitions/initContainers"},
"extraEnv": {
"type": "array", "default": [],
"items": {"$ref": "#/definitions/keyValue"}
Expand All @@ -97,6 +101,7 @@
"enabled": {"$ref": "#/definitions/isEnabled"},
"image": {"$ref": "#/definitions/dockerImage"},
"nodeSelector": {"type": "object", "title": "node selector for registry content sync"},
"initContainers": {"$ref": "#/definitions/initContainers"},
"resources": {"$ref": "#/definitions/podResources"},
"registryUrl": {"type": ["null", "string"], "default": null}
}
Expand Down
4 changes: 4 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ registry:
tag: "2.4.14.Final"
# optional node selector
nodeSelector: {}
# optional init containers
initContainers: []
# list of name, value pairs of extra environment vars
extraEnv: []
# - name: SOME_ENV
Expand Down Expand Up @@ -45,6 +47,8 @@ sync:
tag: "1.0.1"
# optional node selector
nodeSelector: {}
# optional init containers
initContainers: []
# registryUrl:
resources: {}
# limits:
Expand Down

0 comments on commit bc57444

Please sign in to comment.