Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/helm_lib/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
type: library
name: deckhouse_lib_helm
version: 1.72.36
version: 1.72.37
description: "Helm utils template definitions for Deckhouse modules."
40 changes: 31 additions & 9 deletions charts/helm_lib/templates/_module_controller.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ strategy:
- additionalVolumes: additional volumes to add to the pod
- additionalControllerVolumeMounts: additional volume mounts for controller
- additionalControllerEnvs: additional environment variables for controller
- controllerArgs: arguments for the controller container (default: none)
- additionalControllerPorts: additional container ports for the controller, rendered after
the metrics port (default: none)
- additionalPodAnnotations: additional annotations for the pod template, e.g. checksums of
mounted certificates (default: none)
- controllerImage: custom controller image (default: uses helm_lib_module_image)
- controllerImageName: image name for helm_lib_module_image (default: "controller")
- webhooksImageName: image name for webhooks (default: "webhooks")
Expand Down Expand Up @@ -104,6 +109,9 @@ strategy:
{{- $additionalVolumes := $config.additionalVolumes }}
{{- $additionalControllerVolumeMounts := $config.additionalControllerVolumeMounts }}
{{- $additionalControllerEnvs := $config.additionalControllerEnvs }}
{{- $controllerArgs := $config.controllerArgs }}
{{- $additionalControllerPorts := $config.additionalControllerPorts }}
{{- $additionalPodAnnotations := $config.additionalPodAnnotations }}
{{- $controllerImage := $config.controllerImage }}
{{- $controllerImageName := $config.controllerImageName | default "controller" }}
{{- $webhooksImageName := $config.webhooksImageName | default "webhooks" }}
Expand Down Expand Up @@ -193,14 +201,19 @@ spec:
app: {{ $fullname }}
template:
metadata:
{{- if $webhookEnabled }}
{{- $certPath := printf "%s.ca" $webhookCertPath }}
{{- $certValue := $moduleValues }}
{{- range $part := (split "." $certPath) }}
{{- $certValue = index $certValue $part }}
{{- end }}
{{- if or $webhookEnabled $additionalPodAnnotations }}
annotations:
{{- if $webhookEnabled }}
{{- $certPath := printf "%s.ca" $webhookCertPath }}
{{- $certValue := $moduleValues }}
{{- range $part := (split "." $certPath) }}
{{- $certValue = index $certValue $part }}
{{- end }}
checksum/ca: {{ $certValue | sha256sum | quote }}
{{- end }}
{{- if $additionalPodAnnotations }}
{{- $additionalPodAnnotations | toYaml | nindent 8 }}
{{- end }}
{{- end }}
labels:
app: {{ $fullname }}
Expand Down Expand Up @@ -231,6 +244,10 @@ spec:
image: {{ include "helm_lib_module_image" (list $context $controllerImageName) }}
{{- end }}
imagePullPolicy: IfNotPresent
{{- if $controllerArgs }}
args:
{{- $controllerArgs | toYaml | nindent 12 }}
{{- end }}
readinessProbe:
httpGet:
path: /readyz
Expand All @@ -246,16 +263,21 @@ spec:
scheme: HTTP
periodSeconds: 1
failureThreshold: 3
{{- if $controllerMetricsInProcessAuthorization }}
{{- $plainMetricsPort := and $controllerMetricsPort (not $controllerMetricsProxyPort) }}
{{- if or $controllerMetricsInProcessAuthorization $plainMetricsPort $additionalControllerPorts }}
ports:
{{- if $controllerMetricsInProcessAuthorization }}
- name: https-metrics
containerPort: {{ $controllerMetricsProxyPort }}
protocol: TCP
{{- else if and $controllerMetricsPort (not $controllerMetricsProxyPort) }}
ports:
{{- else if $plainMetricsPort }}
- name: metrics
containerPort: {{ $controllerMetricsPort }}
protocol: TCP
{{- end }}
{{- if $additionalControllerPorts }}
{{- $additionalControllerPorts | toYaml | nindent 12 }}
{{- end }}
{{- end }}
resources:
requests:
Expand Down
268 changes: 268 additions & 0 deletions tests/tests/helm_lib_module_controller_manifests_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,271 @@ tests:
name: METRICS_BIND_ADDRESS
value: "127.0.0.1:8080"
documentIndex: 1

- it: passes controllerArgs to the controller container
set:
global:
enabledModules: []
modules:
placement: {}
modulesImages:
registry:
base: "deckhouse.io/deckhouse/ce"
digests:
testModule:
controller: sha256:abc123
webhooks: sha256:def456
common:
kubeRbacProxy: sha256:krp789
discovery:
d8SpecificNodeCountByRole:
master: 3
testModule:
logLevel: INFO
internal:
customWebhookCert:
ca: test-ca-cert
crt: test-crt
key: test-key
_testvalues:
valuesKey: testModule
onMasterNode: false
webhookEnabled: false
controllerArgs:
- --api-addr=:8443
- --api-tls-cert=/etc/tls/tls.crt
asserts:
- equal:
path: spec.template.spec.containers[0].args
value:
- --api-addr=:8443
- --api-tls-cert=/etc/tls/tls.crt
documentSelector:
path: kind
value: Deployment

