diff --git a/scripts/install-k8s.ps1 b/scripts/install-k8s.ps1 index 0830fc7..da7809c 100644 --- a/scripts/install-k8s.ps1 +++ b/scripts/install-k8s.ps1 @@ -1214,6 +1214,10 @@ $envBlock Log "Helm Output: $helmOutput" if ($LASTEXITCODE -ne 0) { Err "Client installation failed. Helm output:`n$helmOutput`nCheck the log for details: $LOG_FILE" } + # Point kubeconfig's current context at the client namespace so kubectl + the + # tracebloc CLI default to it (no -n / --namespace needed). Best-effort. + kubectl config set-context --current --namespace $TB_NAMESPACE 2>$null | Out-Null + Ok "Connected to tracebloc" Log "Values file: $valuesFile" } diff --git a/scripts/lib/install-client-helm.sh b/scripts/lib/install-client-helm.sh index 41e0615..c21ac6e 100644 --- a/scripts/lib/install-client-helm.sh +++ b/scripts/lib/install-client-helm.sh @@ -383,6 +383,11 @@ EOF cat "$helm_log" >> "${LOG_FILE:-/dev/null}" 2>/dev/null rm -f "$helm_log" + # Point the kubeconfig's current context at the client namespace, so kubectl and + # the tracebloc CLI default to it with no -n / --namespace flag. Best-effort: + # a failure here must not abort an otherwise-successful install. + kubectl config set-context --current --namespace "$TB_NAMESPACE" >/dev/null 2>&1 || true + success "Connected to tracebloc" log "Values file: $values_file" } diff --git a/scripts/tests/install-client-helm.bats b/scripts/tests/install-client-helm.bats index e9565bc..67c66ac 100644 --- a/scripts/tests/install-client-helm.bats +++ b/scripts/tests/install-client-helm.bats @@ -135,6 +135,19 @@ setup() { mock_calls | grep -q "helm upgrade --install tracebloc" } +@test "install_client_helm: points kubeconfig at the client namespace (so the CLI needs no -n)" { + HOST_DATA_DIR="$BATS_TEST_TMPDIR/data"; mkdir -p "$HOST_DATA_DIR" + _ensure_tracebloc_dirs() { :; } + _ensure_release_dirs() { :; } + _ensure_helm_runnable() { :; } + helm() { return 0; } + kubectl() { record "kubectl $*"; return 0; } + verify_credentials() { printf valid; } + run install_client_helm <<< $'myid\nmypw' + [ "$status" -eq 0 ] + mock_calls | grep -q "kubectl config set-context --current --namespace tracebloc" +} + @test "install_client_helm: re-prompts on invalid, then accepts valid" { HOST_DATA_DIR="$BATS_TEST_TMPDIR/data"; mkdir -p "$HOST_DATA_DIR" _ensure_tracebloc_dirs() { :; }