Skip to content

Commit 5b5287e

Browse files
Merge pull request jordanwilson230#19 from jordanwilson230/allow-more-user-sessions
Stop constraining number of execs
2 parents f0e2b2c + 790c6a0 commit 5b5287e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

kubectl-ssh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ if [[ $# -gt 0 ]]; then
8484
fi
8585

8686
echo -e "\nConnecting...\nPod: ${POD}\nNamespace: ${NAMESPACE}\nUser: ${USERNAME}\nContainer: ${CONTAINER}\nCommand: $COMMAND\n"
87-
88-
# Limits concurrent sessions (each session deploys a pod) to 2. It's not necessary, just a preference.
89-
test "$(exec "${KUBECTL}" get po "$(whoami|tr -dc '[:alnum:]')-1" 2>/dev/null)" && container="$(whoami|tr -dc '[:alnum:]')-2" || container="$(whoami|tr -dc '[:alnum:]')-1"
87+
# $temp_container is the name of our temporary container which we use to connect behind the scenes. Will be cleaned up automatically.
88+
temp_container="ssh-pod-${RANDOM}"
9089

9190
# We want to mount the docker socket on the node of the pod we're exec'ing into.
9291
NODENAME=$( ${KUBECTL} get pod "${POD}" -o go-template='{{.spec.nodeName}}' )
@@ -117,7 +116,7 @@ read -r -d '' OVERRIDES <<EOF || :
117116
"containers": [
118117
{
119118
"image": "docker",
120-
"name": "'$container'",
119+
"name": "'$temp_container'",
121120
"stdin": true,
122121
"stdinOnce": true,
123122
"tty": true,
@@ -157,6 +156,6 @@ read -r -d '' OVERRIDES <<EOF || :
157156
}
158157
EOF
159158

160-
trap '$KUBECTL delete pod $container >/dev/null 2>&1 &' 0 1 2 3 15
159+
trap '$KUBECTL delete pod $temp_container >/dev/null 2>&1 &' 0 1 2 3 15
161160

162-
eval "$KUBECTL" run -it --restart=Never --image=docker --overrides="'${OVERRIDES}'" "$container"
161+
eval "$KUBECTL" run -it --restart=Never --image=docker --overrides="'${OVERRIDES}'" "$temp_container"

0 commit comments

Comments
 (0)