Skip to content

salt-master: Salt master cluster mode as a StatefulSet; pin Salt 3008.5 - #35

Merged
saifuddinrangwala merged 10 commits into
mainfrom
feat/master-cluster-statefulset
Nov 26, 2026
Merged

saifuddinrangwala merged 10 commits into
mainfrom
feat/master-cluster-statefulset

Conversation

@saifuddinrangwala

@saifuddinrangwala saifuddinrangwala commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Master cluster mode for the salt-master chart (agent.cluster.*), per the Salt master cluster docs. It is opt-in: agent.cluster.enabled defaults to false, which keeps the classic single or multi-master behaviour.
    • storageMode: isolated (default) uses Salt 3008's cluster_isolated_filesystem, with one PVC per pod and no shared storage. file_roots and pillar_roots changes are propagated with salt-run cluster.sync_roots.
    • storageMode: shared mounts one existing ReadWriteMany claim for the cluster pki dir, cachedir, file_roots and pillar_roots.
    • Each master keeps its own keypair, so masterKeySecretName and the keygen Job are not used, and trustedMinions writes into cluster_pki_dir.
    • The chart generates a random cluster_secret once and keeps it across upgrades, unless agent.cluster.secretName is set.
  • Deployment replaced by a StatefulSet, with the new agent.replicas (default 1). The leftover deployment.yaml and standalone job-cache-pvc.yaml are removed, and the job cache is now a volumeClaimTemplate. Classic multi-master still works and fails fast when replicas > 1 without masterKeySecretName.
  • No root, no added capabilities. Both init containers (prepare-master-keys in classic mode, prepare-cluster-dirs in cluster mode) now run with agent.containerSecurityContext as the master's own non-root user. They create their directories themselves, relying on the pod's fsGroup, and the master mounts the existing subdirectories. This is the same pattern the salt-minion chart uses. The master-key Secret is mounted 0440, and the unused agent.initContainers.fixCachePerms value is removed. A user-supplied volume (sharedStorage.existingClaim) must already be writable by uid/gid 10001.
  • Master image entrypoint renders the cluster config from SALT_CLUSTER_*.
  • Pin Salt to 3008.5 in the master and both minion Dockerfiles, chart defaults, scripts/ci.sh and the docs. Isolated-filesystem clustering needs 3008.
  • Key operator namespace fix. The bundled salt-key-operator created its Role and RoleBinding in a fixed salt-master namespace but ran in the release namespace, so a default install into any other namespace failed half-way (namespaces "salt-master" not found). watchNamespace now defaults to the release namespace, and cluster-wide watching is the explicit clusterWide: true. The master chart warns in its notes when the release namespace and namespace differ.
  • Documentation review for all charts and images. README, docs/, the three chart READMEs, both image READMEs, NOTES.txt and the CHANGELOGs were checked against the current code and rewritten where stale. Examples: wrong defaults, a master-key Secret documented with the wrong key names, a per-ordinal Service that does not exist, deployment/... commands for what are now StatefulSets, old paths, and registry instructions that a project-based registry rejects. The never-published master chart "v1.0.0" no longer claims a StatefulSet.

Release workflow, chart and script fixes

