-
Notifications
You must be signed in to change notification settings - Fork 1
/
k9s.sh
executable file
·95 lines (78 loc) · 2.34 KB
/
k9s.sh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
set -eo pipefail
source <(curl -s source https://raw.githubusercontent.com/mmontes11/k8s-scripts/main/lib.sh)
USER_HOME=$(get_user_home)
USER=$(get_username)
ARCH=$(get_architecture)
if [ -z $ARCH ]; then
echo "Architecture not supported"
exit 1
fi
log "Installing yq..."
YQ_VERSION=${YQ_VERSION:-v4.43.1}
YQ_URL=https://github.com/mikefarah/yq/releases/download/$YQ_VERSION/yq_linux_$ARCH
if ! command -v yq &> /dev/null; then
install_bin yq $YQ_URL
else
echo "yq is already installed"
fi
log "Installing k9s..."
K9S_CONFIG=${XDG_CONFIG_HOME:="$USER_HOME/.config/k9s"}
K9S_CTX=${XDG_DATA_HOME:="$USER_HOME/.local/share/k9s"}
echo "Config folder: $K9S_CONFIG"
echo -n "Contexts folder: $K9S_CTX"
function cleanup() {
if [ -d "$K9S_CONFIG" ]; then
echo "Deleting existing config at '$K9S_CONFIG'..."
rm -rf "$K9S_CONFIG"
fi
if [ -d "$K9S_CTX" ]; then
echo "Deleting existing contexts at '$K9S_CTX'..."
rm -rf "$K9S_CTX"
fi
if [ -d "k9s" ]; then
echo "Deleting existing 'k9s' folder..."
rm -rf "k9s"
fi
}
if [ "$1" == "-f" -o "$1" == "-y" ]; then
cleanup
else
read -p "Do you want to cleanup existing config at '$K9S_CONFIG' and contexts at '$K9S_CTX'? (y/n) " -n 1
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
cleanup
fi
fi
K9S_VERSION=${K9S_VERSION:-v0.32.5}
K9S_URL=https://github.com/derailed/k9s/releases/download/$K9S_VERSION/k9s_Linux_$ARCH.tar.gz
install_tar k9s $K9S_URL
mkdir -p "$K9S_CONFIG"
mkdir -p "$K9S_CONFIG/skins"
touch "$K9S_CONFIG/plugins.yaml"
mkdir -p "$K9S_CTX"
mkdir -p "$K9S_CTX/clusters"
git clone -q --no-progress https://github.com/derailed/k9s.git
git clone -q --no-progress https://github.com/mmontes11/k8s-tooling.git
cp k9s/skins/* "$K9S_CONFIG/skins"
cp k8s-tooling/.k9s/config.yaml "$K9S_CONFIG/config.yaml"
cp -r k8s-tooling/.k9s/skins/* "$K9S_CONFIG/skins"
cp -r k8s-tooling/.k9s/clusters/* "$K9S_CTX/clusters"
K9S_PLUGINS=(
# oficial
"k9s/plugins/cert-manager.yaml"
"k9s/plugins/debug-container.yaml"
"k9s/plugins/openssl.yaml"
"k9s/plugins/watch-events.yaml"
# custom
"k8s-tooling/.k9s/plugins/flux.yaml"
)
for PLUGIN in "${K9S_PLUGINS[@]}"; do
yq eval-all '. as $item ireduce ({}; . *+ $item)' \
--inplace "$K9S_CONFIG/plugins.yaml" "$PLUGIN"
done
rm -rf k9s
rm -rf k8s-tooling
chown -R "$USER:$USER" "$K9S_CONFIG"
chown -R "$USER:$USER" "$K9S_CTX"
log "Done!"