zdt-argocd/sa2kubeconfig.sh

30 lines
600 B
Bash
Raw Normal View History

2024-05-19 21:06:39 +00:00
#!/bin/sh -e
2024-05-20 11:30:43 +00:00
KUBECONFIG=$1
SA_NAME=argo-argocd-repo-server
CA64=$(cat /run/secrets/kubernetes.io/serviceaccount/ca.crt | base64 -w0)
TOKEN=$(cat /run/secrets/kubernetes.io/serviceaccount/token)
2024-05-20 11:30:43 +00:00
cat > $KUBECONFIG << EOF
apiVersion: v1
kind: Config
clusters:
- name: local
cluster:
server: https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT_HTTPS
certificate-authority-data: $CA64
users:
- name: $SA_NAME
user:
token: "$TOKEN"
contexts:
- name: ${SA_NAME}_context
context:
cluster: local
user: $SA_NAME
current-context: ${SA_NAME}_context
EOF
2024-05-20 11:30:43 +00:00
chmod 600 $KUBECONFIG