Migrate the home PVC to kubernetes_persistent_volume_claim_v1 without recreating it #6
No reviewers
Labels
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
GuillaumeHemmen-k8s/coder-sindri-deployment!6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "chore/pvc-v1-migration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #5: resolves the last deprecation warning (
kubernetes_persistent_volume_claim.home) without touching any home volume. WIP until tested on a throwaway workspace.Why not a plain rename
Renaming the resource type makes Terraform destroy the old PVC and create a new one. The
longhornStorageClass hasreclaimPolicy: Delete, so that deletes the home data. Amovedblock can't help: v3.2.1'sMoveResourceStateis a no-op stub, so cross-type moves are unsupported.How it works (step 1 of 2)
On each workspace's next build (start or stop, since the PVC isn't count-gated):
removed { lifecycle { destroy = false } }drops the old address from state without deleting the PVC;importadopts the same PVC underkubernetes_persistent_volume_claim_v1.home.The import is gated on a
kubernetes_resourceslookup of the PVC, so brand-new workspaces (no PVC yet) and the template-push dry-run just create it normally. Once_v1is in state, Terraform treats the import as a no-op.Tested (plan only, never applied)
Terraform 1.14.5 + kubernetes v3.2.1, planned against the real cluster with a local state and real parameter values:
forget;_v1: import + in-place update (wait_until_boundonly), same UID46f76366…, 100Gi_v1:create, no import_v1already in state)_v1: update, no importThe deprecation warning is gone from
terraform validate.Still to do: a real build on a throwaway workspace (file in
~must survive, PVC UID must be unchanged).Step 2 (separate PR, later)
Once every workspace has had one build on this version (check that the resource type in each workspace's latest build is
_v1), delete the data source and theimportblock. Keep theremovedblock: if a straggler still had the old address in state andremovedwere gone too, Terraform would plan to destroy its PVC. Withremovedkept, the worst case is a harmless "already exists" error on create.🤖 Generated with Claude Code
Template push of
af361c5failed at "Detecting persistent resources":kubernetes_resourcesis a manifest-family data source: it lists CRDs cluster-wide even for built-in kinds. My earlier dry-run used a kubeconfig with broader rights than the coder SA, so it didn't catch this. Nothing was applied; the test workspace's PVC is untouched.Fix (
16db2af): the existence check now uses the typedkubernetes_persistent_volume_claim_v1data source, a plainGET(kubectl auth can-i get pvc -n coder --as=system:serviceaccount:coder:coder→ yes) that returns empty on NotFound (data_source_kubernetes_persistent_volume_claim_v1.go:111). The import is gated on the PVC having a UID. No RBAC change.Re-planned all three scenarios, using the
red-reindeer-86test workspace (PVC UID83d83509…) as the existing one: old addressforget+ same UID imported / brand-new workspacecreatewithout import / already migrated: no import. 0 to destroy in all three.Caveat: I couldn't run the plan as the SA (writing an impersonating kubeconfig was blocked), so SA coverage is proven by
can-ion the exact calls (GET pvc), not by a full plan as the SA. The template push itself is the real check.WIP: Migrate the home PVC to kubernetes_persistent_volume_claim_v1 without recreating itto Migrate the home PVC to kubernetes_persistent_volume_claim_v1 without recreating it