Skip to content

Commit 45510df

Browse files
committed
docs: document kubernetes provider identity tracking bug and state fix
1 parent 01cf767 commit 45510df

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ All templates use a shared Terraform module at `modules/kubernetes-workspace/`.
3434

3535
```terraform
3636
module "workspace" {
37-
source = "git::https://github.com/codespacesh/templates.git//modules/kubernetes-workspace?ref=v1.0.4"
37+
source = "git::https://github.com/codespacesh/templates.git//modules/kubernetes-workspace?ref=v1.1.4"
3838
}
3939
```
4040

@@ -219,6 +219,50 @@ coder ssh admin/<workspace> -- 'for p in $(ls /proc/ | grep "^[0-9]*$"); do fd=$
219219
```
220220
See Coder docs on [wildcard access URL](https://coder.com/docs/admin/setup#wildcard-access-url) for setup with your DNS/ingress.
221221

222+
### Kubernetes Provider Identity Tracking Bug
223+
224+
The `hashicorp/kubernetes` provider v2.37.0+ has a bug where `ResourceIdentity` values are written as all-nulls to Terraform state when pod creation is slow. On the next plan/apply, the provider reads actual values, detects a mismatch, and errors with `Unexpected Identity Change`.
225+
226+
**Affected versions:**
227+
- v2.37.0: identity tracking on `kubernetes_config_map_v1`
228+
- v2.38.0: identity tracking on ALL SDKv2 resources (including `kubernetes_pod_v1`) + added `sub_path_expr`
229+
- v3.0.x: also affected (GitHub #2779)
230+
231+
**Why we can't downgrade:** v2.38.0 added `sub_path_expr` to the schema. Any workspace state written by v2.38.0 contains this attribute and can't be decoded by older versions. The templates stay on `~> 2.37` (resolves to v2.38.0).
232+
233+
**Fix for stuck workspaces:**
234+
```bash
235+
# 1. Pull the workspace state
236+
coder state pull admin/<workspace> /tmp/workspace.tfstate
237+
238+
# 2. Fix the null identity values
239+
python3 << 'EOF'
240+
import json
241+
with open('/tmp/workspace.tfstate') as f:
242+
state = json.load(f)
243+
for r in state.get('resources', []):
244+
if r.get('type') == 'kubernetes_pod_v1':
245+
for inst in r.get('instances', []):
246+
identity = inst.get('identity')
247+
if identity and all(v is None for v in identity.values()):
248+
meta = inst['attributes']['metadata'][0]
249+
inst['identity'] = {
250+
'api_version': 'v1',
251+
'kind': 'Pod',
252+
'name': meta['name'],
253+
'namespace': meta['namespace'],
254+
}
255+
print(f"Fixed: {meta['name']}")
256+
with open('/tmp/workspace-fixed.tfstate', 'w') as f:
257+
json.dump(state, f, indent=2)
258+
EOF
259+
260+
# 3. Push fixed state (--no-build skips terraform validation)
261+
coder state push --no-build admin/<workspace> /tmp/workspace-fixed.tfstate
262+
263+
# 4. Workspace can now be stopped/started/deleted normally
264+
```
265+
222266
## GitHub Actions
223267

224268
The `build-images.yaml` workflow:

0 commit comments

Comments
 (0)