summaryrefslogtreecommitdiffstats
path: root/utils/k8s_setup/k8s_config_pre.sh
blob: f57add782bb1971ccdbc34e4b4cf38463377dc9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
##############################################################################
# Copyright (c) 2018 Huawei Tech and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
K8S_CONFIG="/tmp/k8s_config"

usage="Script to prepare kubenetes test configurations.

usage:
    bash $(basename "$0") [-h|--help] [-i|--installer <installer typer>] [-c|--config <k8s config>]

where:
    -h|--help         show the help text
    -i|--installer    specify the installer for the system to be monitored
      <installer type>
                      one of the following:
                              (compass)
examples:
    $(basename "$0") -i compass"


info () {
    logger -s -t "BOTTLENECKS INFO" "$*"
}

error () {
    logger -s -t "BOTTLENECKS ERROR" "$*"
    exit 1
}

# Process input variables
while [[ $# > 0 ]]
    do
    key="$1"
    case $key in
        -h|--help)
            echo "$usage"
            exit 0
            shift
        ;;
        -i|--installer)
            INSTALLER_TYPE="$2"
            shift
        ;;
        -c|--config)
            K8S_CONFIG="$2"
            shift
        ;;
        *)
            error "unkown input options $1 $2"
            exit 1
        ;;
     esac
     shift
done

if [[ ${INSTALLER_TYPE} == 'compass' ]]; then
    sshpass -p root scp -o StrictHostKeyChecking=no root@10.1.0.50:~/.kube/config ${K8S_CONFIG}
else
    echo "BOTTLENECKS EROOR: unrecognized installer"
fi

if [[ -f ${K8S_CONFIG} ]]; then
    if [[ -d ~/.kube ]]; then
        cp ${K8S_CONFIG} ~/.kube/config
        echo "BOTTLENECKS INFO: copying k8s config to ~./kube"
    else
        mkdir ~/.kube
        cp ${K8S_CONFIG} ~/.kube/config
        echo "BOTTLENECKS INFO: copying k8s config to ~./kube"
    fi
else
    echo "BOTTLENECKS ERROR: k8s config file does no exit (${K8S_CONFIG})"
    exit 1
fi