From f1936624b3646ee48d4aa19b19d364819467b482 Mon Sep 17 00:00:00 2001 From: "v.oleynikov" Date: Sun, 15 Nov 2026 17:09:41 +0300 Subject: [PATCH] feat(controller): add args, extra ports and pod annotations to the module controller Several storage controllers are still written by hand because helm_lib_module_controller_manifests has no place for three things they need, and so they miss the two-replica rule on masters and the in-process metrics authorization: - the state-snapshotter controller starts its aggregated API server with --api-addr and --api-tls-* arguments; - the storage-foundation and state-snapshotter controllers serve that API on a named "https" port that their Service and APIService target; - the storage-foundation controller rolls its pods when the aggregation API CA changes, through a checksum annotation on the pod template. Add controllerArgs (container args), additionalControllerPorts (rendered after the metrics port) and additionalPodAnnotations (merged with checksum/ca when webhooks are enabled). None is set by default, and modules that do not set them render as before. Signed-off-by: v.oleynikov --- charts/helm_lib/Chart.yaml | 2 +- .../helm_lib/templates/_module_controller.tpl | 40 ++- ..._lib_module_controller_manifests_test.yaml | 268 ++++++++++++++++++ 3 files changed, 300 insertions(+), 10 deletions(-) diff --git a/charts/helm_lib/Chart.yaml b/charts/helm_lib/Chart.yaml index 4943578..e87c9a2 100644 --- a/charts/helm_lib/Chart.yaml +++ b/charts/helm_lib/Chart.yaml @@ -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." diff --git a/charts/helm_lib/templates/_module_controller.tpl b/charts/helm_lib/templates/_module_controller.tpl index 8f20ddf..318e634 100644 --- a/charts/helm_lib/templates/_module_controller.tpl +++ b/charts/helm_lib/templates/_module_controller.tpl @@ -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") @@ -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" }} @@ -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 }} @@ -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 @@ -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: diff --git a/tests/tests/helm_lib_module_controller_manifests_test.yaml b/tests/tests/helm_lib_module_controller_manifests_test.yaml index 6394a40..2137b1b 100644 --- a/tests/tests/helm_lib_module_controller_manifests_test.yaml +++ b/tests/tests/helm_lib_module_controller_manifests_test.yaml @@ -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