Created
July 30, 2021 20:58
-
-
Save todd-dsm/74d423689fcfc66a2b9082be3622b9b1 to your computer and use it in GitHub Desktop.
retrieves service account details from kubernetes for the GitLab pipeline
This file contains 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
#!/usr/bin/env bash | |
#set -x | |
###---------------------------------------------------------------------------- | |
### FUNCTIONS | |
###---------------------------------------------------------------------------- | |
function pMsg() { | |
theMessage="$1" | |
printf '%s\n' "$theMessage" | |
} | |
function pRpt() { | |
theMessage="$1" | |
printf '\n%s\n' "$theMessage" | |
} | |
###---------------------------------------------------------------------------- | |
### MAIN PROGRAM | |
###---------------------------------------------------------------------------- | |
# Grab api url from cluster-info | |
api_url=$(kubectl cluster-info | grep "Kubernetes master" | awk '{print $NF}') | |
# Grab cert using default token | |
default_token=$(kubectl get secrets | grep default | awk '{print $1}') | |
ca_cert=$(kubectl get secret "$default_token" -o jsonpath="{['data']['ca\.crt']}" | base64 --decode) | |
# Display the token | |
service_token=$(kubectl -n kube-system describe secret "$(kubectl \ | |
-n kube-system get secret | grep gitlab | awk '{print $1}')" | \ | |
grep token: | awk '{print $NF}') | |
pMsg "===========================" | |
pMsg """ | |
API URL: | |
$api_url | |
""" | |
pMsg """ | |
CA Certificate: | |
$ca_cert""" | |
pMsg """ | |
Token: | |
$service_token | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment