File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,11 @@ kubeconfig="${directory}/${namespace}/${account}"
3232mkdir -p " ${directory} /${namespace} "
3333kubectl config view --minify --raw > " ${kubeconfig} "
3434
35- # grab the service account token
36- token=$( kubectl get secret -n " ${namespace} " -o go-template='
35+ # Grab the service account token. If one has not already been generated,
36+ # create a secret to do so. See the LegacyServiceAccountTokenNoAutoGeneration
37+ # feature gate.
38+ for i in 1 2; do
39+ token=$( kubectl get secret -n " ${namespace} " -o go-template='
3740{{- range .items }}
3841 {{- if and (eq (or .type "") "kubernetes.io/service-account-token") .metadata.annotations }}
3942 {{- if (eq (or (index .metadata.annotations "kubernetes.io/service-account.name") "") "' " ${account} " ' ") }}
@@ -43,6 +46,18 @@ token=$(kubectl get secret -n "${namespace}" -o go-template='
4346 {{- end }}
4447 {{- end }}
4548{{- end }}' )
49+
50+ [[ -n " ${token} " ]] && break
51+
52+ kubectl apply -n " ${namespace} " --server-side --filename=- <<< "
53+ apiVersion: v1
54+ kind: Secret
55+ type: kubernetes.io/service-account-token
56+ metadata: {
57+ name: ${account}-token,
58+ annotations: { kubernetes.io/service-account.name: ${account} }
59+ }"
60+ done
4661kubectl config --kubeconfig=" ${kubeconfig} " set-credentials " ${account} " --token=" ${token} "
4762
4863# remove any namespace setting, replace the username, and minify once more
You can’t perform that action at this time.
0 commit comments