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_HOME when it is set. KUBECONFIG and --kubeconfig still take precedence, unchanged.
  • Adds a kube-config plug (personal-files interface, write access to $HOME/.kube) to snap/snapcraft.yaml, because the home plug excludes hidden files.
  • When running under snap and reading or writing the kubeconfig fails with permission denied, appends a hint to run sudo 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.

Closes #8304 (closed)

How has this been tested?

  • New command-level tests in agent_update_kubeconfig_test.go, using cmdtest.SetupCmdForTest and client-go mocks:
    • with SNAP_REAL_HOME set, the context goes to $SNAP_REAL_HOME/.kube/config
    • KUBECONFIG and --kubeconfig still win over SNAP_REAL_HOME
    • a read or write permission denied under snap shows the snap connect hint, and the same error outside snap does not
    • outside snap, the default path is still client-go's RecommendedHomeFile
  • go test ./internal/commands/cluster/..., golangci-lint run ./internal/commands/cluster/agent/..., go run ./scripts/comment-overlap -threshold 1.0 -max-findings 0 on the changed files, and go 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, run glab cluster agent update-kubeconfig --agent <id>, then confirm the context shows up in ~/.kube/config.

Merge request reports

Loading
Loading