Skip to content

Commit 080b48c

Browse files
fix: remove stale context/cluster/user from kubeconfig to prevent x509/Unauthorized errors
1 parent 4fa7eb7 commit 080b48c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

scripts/get-kubeconfig.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ chmod 600 "${TMP_KUBECONFIG}"
5353
# Merge into existing kubeconfig (or create it if it doesn't exist)
5454
if [[ -f "${TARGET}" ]]; then
5555
log_info "Merging into existing ${TARGET}..."
56+
# Remove stale context/cluster/user first so the new credentials always win
57+
# (re-installs generate a new CA — old creds cause x509/Unauthorized errors)
58+
kubectl config --kubeconfig="${TARGET}" delete-context "${CONTEXT_NAME}" 2>/dev/null || true
59+
kubectl config --kubeconfig="${TARGET}" delete-cluster "${CONTEXT_NAME}" 2>/dev/null || true
60+
kubectl config --kubeconfig="${TARGET}" delete-user "${CONTEXT_NAME}" 2>/dev/null || true
5661
KUBECONFIG="${TARGET}:${TMP_KUBECONFIG}" kubectl config view --flatten > "${TARGET}.merged"
5762
mv "${TARGET}.merged" "${TARGET}"
5863
else

0 commit comments

Comments
 (0)