Found while reviewing the docs against the code, fixed here:

  • Kubernetes minion image was never published. Its workflow triggered on salt-minion-v*, which also matches salt-minion-vcf-v* tags, while scripts/release-docker-tags.sh pushed salt-minion-kubernetes-vX, a tag that matched no workflow, so salt-minion-kubernetes-v0.1.0 never produced an image. Image and chart tags now use the package name (salt-minion-vX.Y.Z and chart-salt-minion-vX.Y.Z): the workflow matches salt-minion-v[0-9]*, so a digit has to follow the v and a salt-minion-vcf-vX tag starts only the VCF workflow, and the release script pushes salt-minion-vX.
  • Key operator chart workflow wrote the release version into helm/salt-minion/Chart.yaml instead of its own chart.
  • Minion and key operator chart workflows pushed to oci://ghcr.io/<owner>//helm (double slash); fixed to /helm, as the master chart already had. The chart workflows also strip the tag prefix that actually triggers them.
  • Default image repositories of the minion and key operator charts pointed at ghcr.io/saltstack/salt-kubernetes/..., which does not exist. Images are published to ghcr.io/saltstack/<image> (for example salt-master:0.1.0 and salt-key-operator:0.1.0 exist there), so the defaults now point there.
  • salt-master chart: new agent.image.imagePullSecrets, and a keygen block for the key-generation Job (image, pull policy, pull secrets, and restricted security contexts). The Job image was hardcoded and the Job had no security context.
  • salt-minion chart: the key-generation Job gets the same restricted security context. Removed agent.minion.grains and agent.minion.masterId and the <release>-minion-config ConfigMap they went into: nothing mounted it, so they never had any effect. Removed the unused scripts/ copies and salt-extensions.txt from the chart, and Chart.yaml now describes a StatefulSet.
  • Dockerfiles: removed the unused SALT_GPG_KEY_URL and SALT_APT_REPO_URL build args and fixed comments that named the old chart and file paths.
  • scripts/salt-kubernetes-e2e-local-test.sh: the workloads are StatefulSets now (the minion since salt-minion: StatefulSet with a unique ID and keypair per replica #36), so deployment/... became statefulset/.... It also no longer hardcodes an environment-specific CA, package mirror or IP; those are optional environment variables (BUILD_CA, PIP_INDEX_URL, PACKAGES_ADD_HOST, PLATFORM, KUBE_CONTEXT).
  • scripts/ci.sh: fixed stale paths and re-enabled the chart template checks, including configurations the charts must reject.

The workflow changes cannot be run before merging; they were checked by reading them and by confirming the YAML parses. The new keygen security contexts were checked on a real cluster: both Jobs complete under them and create their Secrets.

What testing on a real cluster found

The first version of this PR was only linted and rendered. Running it on a real cluster (5 nodes, Longhorn storage, 3 replicas) found several problems, all fixed here:

  • Root-owned subPath directories. Kubelet creates PVC subPath directories as root, so the non-root master crashed on chmod of its pki directory. The init container now creates the directories itself, as the master's user (see above).
  • Salt rejects a cluster member with no peers (Dynamic peer discovery is not supported), so there is no single founding master. The entrypoint now waits for all peers to resolve and fails clearly if none do, and the chart requires replicas >= 2 in cluster mode.
  • interface and id must be the pod IP. Salt uses interface as the consensus node identity and matches it against cluster_peers; with the 0.0.0.0 default, Raft replies were dropped. The pod IP is now passed through the downward API.
  • keys.cache_driver: mmap_key could not read its own keys on Longhorn volumes, although it worked on a local bind mount. The chart now uses Salt's default localfs_key, with agent.cluster.keysCacheDriver to opt in to others (saltstack/salt#70951).
  • helm upgrade --reuse-values left newly added values unset; the template now falls back to the default.

With these fixes, 3 masters start, elect a leader and form a 3-voter cluster in which every pod reports the same membership. That was re-checked after the non-root change, on fresh volumes. Classic mode was also run on the cluster (1 replica, chart-generated key): the pod starts as the non-root user, listens on 4505 and 4506, and Salt 3008 keeps the supplied key (it stores it under the master id and links master.pem/master.pub to it).

Pod restarts in cluster mode, and the hostNetwork option

By default a restarted or rescheduled master cannot rejoin the cluster. A master's cluster identity is its interface, which by default is the pod IP, and Salt 3008.5 has no setting to separate identity from bind address. A pod IP changes on every restart, so the restarted pod joins as a new learner and waits for a join reply, while its old identity stays a dead voter. Each restart leaves one more dead voter, so quorum is lost after the second restart.

Salt's own recovery, cluster_auto_replace_voters, is off by default. When I turned it on, the leader flagged a healthy voter as unhealthy and demoted it instead of the dead one, which broke quorum (saltstack/salt#70952). The chart exposes autoReplaceVoters and minVoters but leaves auto-replace off.

New opt-in agent.cluster.hostNetwork makes the identity a stable node IP. The masters run on the host network, one per node (required pod anti-affinity), so a pod that comes back on the same node keeps its identity. It needs exactly agent.replicas labelled nodes selected with agent.nodeSelector, so the only node a replacement can land on is the one that was freed; the ports 4505, 4506 and poolPort must be free on them, and the namespace must allow hostNetwork pods. The entrypoint now identifies itself by POD_NAME, because under hostNetwork the container's hostname is the node's, and drops any peer that resolves to its own address. Tested on a real cluster with 3 masters on 3 nodes: after four restarts, the leader three times among them, the cluster stayed at 3 voters with no learners, leadership failed over each time, and every pod came back on its own node with the same IP. On the first start one master came up as a joiner and did not become ready (Failed to decrypt join-notify); deleting that pod fixed it. This was seen once.

Not tested with hostNetwork: a node failing or being drained so that a master has to move, trustedMinions, minions connecting through the cluster. Without hostNetwork, treat pod restarts in cluster mode as unsupported. Cluster mode stays opt-in. See the master chart README.

Testing

  • helm lint passes for all three charts, and helm template renders classic, cluster-isolated and cluster-shared, with trustedMinions on and off. The guards fire: shared without a claim, classic replicas > 1 without a key, and cluster mode with replicas < 2 all fail with clear messages.
  • helm unittest on the minion chart: 44 of 44 pass. Hadolint is clean on the three Dockerfiles. Relative links in all Markdown files resolve.
  • The entrypoint's cluster block was run in containers, including the unresolvable-peer path.
  • Installed on a real cluster: cluster mode (isolated storage, 3 replicas), the same with hostNetwork and four restarts, and classic mode (1 replica), as described above.
  • Default install and classic multi-master, run on a real cluster (this is how the key operator namespace bug was found):
    • a default install (trustedMinions on, with the key operator) came up with the release deployed; a SaltMinionKey was accepted on the master in about 50 seconds as a real file, its status showed Accepted=True, and deleting it removed the key again;
    • 3 replicas sharing one key (the keygen Job created the Secret): all three masters present the identical key, run without cluster config, one SaltMinionKey was accepted on all three masters within 20 seconds and removed from all three within 30 seconds, and the per-pod DNS names resolve.

Not tested:

  • Cluster mode with storageMode: shared.
  • Minions connecting to a master cluster, or any job dispatch through it.
  • A node failing, or a master having to move to another node.
  • The steps in docs/complete-system-test.md and the compliance guide were checked against the code, not run.

Notes

🤖 Generated with Claude Code

Saifuddin Rangwala and others added 4 commits November 25, 2026 20:55
…n Salt 3008.5

- salt-master chart: replace the Deployment with a StatefulSet and add
  agent.replicas and agent.cluster.* (cluster_id, cluster_peers,
  cluster_pki_dir, cluster_secret, cluster_pool_port). storageMode is
  "isolated" (Salt 3008 cluster_isolated_filesystem, per-pod PVCs) or
  "shared" (one ReadWriteMany claim). The chart generates and keeps a
  cluster_secret unless one is supplied.
- master image entrypoint renders the cluster config from SALT_CLUSTER_*
  and resolves peer DNS names to IPs; unresolvable peers are skipped.
- Pin Salt to 3008.5 in the master and minion Dockerfiles, chart defaults,
  CI script and docs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- prepare-cluster-dirs root init container: PVC subPath dirs are root-owned.
- entrypoint: wait for all peers and fail clearly if none resolve (Salt
  refuses a member with no peers); chart requires replicas >= 2.
- set interface and id to the pod IP: Salt uses `interface` as the cluster
  node identity.
- add agent.cluster.keysCacheDriver, autoReplaceVoters (default off) and
  minVoters; document that a restarted pod gets a new identity.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…hart

prepare-master-keys (classic) and prepare-cluster-dirs (cluster) ran as root
with CHOWN/FOWNER/DAC_OVERRIDE. They now use agent.containerSecurityContext,
mount the whole volume and create their directories as the master's own
user (the pod's fsGroup makes volumes group-writable), and the master
mounts the existing subdirectories. The master-key Secret is mounted 0440.
Removes the unused agent.initContainers.fixCachePerms value.

Verified on a real cluster: cluster mode on fresh Longhorn volumes (3
voters form) and classic mode with a chart-generated key (Salt keeps the
supplied key, storing it by master id).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Rewrote or corrected the docs against the current code (charts, Dockerfiles,
entrypoints, workflows) after the StatefulSet, non-root and cluster-mode
changes:

- README, src/README: layout, components, master modes (classic and
  cluster, with the pod-restart limitation), the minion StatefulSet model,
  testing, Salt 3008.5.
- salt-master chart and image: classic vs cluster, all agent.cluster.*
  values, storage modes, non-root init containers, entrypoint variables,
  correct defaults and Secret key names, removed per-ordinal Service and
  other features that do not exist. NOTES.txt updated.
- salt-minion chart and images: StatefulSet identity, per-pod keys, keygen
  Job behaviour, guard rails, real build args, the extension constraint.
- docs/: building, releasing, release-prep, ci-debug, helm-test (registry
  projects and private-CA trust), complete-system-test and the compliance
  guide rewritten against the real workflows and charts.
- salt-key-operator docs: renamed to salt-master, how it relates to
  trustedMinions and per-pod minion keys.
- CHANGELOGs corrected; the never-published master chart v1.0.0 text no
  longer claims a StatefulSet.
- scripts/salt-kubernetes-e2e-local-test.sh: the workloads are StatefulSets,
  not Deployments (the minion since the previous merge).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@saifuddinrangwala
saifuddinrangwala force-pushed the feat/master-cluster-statefulset branch from 1ae3f74 to d70622f Compare November 25, 2026 15:44
Saifuddin Rangwala and others added 6 commits November 25, 2026 21:25
The multi-master links targeted /en/3006/ and the master-cluster links
/en/latest/. The images and charts are pinned to Salt 3008.5, so link to
/en/3008/ (both pages exist there). Also updates the comments in the
entrypoint scripts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Release workflows
- Kubernetes minion image: trigger on salt-minion-kubernetes-v* (what
  scripts/release-docker-tags.sh pushes). The old glob salt-minion-v*
  never matched that tag, so no Kubernetes minion image was published, and
  it also matched salt-minion-vcf-v* tags.
- Key operator chart: version was injected into helm/salt-minion/Chart.yaml
  instead of its own chart.
- Minion and key operator charts: push to oci://ghcr.io/<owner>/helm, not
  //helm.
- Chart workflows: strip the tag prefix that actually triggers them.

Charts
- Default image repositories for the minion and key operator charts pointed
  at ghcr.io/saltstack/salt-kubernetes/..., which does not exist; use
  ghcr.io/saltstack/<image>, where the workflows publish.
- salt-master: add agent.image.imagePullSecrets and a keygen block (image,
  pull policy, pull secrets, restricted security contexts); the keygen image
  was hardcoded and the Job had no security context.
- salt-minion: keygen Job runs with a restricted security context; remove
  agent.minion.grains and masterId and the unmounted minion-config ConfigMap
  (no effect); remove the unused scripts/ and salt-extensions.txt; Chart.yaml
  describes a StatefulSet.

Images and scripts
- Remove the unused SALT_GPG_KEY_URL and SALT_APT_REPO_URL build args and fix
  comments that named the old chart and file paths.
- e2e script: no internal CA, mirror or IP; configurable by environment
  variables.
- scripts/ci.sh: fix stale paths and re-enable the chart template checks,
  including configurations the charts must reject.

Docs and changelogs updated to match. Checked on a real cluster: both keygen
Jobs complete under the restricted security context and create their Secrets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A master's cluster identity is its `interface`. By default that is the pod
IP, which changes on restart, so a restarted master cannot rejoin.

agent.cluster.hostNetwork runs the masters on the host network: the
identity is the node's IP and a pod that returns to the same node keeps it.
Adds hostNetwork, dnsPolicy ClusterFirstWithHostNet and a required pod
anti-affinity (one master per node); it needs exactly replicas labelled
nodes selected with agent.nodeSelector so a replacement can only land on
its own node. Rejected without cluster mode.

The entrypoint now identifies itself by POD_NAME (the hostname is the
node's under hostNetwork) and drops any peer that resolves to its own
address.

Tested on a real cluster, 3 masters on 3 nodes: after four restarts (the
leader three times among them) the cluster stayed at 3 voters with no
learners, leadership failed over and every pod returned on its own node
with the same IP. Docs, changelogs and ci.sh updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
watchNamespace defaulted to "salt-master". The operator's Role and
RoleBinding were created in that namespace, but its Deployment goes into
the release namespace, so installing the salt-master chart (which bundles
this chart) with defaults into any other namespace failed with
`namespaces "salt-master" not found` and left a half-installed release.

watchNamespace now defaults to the release namespace (empty), and
cluster-wide watching is the explicit `clusterWide: true` (it used to be
watchNamespace: ""). The salt-master chart prints a warning in its notes
when the release namespace differs from `namespace` while trusted minions
are enabled. Docs, changelog and ci.sh updated.

Found by installing the master chart with its defaults on a real cluster.
Re-tested: the default install, and a 3-replica classic multi-master install
with a shared key, both work end to end (a SaltMinionKey is accepted, and
removed again, on every master).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The Kubernetes minion image is published as salt-minion and the chart tag is
chart-salt-minion-vX, so tag the image salt-minion-vX.Y.Z, not
salt-minion-kubernetes-vX.Y.Z.

That tag prefix also matches salt-minion-vcf-v* tags, which would start the
Kubernetes workflow as well. The workflow now matches salt-minion-v[0-9]*, so
a digit has to follow the "v" and only the VCF workflow runs for a
salt-minion-vcf-vX tag. scripts/release-docker-tags.sh creates the same tag.

Docs, the minion changelog and stale comments that still named the old chart
updated. The managed_by grain value is left unchanged: it is a runtime value
that external states may target.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The entrypoints set the grain managed_by: salt-minion-kubernetes, the old
chart name. Use salt-minion, the package name, in both the Kubernetes and the
VCF image (the VCF image is run through the salt-minion chart too).

Behaviour change: any states or targeting that match the old grain value need
updating; noted in the minion image changelog. Checked by running both
entrypoints against a stub salt-minion and reading the generated config.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@saifuddinrangwala
saifuddinrangwala merged commit c80732a into main Nov 26, 2026
1 check passed
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