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}"
32
32
mkdir -p " ${directory} /${namespace} "
33
33
kubectl config view --minify --raw > " ${kubeconfig} "
34
34
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='
37
40
{{- range .items }}
38
41
{{- if and (eq (or .type "") "kubernetes.io/service-account-token") .metadata.annotations }}
39
42
{{- 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='
43
46
{{- end }}
44
47
{{- end }}
45
48
{{- 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
46
61
kubectl config --kubeconfig=" ${kubeconfig} " set-credentials " ${account} " --token=" ${token} "
47
62
48
63
# remove any namespace setting, replace the username, and minify once more
You can’t perform that action at this time.
0 commit comments