Skip to content

Commit

Permalink
Merge pull request #87 from kyma-project/add/genkubeconfig-script
Browse files Browse the repository at this point in the history
add scripts to generate serviceaccount based kubeconfig
  • Loading branch information
szeort authored Oct 21, 2024
2 parents 89749f9 + 23c5950 commit 56fc239
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tools/kubeconfig/genkubeconfig.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$PWD = (Get-Item .).FullName
$SCRIPTDIR = $PSScriptRoot

kubectl apply -f $SCRIPTDIR/serviceaccount.yaml
kubectl wait --for=jsonpath='{.data.token}' secret/admin-serviceaccount
$SA_TOKEN=$(kubectl get secret admin-serviceaccount -o=go-template='{{.data.token | base64decode}}')
cp ~/.kube/config kubeconfig-sa.yaml
docker run -v ${PWD}:/workdir -ti mikefarah/yq -i ".users |= [{\`"name\`":\`"admin-serviceaccount\`", \`"user\`": {\`"token\`":\`"${SA_TOKEN}\`"}}]" kubeconfig-sa.yaml
docker run -v ${PWD}:/workdir -ti mikefarah/yq -i ".contexts[0].context.user |= \`"admin-serviceaccount\`"" kubeconfig-sa.yaml
13 changes: 13 additions & 0 deletions tools/kubeconfig/genkubeconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -eo pipefail
set -o xtrace

SCRIPTDIR=$(dirname "$0")

kubectl apply -f $SCRIPTDIR/serviceaccount.yaml
kubectl wait --for=jsonpath='{.data.token}' secret/admin-serviceaccount
$SA_TOKEN=$(kubectl get secret admin-serviceaccount -o=go-template='{{.data.token | base64decode}}')
cp ~/.kube/config kubeconfig-sa.yaml
docker run -v ${PWD}:/workdir -ti mikefarah/yq -i ".users |= [{\"name\":\"admin-serviceaccount\", \"user\": {\"token\":\"${SA_TOKEN}\"}}]" kubeconfig-sa.yaml
docker run -v ${PWD}:/workdir -ti mikefarah/yq -i ".contexts[0].context.user |= \"admin-serviceaccount\"" kubeconfig-sa.yaml

0 comments on commit 56fc239

Please sign in to comment.