Skip to content

feat(helm): add extraVolumes, extraVolumeMounts, extraContainers and extraInitContainers - #2173

Open
khrisrichardson wants to merge 1 commit into
Altinity:0.28.0from
khrisrichardson:helm-extra-pod-spec
Open

khrisrichardson wants to merge 1 commit into
Altinity:0.28.0from
khrisrichardson:helm-extra-pod-spec

Conversation

@khrisrichardson

Copy link
Copy Markdown

Thanks for taking the time to contribute to clickhouse-operator!

Please, read carefully instructions on how to make a Pull Request.

This will help a lot for maintainers to adopt your Pull Request.

Important items to consider before making a Pull Request

Please check items PR complies to:

  • All commits in the PR are squashed. More info
  • The PR is made into dedicated next-release branch, not into master branch1. More info
  • The PR is signed. More info

--

1 If you feel your PR does not affect any Go-code or any testable functionality (for example, PR contains docs only or supplementary materials), PR can be made into master branch, but it has to be confirmed by project's maintainer.

What

Step 1 of the order proposed in #2171: the chart can add volumes, mounts and containers to the operator pod, so the client certificate from #2171 (clickhouse.access.clientCertFile / clientKeyFile) can be provided from the chart, without patching the Deployment. It can come from a Secret, or be written and rotated by a sidecar.

  • extraVolumes: added to the pod's volumes.
  • operator.extraVolumeMounts: added to the clickhouse-operator container.
  • metrics.extraVolumeMounts: added to the metrics-exporter container. It reads its own copy of the operator configuration, so the same files have to be mounted there too.
  • extraContainers: appended after the chart's containers, and not gated by metrics.enabled.
  • extraInitContainers: rendered as initContainers. One with restartPolicy: Always is a native sidecar: it starts before the operator and keeps running. Native sidecars are GA in Kubernetes 1.33 (beta, on by default, since 1.29).

All five default to [] and render nothing, so existing installs are unchanged.

How

The Deployment template is generated, so the change is in dev/generate_helm_chart.sh, using the same yq + perl pattern as operator.env and the probes. The generated template, values.yaml, values.schema.json and the README (helm-docs) are regenerated from it, and only those files changed.

Tests

New "extra volumes" and "extra containers" checks in dev/test_helm_chart.sh. They are structural: yq over the rendered Deployment.

  • Nothing extra is rendered by default: no initContainers, only the chart's two containers.
  • With the values set:
    • the volume is in the pod, mounted in the operator and in the metrics-exporter, and the chart's own volumes are kept;
    • extra containers come after the chart's;
    • the init container renders with restartPolicy: Always.
  • With metrics.enabled=false, the volume, the operator mount and the extra containers are still rendered.

dev/test_helm_chart.sh passes 35/35, including the README drift check. Against the unchanged chart, the 7 checks that need the new values fail, as expected. helm lint passes with default values and with every new value set.

Example 1, a client certificate from a Secret:

extraVolumes:
  - name: client-tls
    secret:
      secretName: clickhouse-operator-client-tls
operator:
  extraVolumeMounts:
    - name: client-tls
      mountPath: /etc/clickhouse-operator-client-tls
      readOnly: true
metrics:
  extraVolumeMounts:
    - name: client-tls
      mountPath: /etc/clickhouse-operator-client-tls
      readOnly: true

Example 2, a certificate written and rotated by spiffe-helper as a native sidecar (Kubernetes 1.33+). It reads the SPIFFE Workload API socket from the SPIFFE CSI driver and writes tls.crt/tls.key into a shared in-memory volume that both operator containers mount. helper.conf comes from a ConfigMap you create, for example:

agent_address = "/spiffe-workload-api/spire-agent.sock"
cert_dir = "/etc/clickhouse-operator-client-tls"
svid_file_name = "tls.crt"
svid_key_file_name = "tls.key"
svid_bundle_file_name = "ca.crt"
daemon_mode = true
key_file_mode = 0640

spiffe-helper writes the key 0600 by default. If the helper and the operator containers run as different users, set key_file_mode as above and a shared group with podSecurityContext.fsGroup.

extraVolumes:
  - name: spiffe-workload-api
    csi:
      driver: csi.spiffe.io
      readOnly: true
  - name: client-tls
    emptyDir:
      medium: Memory
  - name: spiffe-helper-config
    configMap:
      name: clickhouse-operator-spiffe-helper
extraInitContainers:
  - name: spiffe-helper
    image: ghcr.io/spiffe/spiffe-helper:0.12.3
    restartPolicy: Always
    args: ["-config", "/etc/spiffe-helper/helper.conf"]
    volumeMounts:
      - name: spiffe-workload-api
        mountPath: /spiffe-workload-api
        readOnly: true
      - name: client-tls
        mountPath: /etc/clickhouse-operator-client-tls
      - name: spiffe-helper-config
        mountPath: /etc/spiffe-helper
        readOnly: true
operator:
  extraVolumeMounts:
    - name: client-tls
      mountPath: /etc/clickhouse-operator-client-tls
      readOnly: true
metrics:
  extraVolumeMounts:
    - name: client-tls
      mountPath: /etc/clickhouse-operator-client-tls
      readOnly: true

In both examples the operator configuration points at the mounted files: clickhouse.access.clientCertFile: /etc/clickhouse-operator-client-tls/tls.crt and clientKeyFile: /etc/clickhouse-operator-client-tls/tls.key. A sidecar that starts before its first SVID is written is covered by #2171's loader: the handshake fails until the pair is readable, then picks it up without a restart.

Disclosure: drafted with AI assistance; I reviewed the code and text before submitting.

@khrisrichardson

Copy link
Copy Markdown
Author

Could a maintainer approve the workflow runs for this PR? As a first-time contributor here, CI is waiting on approval and hasn't run yet.

…extraInitContainers

Let the chart add volumes, volume mounts and containers to the operator
pod, for example to provide the client certificate that
clickhouse.access.clientCertFile/clientKeyFile point to (Altinity#2171): from a
Secret, or written by a sidecar such as spiffe-helper. extraInitContainers
allows a native sidecar (restartPolicy: Always, Kubernetes 1.33+), which
starts before the operator. The clickhouse-operator and metrics-exporter
each read their own copy of the operator configuration, so each gets its
own mounts. All five default to empty and render nothing.

Refs Altinity#2163, Altinity#2171

Signed-off-by: Khris Richardson <khris.richardson@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant