Near RT RIC Platform new-installer initial release
[ric-plt/ric-dep.git] / new-installer / helm / charts / nearrtric / appmgr / bin / _svcacct-to-kubeconfig.sh.tpl
1 #!/bin/sh
2 ###########################################################################
3 #   Copyright (c) 2019 AT&T Intellectual Property.
4 #   Copyright (c) 2019 Nokia.
5 #
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
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
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 ##########################################################################
18
19 # generate a kubconfig (at ${KUBECONFIG} file from the automatically-mounted
20 # service account token.
21 # ENVIRONMENT:
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'`
27
28 cat >${KUBECONFIG} <<__EOF__
29 ApiVersion: v1
30 kind: Config
31 users:
32 - name: ${SVCACCT_NAME:-default}
33   user:
34     token: ${SVCACCT_TOKEN}
35 clusters:
36 - cluster:
37     certificate-authority-data: ${CLUSTER_CA}
38     server: ${K8S_API_HOST:-https://kubernetes.default.svc.cluster.local/}
39   name: ${CLUSTER_NAME:-kubernetes}
40 contexts:
41 - context:
42     cluster: ${CLUSTER_NAME:-kubernetes}
43     user: ${SVCACCT_NAME:-default}
44   name: svcs-acct-context
45 current-context: svcs-acct-context
46 __EOF__