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

add scripts to generate serviceaccount based kubeconfig #87

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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
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