fix(cluster): write kubeconfig to real home in snap
Description
Under strict snap confinement, snapd rewrites HOME to $SNAP_USER_DATA. client-go builds the default kubeconfig path from HOME, so glab cluster agent update-kubeconfig wrote to ~/snap/glab/<rev>/.kube/config, reported Updated context ..., and left ~/.kube/config untouched. This follows the root-cause analysis in the issue triage comment.
This MR:
- Resolves the default kubeconfig against
SNAP_REAL_HOMEwhen it is set.KUBECONFIGand--kubeconfigstill take precedence, unchanged. - Adds a
kube-configplug (personal-filesinterface, write access to$HOME/.kube) tosnap/snapcraft.yaml, because thehomeplug excludes hidden files. - When running under snap and reading or writing the kubeconfig fails with
permission denied, appends a hint to runsudo snap connect glab:kube-config. Without the plug connected, the command now fails loudly instead of reporting success.
Note for maintainers: personal-files is a super-privileged interface. The Snap Store must approve it before upload, and it is not auto-connected, so users must run sudo snap connect glab:kube-config (same as the existing password-manager-service plug). Until the store approves it, the export KUBECONFIG=~/kubeconfig workaround from the issue still applies. If you'd rather ship the Go change on its own first, the snapcraft change can be split out.
Related Issues
Closes #8304 (closed)
How has this been tested?
- New command-level tests in
agent_update_kubeconfig_test.go, usingcmdtest.SetupCmdForTestand client-go mocks:- with
SNAP_REAL_HOMEset, the context goes to$SNAP_REAL_HOME/.kube/config KUBECONFIGand--kubeconfigstill win overSNAP_REAL_HOME- a read or write
permission deniedunder snap shows thesnap connecthint, and the same error outside snap does not - outside snap, the default path is still client-go's
RecommendedHomeFile
- with
go test ./internal/commands/cluster/...,golangci-lint run ./internal/commands/cluster/agent/...,go run ./scripts/comment-overlap -threshold 1.0 -max-findings 0on the changed files, andgo build ./....- The snap package itself is not built or installed in this MR. Manual check on Ubuntu after the store approves the plug:
sudo snap connect glab:kube-config, runglab cluster agent update-kubeconfig --agent <id>, then confirm the context shows up in~/.kube/config.