X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=ric-infra%2F25-tiller%2Fdocker%2Fbin%2Fsvcacct-to-kubeconfig.sh;fp=ric-infra%2F25-tiller%2Fdocker%2Fbin%2Fsvcacct-to-kubeconfig.sh;h=e294b617aa16e6e0ae43e0816ceb5f72f421abf4;hb=e0ab3ca89c2850f26ce7e3bbccb891d750f1491b;hp=0000000000000000000000000000000000000000;hpb=b0d610ef0ba334c963cac6e2f3423657fda803dd;p=it%2Fdep.git diff --git a/ric-infra/25-tiller/docker/bin/svcacct-to-kubeconfig.sh b/ric-infra/25-tiller/docker/bin/svcacct-to-kubeconfig.sh new file mode 100755 index 00000000..e294b617 --- /dev/null +++ b/ric-infra/25-tiller/docker/bin/svcacct-to-kubeconfig.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# Copyright (c) 2019 AT&T Intellectual Property. +# Copyright (c) 2019 Nokia. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# generate a kubconfig (at ${KUBECONFIG} file from the automatically-mounted +# service account token. +# ENVIRONMENT: +# SVCACCT_NAME: the name of the service account user. default "default" +# CLUSTER_NAME: the name of the kubernetes cluster. default "kubernetes" +# KUBECONFIG: where the generated file will be deposited. +SVCACCT_TOKEN=`cat /var/run/secrets/kubernetes.io/serviceaccount/token` +CLUSTER_CA=`base64 /var/run/secrets/kubernetes.io/serviceaccount/ca.crt|tr -d '\n'` + +cat >${KUBECONFIG} <<__EOF__ +ApiVersion: v1 +kind: Config +users: +- name: ${SVCACCT_NAME:-default} + user: + token: ${SVCACCT_TOKEN} +clusters: +- cluster: + certificate-authority-data: ${CLUSTER_CA} + server: https://kubernetes.default.svc.cluster.local/ + name: ${CLUSTER_NAME:-kubernetes} +contexts: +- context: + cluster: ${CLUSTER_NAME:-kubernetes} + user: ${SVCACCT_NAME:-default} + name: svcs-acct-context +current-context: svcs-acct-context +__EOF__