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.
18 # generate a kubconfig (at ${KUBECONFIG} file from the automatically-mounted
19 # service account token.
21 # SVCACCT_NAME: the name of the service account user. default "default"
22 # CLUSTER_NAME: the name of the kubernetes cluster. default "kubernetes"
23 # KUBECONFIG: where the generated file will be deposited.
24 SVCACCT_TOKEN=`cat /var/run/secrets/kubernetes.io/serviceaccount/token`
25 CLUSTER_CA=`base64 /var/run/secrets/kubernetes.io/serviceaccount/ca.crt|tr -d '\n'`
27 cat >${KUBECONFIG} <<__EOF__
31 - name: ${SVCACCT_NAME:-default}
33 token: ${SVCACCT_TOKEN}
36 certificate-authority-data: ${CLUSTER_CA}
37 server: ${CLUSTER_SERVER:-https://kubernetes.default.svc.cluster.local/}
38 name: ${CLUSTER_NAME:-kubernetes}
41 cluster: ${CLUSTER_NAME:-kubernetes}
42 user: ${SVCACCT_NAME:-default}
43 name: svcs-acct-context
44 current-context: svcs-acct-context