-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubectl-switch_config
executable file
·58 lines (51 loc) · 1.76 KB
/
kubectl-switch_config
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
#!/usr/bin/env sh
#kubectl-switch-config - plugin for kubectl to easy switch between configuration files, using symbolic links
#Author: Radoslaw Warowny
#License: GPL (General Public License) version 3
getopts hl opt
if [ "$opt" = "h" ]; then
echo Usage:
echo "\t kubectl switch-config [-h] [-l] | [<name>]"
echo
echo 'Notice: You shoud have created configuration file in your $HOME/.kube directory named: config-name before first use.'
echo
echo 'Options:'
echo ' -h show (this) help'
echo ' -l list available configuration names possible for switching'
echo
echo 'Invoking with no arguments shows current (lately selected) configuration'
exit
fi
if [ "$opt" = "l" ]; then
cd ~/.kube && ls -1 config-* | sed 's/^config-//'
exit
fi
config=$1
if [ "$config" = "" ]; then
if [ -h $HOME/.kube/config ]; then
ls -l $HOME/.kube/config | sed 's/.*config-//'
else
if [ -f $HOME/.kube/config ]; then
echo "ERROR: Configuration file \$HOME/.kube/config exists but it's not symbolic link"
echo "Notice: If it's your first time, backup or move your current $HOME/.kube/config file"
echo "to $HOME/.kube/config-somename. Than you can use it by: kubectl switch-config somename"
else
echo "ERROR: \$HOME/.kube/config symbolic link desn't exit."
echo "Notice: If it's your first time, create \$HOME/.kube/config-somename file and invoke:"
echo "kubectl switch-config somename"
fi
exit 1
fi
exit
fi
file=config-$config
if ! cd $HOME/.kube; then
echo "ERROR: Directory $HOME/.kube is not accessable"
fi
if [ -f $file ]; then
cd $HOME/.kube
ln -sf config-$config config
else
echo "ERROR: Configuration file $file doesn't exist in your \$HOME/.kube directory. Configuration has NOT been switched."
exit 1
fi