-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathkubeconfig-loader
executable file
·61 lines (52 loc) · 1.26 KB
/
kubeconfig-loader
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
#!/bin/bash
KUBECONFIGS=~/.kube-configs/
KUBECONFIG=~/.kube/config
if [ ! -d $KUBECONFIGS ]; then
mkdir $KUBECONFIGS;
fi
if [ $# -lt 1 ]; then
echo "Usage: kubeconfig-loader [ls | use | add | rm] <config-name> [<config-content>]"
exit 1
fi
CMD=$1
CONFIG_NAME=$2
case $CMD in
"ls")
ls -1 $KUBECONFIGS
;;
"use")
if [ ! $# -eq 2 ]; then
echo "Usage: kubeconfig-loader use <config-name>"
exit 1
fi
if [ ! -f $KUBECONFIGS$CONFIG_NAME ]; then
echo "no config found with name '$CONFIG_NAME'"
exit 1
fi
cp $KUBECONFIGS$CONFIG_NAME $KUBECONFIG
;;
"add")
if [ $# != 3 ]; then
echo "usage: kubeconfig-loader add <config-name> <config-loader>"
exit 1
fi
CONFIG_FILE=$3
cat $CONFIG_FILE > "$KUBECONFIGS$CONFIG_NAME"
echo "added $CONFIG_NAME"
;;
"rm")
if [ ! $# -eq 2 ]; then
echo "Usage: kubeconfig-loader rm <config-name>"
exit 1
fi
if [ ! -f $KUBECONFIGS$CONFIG_NAME ]; then
echo "no config found with name '$CONFIG_NAME'"
exit 1
fi
rm $KUBECONFIGS$CONFIG_NAME
;;
*)
echo "unknown command $CMD"
exit 1
;;
esac