Skip to content
Draft
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
10 changes: 9 additions & 1 deletion gotty/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,22 @@ func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) e
arg := ""

podname := params.Get("podname")
deployname := params.Get("deployname")
namespace := params.Get("namespace")

if len(params.Get("token")) > 0 {
ttyParameter := server.cache.Get(params.Get("token"))
cachedKey := params.Get("token")
if ttyParameter != nil {
windowTitle = ttyParameter.Title
arg = ttyParameter.Arg + " " + podname + " " + namespace
// If podname is not empty, use it in args
if len(podname) > 0 {
arg = ttyParameter.Arg + " " + podname + " " + namespace
} else if len(deployname) > 0 {
arg = ttyParameter.Arg + " " + deployname + " " + namespace + " " + "true"
} else {
panic("podname or deployname must be provided")
}
server.cache.Delete(cachedKey)
} else {
arg = "ERROR:Invalid Token"
Expand Down
24 changes: 14 additions & 10 deletions init-kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ if [ "${WELCOME_BANNER}" ]; then
echo ${WELCOME_BANNER}
fi

arg1=$1
arg2=$2
arg3=$3
KUBECONFIG_INPUT=$1
OBJECT_NAME=$2 # eg: pod name or deployment name
OBJECT_NAMESPACE=$3 # eg: mentored
USE_DEPLOY_NAME=$4 # eg: true or false

mkdir -p /nonexistent
mount -t tmpfs -o size=${SESSION_STORAGE_SIZE} tmpfs /nonexistent
Expand All @@ -20,7 +21,7 @@ mkdir -p .kube

export HOME=/nonexistent

echo $arg1| base64 -d > .kube/config
echo $KUBECONFIG_INPUT| base64 -d > .kube/config

if [ ${KUBECTL_INSECURE_SKIP_TLS_VERIFY} == "true" ];then
{
Expand Down Expand Up @@ -53,15 +54,18 @@ done
unset WELCOME_BANNER PPROF_ENABLED KUBECTL_INSECURE_SKIP_TLS_VERIFY SESSION_STORAGE_SIZE KUBECTL_VERSION


# Check arg3 and define it with a default value if is empty
if [ -z "${arg3}" ]; then
arg3="mentored"
# Check OBJECT_NAMESPACE and define it with a default value if is empty
if [ -z "${OBJECT_NAMESPACE}" ]; then
OBJECT_NAMESPACE="mentored"
fi
# Run

# if arg3 is not empty
if [ -z "${arg2}" ]; then
# if OBJECT_NAMESPACE is not empty
if [ -z "${OBJECT_NAME}" ]; then
exec su -s /bin/bash nobody
elif [ "${USE_DEPLOY_NAME}" == "true" ]; then
# If USE_DEPLOY_NAME is true, then use OBJECT_NAME as the deployment name
kubectl exec -n $OBJECT_NAMESPACE -it --tty deploy/$OBJECT_NAME -- /bin/bash
else
kubectl exec -n $arg3 -it --tty $arg2 -- /bin/bash
kubectl exec -n $OBJECT_NAMESPACE -it --tty $OBJECT_NAME -- /bin/bash
fi