8000 k3s, setup-secrets: Cluster secrets in a group of their own, run after k3s by andsens · Pull Request #37 · nixos-homelab/shared · GitHub
[go: up one dir, main page]

Skip to content

k3s, setup-secrets: Cluster secrets in a group of their own, run after k3s - #37

Merged
andsens merged 1 commit into
mainfrom
setup-secrets-groups
Nov 19, 2026
Merged

andsens merged 1 commit into
mainfrom
setup-secrets-groups

Conversation

@andsens
@andsens andsens commented Nov 19, 2026
Copy link
Copy Markdown
Collaborator

Needs andsens/nixos-setup-secrets#13 and #14 (setup-secrets groups as setup-secrets@<group>.service). Locked to #14's head until those merge; relock to main before merging this.

What changes

  • lib.setup-secrets gets helpers next to mkScript:
    • kubeSecretSource: reads one field of a Secret. With generate, a missing Secret or field makes a new value; an API that doesn't answer still fails the source, so a value is never replaced because k3s was down. (The old getKubeSecret … || wg genkey in client-vpn generated a new key on any failure.)
    • kubeExecSource: kubectl rollout status first, then kubectl exec, for API keys a workload writes itself.
    • kubeSecretDestination: one Secret from data (field → source); clusterDestination: a script of its own.
    • Destinations from these are in the group cluster; everything gets timeout = 60s and retries = 5 (exec sources 150 s, 2 retries).
  • The k3s module declares setup-secrets.groups.cluster and adds wantedBy/partOf/after = k3s.service to setup-secrets@cluster, in place of systemd.services."setup-secrets".after. The cluster secrets are stored after every start of k3s, so a deploy that restarts k3s stores them again once it's back.

Test: checks.k3s gets a subtest (last, since restarting k3s makes it re-apply its own manifests, which the takeover subtest races with): a Secret generated through the helpers appears after boot, a restart of k3s re-runs the group, and the value stays the same. Passes locally (167 s), together with deadnix, manifests, logs and logql.

The module repos move their cluster sources and destinations to these helpers in their own PRs (same branch name).

🤖 Generated with Claude Code

…r k3s

lib.setup-secrets gets helpers for cluster sources and destinations: kubeSecretSource (with an optional generator for a missing Secret or field), kubeExecSource (waits for the rollout first), kubeSecretDestination and clusterDestination. The destinations are in the setup-secrets group cluster and retry while k3s and the workloads come up.

The k3s module declares that group and wires its unit to k3s (wanted by, part of and after k3s.service), in place of ordering the old setup-secrets.service after k3s. A deploy that restarts k3s now stores the cluster secrets again once it is back. The k3s VM test covers it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andsens
andsens force-pushed the setup-secrets-groups branch from 5e92349 to 27e1329 Compare November 19, 2026 20:46
@andsens
andsens enabled auto-merge (squash) November 19, 2026 20:46
@andsens
andsens merged commit fe16d60 into main Nov 19, 2026
3 checks passed
@andsens
andsens deleted the setup-secrets-groups branch November 19, 2026 20:53
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

0