2 ###########################################################################
3 # Copyright (c) 2019 AT&T Intellectual Property.
4 # Copyright (c) 2019 Nokia.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 ##########################################################################
19 # generate a kubconfig (at ${KUBECONFIG} file from the automatically-mounted
20 # service account token.
22 # SVCACCT_NAME: the name of the service account user. default "default"
23 # CLUSTER_NAME: the name of the kubernetes cluster. default "kubernetes"
24 # KUBECONFIG: where the generated file will be deposited.
25 SVCACCT_TOKEN=`cat /var/run/secrets/kubernetes.io/serviceaccount/token`
26 CLUSTER_CA=`base64 /var/run/secrets/kubernetes.io/serviceaccount/ca.crt|tr -d '\n'`
28 cat >${KUBECONFIG} <<__EOF__
32 - name: ${SVCACCT_NAME:-default}
34 token: ${SVCACCT_TOKEN}
37 certificate-authority-data: ${CLUSTER_CA}
38 server: ${K8S_API_HOST:-https://kubernetes.default.svc.cluster.local/}
39 name: ${CLUSTER_NAME:-kubernetes}
42 cluster: ${CLUSTER_NAME:-kubernetes}
43 user: ${SVCACCT_NAME:-default}
44 name: svcs-acct-context
45 current-context: svcs-acct-context