bug-fix: kubectl not installed in Bottlenecks docker
[bottlenecks.git] / utils / k8s_setup / k8s_config_pre.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2018 Huawei Tech and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 K8S_CONFIG="/tmp/k8s_config"
11
12 usage="Script to prepare kubenetes test configurations.
13
14 usage:
15     bash $(basename "$0") [-h|--help] [-i|--installer <installer typer>] [-c|--config <k8s config>]
16
17 where:
18     -h|--help         show the help text
19     -i|--installer    specify the installer for the system to be monitored
20       <installer type>
21                       one of the following:
22                               (compass)
23 examples:
24     $(basename "$0") -i compass"
25
26
27 info () {
28     logger -s -t "BOTTLENECKS INFO" "$*"
29 }
30
31 error () {
32     logger -s -t "BOTTLENECKS ERROR" "$*"
33     exit 1
34 }
35
36 # Process input variables
37 while [[ $# > 0 ]]
38     do
39     key="$1"
40     case $key in
41         -h|--help)
42             echo "$usage"
43             exit 0
44             shift
45         ;;
46         -i|--installer)
47             INSTALLER_TYPE="$2"
48             shift
49         ;;
50         -c|--config)
51             K8S_CONFIG="$2"
52             shift
53         ;;
54         *)
55             error "unkown input options $1 $2"
56             exit 1
57         ;;
58      esac
59      shift
60 done
61
62 if [[ ${INSTALLER_TYPE} == 'compass' ]]; then
63     sshpass -p root scp -o StrictHostKeyChecking=no root@192.16.1.222:~/.kube/config ${K8S_CONFIG}
64 else
65     echo "BOTTLENECKS EROOR: unrecognized installer"
66 fi
67
68 if [[ -f ${K8S_CONFIG} ]]; then
69     if [[ -d ~/.kube ]]; then
70         cp ${K8S_CONFIG} ~/.kube/config
71         echo "BOTTLENECKS INFO: copying k8s config to ~./kube"
72     else
73         mkdir ~/.kube
74         cp ${K8S_CONFIG} ~/.kube/config
75         echo "BOTTLENECKS INFO: copying k8s config to ~./kube"
76     fi
77 else
78     echo "BOTTLENECKS ERROR: k8s config file does no exit (${K8S_CONFIG})"
79     exit 1
80 fi