Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Use this mode to run tests against a cluster that is already running (faster ite
export TEST_CLUSTER_CREATE_MODE=alwaysUseExisting
```
2. Point SSH to the **test cluster** (the Kubernetes API master you want to run tests on):
- **Direct access:** `SSH_HOST` = IP/hostname of the cluster master, `SSH_USER` = user that can run `sudo cat /etc/kubernetes/admin.conf` on that host.
- **Direct access:** `SSH_HOST` = IP/hostname of the cluster master, `SSH_USER` = user that can read kubeconfig on that host (prefers `sudo cat /etc/kubernetes/super-admin.conf` if that file exists, otherwise `sudo cat /etc/kubernetes/admin.conf`).
- **Via jump host:** set `SSH_JUMP_HOST`, `SSH_JUMP_USER`, `SSH_JUMP_KEY_PATH` (optional); `SSH_HOST`/`SSH_USER` are the target cluster master.
3. Source the rest of your test env (e.g. `source tests/<your-test-name>/test_exports`), then run:
```bash
Expand Down
14 changes: 10 additions & 4 deletions internal/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,14 @@ func expandPath(path string) (string, error) {
return resolvedPath, nil
}

// GetKubeconfig connects to the master node via SSH, retrieves kubeconfig from /etc/kubernetes/admin.conf,
// and returns a rest.Config that can be used with Kubernetes clients, along with the path to the kubeconfig file.
// getKubeconfigRemoteShell prints kubeconfig for use with client-go. It prefers
// /etc/kubernetes/super-admin.conf (Kubernetes 1.29+ unified kubeconfig) when the file
// exists, and falls back to /etc/kubernetes/admin.conf otherwise.
const getKubeconfigRemoteShell = "sudo -n sh -c 'if [ -f /etc/kubernetes/super-admin.conf ]; then cat /etc/kubernetes/super-admin.conf; else cat /etc/kubernetes/admin.conf; fi'"

// GetKubeconfig connects to the master node via SSH, retrieves kubeconfig (preferring
// super-admin.conf over admin.conf when available), and returns a rest.Config that can
// be used with Kubernetes clients, along with the path to the kubeconfig file.
// If sshClient is provided, it will be used instead of creating a new connection.
// If sshClient is nil, a new connection will be created and closed automatically.
// If kubeconfigOutputDir is non-empty, the kubeconfig file is written there; otherwise /tmp/e2e/ is used.
Expand Down Expand Up @@ -212,8 +218,8 @@ func GetKubeconfig(ctx context.Context, masterIP, user, keyPath string, sshClien

var kubeconfigContent []byte

// Try to read kubeconfig from /etc/kubernetes/admin.conf via SSH
kubeconfigContentStr, err := sshClient.Exec(ctx, "sudo -n cat /etc/kubernetes/admin.conf")
// Read kubeconfig via SSH: prefer super-admin.conf when present (see getKubeconfigRemoteShell).
kubeconfigContentStr, err := sshClient.Exec(ctx, getKubeconfigRemoteShell)
if err != nil {
// SSH retrieval failed (likely due to sudo password requirement)
// Try to use KUBE_CONFIG_PATH if set, otherwise notify user
Expand Down
Loading