Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite kube config if set as env var #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 20 additions & 22 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,34 @@ if [ ! -d "$HOME/.kube" ]; then
mkdir -p $HOME/.kube
fi

if [ ! -f "$HOME/.kube/config" ]; then
if [ ! -z "${KUBE_CONFIG}" ]; then
if [ ! -z "${KUBE_CONFIG}" ]; then

echo "$KUBE_CONFIG" | base64 -d > $HOME/.kube/config
echo "$KUBE_CONFIG" | base64 -d > $HOME/.kube/config

if [ ! -z "${KUBE_CONTEXT}" ]; then
kubectl config use-context $KUBE_CONTEXT
fi

elif [ ! -z "${KUBE_HOST}" ]; then

echo "$KUBE_CERTIFICATE" | base64 -d > $HOME/.kube/certificate
kubectl config set-cluster default --server=https://$KUBE_HOST --certificate-authority=$HOME/.kube/certificate > /dev/null
if [ ! -z "${KUBE_CONTEXT}" ]; then
kubectl config use-context $KUBE_CONTEXT
fi

if [ ! -z "${KUBE_PASSWORD}" ]; then
kubectl config set-credentials cluster-admin --username=$KUBE_USERNAME --password=$KUBE_PASSWORD > /dev/null
elif [ ! -z "${KUBE_TOKEN}" ]; then
kubectl config set-credentials cluster-admin --token="${KUBE_TOKEN}" > /dev/null
else
echo "No credentials found. Please provide KUBE_TOKEN, or KUBE_USERNAME and KUBE_PASSWORD. Exiting..."
exit 1
fi
elif [ ! -z "${KUBE_HOST}" ]; then

kubectl config set-context default --cluster=default --namespace=default --user=cluster-admin > /dev/null
kubectl config use-context default > /dev/null
echo "$KUBE_CERTIFICATE" | base64 -d > $HOME/.kube/certificate
kubectl config set-cluster default --server=https://$KUBE_HOST --certificate-authority=$HOME/.kube/certificate > /dev/null

if [ ! -z "${KUBE_PASSWORD}" ]; then
kubectl config set-credentials cluster-admin --username=$KUBE_USERNAME --password=$KUBE_PASSWORD > /dev/null
elif [ ! -z "${KUBE_TOKEN}" ]; then
kubectl config set-credentials cluster-admin --token="${KUBE_TOKEN}" > /dev/null
else
echo "No authorization data found. Please provide KUBE_CONFIG or KUBE_HOST variables. Exiting..."
echo "No credentials found. Please provide KUBE_TOKEN, or KUBE_USERNAME and KUBE_PASSWORD. Exiting..."
exit 1
fi

kubectl config set-context default --cluster=default --namespace=default --user=cluster-admin > /dev/null
kubectl config use-context default > /dev/null

elif [ ! -f "$HOME/.kube/config" ]; then
echo "No authorization data found. Please provide KUBE_CONFIG or KUBE_HOST variables. Exiting..."
exit 1
fi

echo "/usr/local/bin/kubectl" >> $GITHUB_PATH
Expand Down