- it: renders no args when controllerArgs is not set
set:
global:
enabledModules: []
modules:
placement: {}
modulesImages:
registry:
base: "deckhouse.io/deckhouse/ce"
digests:
testModule:
controller: sha256:abc123
webhooks: sha256:def456
common:
kubeRbacProxy: sha256:krp789
discovery:
d8SpecificNodeCountByRole:
master: 3
testModule:
logLevel: INFO
internal:
customWebhookCert:
ca: test-ca-cert
crt: test-crt
key: test-key
_testvalues:
valuesKey: testModule
onMasterNode: false
webhookEnabled: false
asserts:
- notExists:
path: spec.template.spec.containers[0].args
documentSelector:
path: kind
value: Deployment
- notExists:
path: spec.template.metadata.annotations
documentSelector:
path: kind
value: Deployment
- notExists:
path: spec.template.spec.containers[0].ports
documentSelector:
path: kind
value: Deployment

- it: adds additionalControllerPorts after the in-process metrics port
set:
global:
enabledModules: []
modules:
placement: {}
modulesImages:
registry:
base: "deckhouse.io/deckhouse/ce"
digests:
testModule:
controller: sha256:abc123
webhooks: sha256:def456
common:
kubeRbacProxy: sha256:krp789
discovery:
d8SpecificNodeCountByRole:
master: 3
testModule:
logLevel: INFO
internal:
customWebhookCert:
ca: test-ca-cert
crt: test-crt
key: test-key
_testvalues:
valuesKey: testModule
onMasterNode: false
webhookEnabled: false
controllerMetricsPort: 8080
controllerMetricsProxyPort: 4207
controllerMetricsInProcessAuthorization: true
additionalControllerPorts:
- name: https
containerPort: 8443
protocol: TCP
asserts:
- equal:
path: spec.template.spec.containers[0].ports
value:
- name: https-metrics
containerPort: 4207
protocol: TCP
- name: https
containerPort: 8443
protocol: TCP
documentSelector:
path: kind
value: Deployment

- it: renders additionalControllerPorts without a metrics port
set:
global:
enabledModules: []
modules:
placement: {}
modulesImages:
registry:
base: "deckhouse.io/deckhouse/ce"
digests:
testModule:
controller: sha256:abc123
webhooks: sha256:def456
common:
kubeRbacProxy: sha256:krp789
discovery:
d8SpecificNodeCountByRole:
master: 3
testModule:
logLevel: INFO
internal:
customWebhookCert:
ca: test-ca-cert
crt: test-crt
key: test-key
_testvalues:
valuesKey: testModule
onMasterNode: false
webhookEnabled: false
additionalControllerPorts:
- name: https
containerPort: 8443
protocol: TCP
asserts:
- equal:
path: spec.template.spec.containers[0].ports
value:
- name: https
containerPort: 8443
protocol: TCP
documentSelector:
path: kind
value: Deployment

- it: renders additionalPodAnnotations on the pod template
set:
global:
enabledModules: []
modules:
placement: {}
modulesImages:
registry:
base: "deckhouse.io/deckhouse/ce"
digests:
testModule:
controller: sha256:abc123
webhooks: sha256:def456
common:
kubeRbacProxy: sha256:krp789
discovery:
d8SpecificNodeCountByRole:
master: 3
testModule:
logLevel: INFO
internal:
customWebhookCert:
ca: test-ca-cert
crt: test-crt
key: test-key
_testvalues:
valuesKey: testModule
onMasterNode: false
webhookEnabled: false
additionalPodAnnotations:
checksum/aggregation-api-ca: abc
asserts:
- equal:
path: spec.template.metadata.annotations
value:
checksum/aggregation-api-ca: abc
documentSelector:
path: kind
value: Deployment

- it: keeps checksum/ca next to additionalPodAnnotations when webhooks are enabled
set:
global:
enabledModules: []
modules:
placement: {}
modulesImages:
registry:
base: "deckhouse.io/deckhouse/ce"
digests:
testModule:
controller: sha256:abc123
webhooks: sha256:def456
common:
kubeRbacProxy: sha256:krp789
discovery:
d8SpecificNodeCountByRole:
master: 3
testModule:
logLevel: INFO
internal:
customWebhookCert:
ca: test-ca-cert
crt: test-crt
key: test-key
_testvalues:
valuesKey: testModule
onMasterNode: false
webhookEnabled: true
webhookCertPath: internal.customWebhookCert
additionalPodAnnotations:
checksum/aggregation-api-ca: abc
asserts:
- equal:
path: spec.template.metadata.annotations["checksum/aggregation-api-ca"]
value: abc
documentSelector:
path: kind
value: Deployment
- matchRegex:
path: spec.template.metadata.annotations["checksum/ca"]
pattern: "^[0-9a-f]{64}$"
documentSelector:
path: kind
value: Deployment
Loading