Created
January 4, 2021 20:11
-
-
Save abdennour/fee44ca16e054c85d484e4cd9efa9f78 to your computer and use it in GitHub Desktop.
login-with-service-account.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Syntax: ${0} <namespace> <service-account-name> https://openshift.example.com | |
export ns=${1} | |
export sa_name=${2} | |
export ocp_endpoint=${3} | |
cluster_name=$(oc config current-context | cut -f2 -d'/') | |
token_tmpfile=/tmp/${sa_name}-${cluster_name}.txt | |
oc -n ${ns} create sa ${sa_name} | |
sa_secret_name=$(oc -n ${ns} get sa ${sa_name} -o jsonpath='{.secrets[0].name}') | |
oc -n ${ns} get secret ${sa_secret_name} -o jsonpath='{.data.token}' |\ | |
base64 --decode > ${token_tmpfile} | |
oc login ${ocp_endpoint} --token=$(<${token_tmpfile}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment