Skip to content

Commit 437d76e

Browse files
solssonclaude
andcommitted
y-kubeconfig-import: set -u and guard unset reads; document current-context flip
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 08898ad commit 437d76e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

bin/y-kubeconfig-import

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/usr/bin/env bash
2-
[ -z "$DEBUG" ] || set -x
3-
set -eo pipefail
2+
[ -z "${DEBUG:-}" ] || set -x
3+
set -euo pipefail
44

5-
[ -z "$1" ] && echo "First arg should be the path to a _temporary_ kubeconfig file" && exit 1
5+
[ -z "${1:-}" ] && echo "First arg should be the path to a _temporary_ kubeconfig file" && exit 1
66

77
CONFTEMP="$1"
88

99
[ ! -f "$CONFTEMP" ] && echo "Temporary file $CONFTEMP not found. No import performed." && exit 1
1010

11-
[ -z "$KUBECONFIG" ] && echo "This script requires a KUBECONFIG env. Aborting merge." && exit 1
11+
[ -z "${KUBECONFIG:-}" ] && echo "This script requires a KUBECONFIG env. Aborting merge." && exit 1
1212

1313
if [ -f "$KUBECONFIG" ]; then
1414
echo "Target kubeconfig $KUBECONFIG already exists. Merging."
15+
# note: current-context becomes whatever CONFTEMP set, because CONFTEMP is listed
16+
# first in KUBECONFIG and --flatten preserves the merged current-context.
1517
KUBECONFIG="$CONFTEMP:$KUBECONFIG" kubectl config view --flatten > "$CONFTEMP-merged"
1618
mv "$CONFTEMP-merged" "$CONFTEMP"
1719
else

0 commit comments

Comments
 (0)