Fix upgrade deadlock: move authkey creation to init container#26
Merged
Conversation
…alysis Move authkey provisioning from a Helm post-install/post-upgrade Job to an init container on the client pod, eliminating race conditions and simplifying the lifecycle. Add RBAC for pods/exec needed by the init container. Add a risk analysis checklist to the DaemonSet mode README section covering subnet overlap, recovery planning, and acceptDns. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ensure-client-key.shwith dual-mode support (AUTH_FILE_PATHenv var) so the same script serves both the init container and the optional CronJobProblem
When upgrading the chart, Helm waits for all pods to become ready before running post-hooks. The client pod needs a valid authkey to become ready, but the authkey is created by the post-upgrade hook — a classic deadlock. If the existing authkey Secret has expired (e.g. old 1h default), the upgrade times out and rolls back.
Approach
Inspired by #7 by @tekulvw, which proposed moving authkey creation to an init container. This PR takes that core idea and integrates it with the existing idempotent key management script (reusing valid keys, long-lived expiry, CronJob compatibility) rather than replacing it.
Credits to @tekulvw for the init container approach in #7.
What changed
templates/create-client-secret-job.yamltemplates/client-deployment.yamlensure-authkeyinit container, replaced Secret volume with emptyDirtemplates/client-job-script-configmap.yamlAUTH_FILE_PATHdual-mode supporttemplates/client-rbac.yamlhack/kind-smoke.shChart.yamlUpgrade path
client-authkeySecret persists; init container reuses valid keyshook-delete-policyTest plan
helm lint headscale/passeshack/kind-smoke.sh --with-clientpasses (single-node, client deployment)hack/kind-smoke.sh --with-client-daemonsetpasses (multi-node, 3-node kind cluster, client daemonset)kubectl get pod -l app.kubernetes.io/component=client -o jsonpath='{.items[0].status.initContainerStatuses[?(@.name=="ensure-authkey")].state}'🤖 Generated with Claude Code