forked from cloud-ark/kubeplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·113 lines (100 loc) · 3.91 KB
/
install.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Function to print usage
usage() {
echo "Usage: $0 [--kubeplus-plugin] [--kubeplus <kubeplus-namespace>]"
echo "Example: $0 --kubeplus-plugin --kubeplus kubeplus-namespace"
exit 1
}
# Exit on error
set -e
# Check if Helm is installed
if ! command -v helm &> /dev/null; then
echo "Error: Helm is not installed. Please install Helm before running this script."
exit 1
fi
# Check if KUBEPLUS_CI is set and is true
if [ -z "$KUBEPLUS_CI" ]; then
KUBEPLUS_CI=false
fi
# Parse arguments
TIMEOUT=1200
INSTALL_KUBEPLUS=false
INSTALL_KUBEPLUS_PLUGIN=false
KUBEPLUS_NAMESPACE="kubeplus"
while [[ "$#" -gt 0 ]]; do
case $1 in
--kubeplus-plugin)
INSTALL_KUBEPLUS_PLUGIN=true
;;
--kubeplus)
INSTALL_KUBEPLUS=true
if [ -n "$2" ] && [[ "$2" != --* ]]; then
KUBEPLUS_NAMESPACE="$2"
shift
fi
;;
*)
usage
;;
esac
shift
done
# Function to configure provider kubeconfig for KubePlus
provider_kubeconfig() {
echo "Downloading and setting up provider-kubeconfig.py"
kubectl create namespace $KUBEPLUS_NAMESPACE 2>/dev/null || echo "Namespace $KUBEPLUS_NAMESPACE already exists"
if ! $KUBEPLUS_CI; then
wget -q https://raw.githubusercontent.com/cloud-ark/kubeplus/master/requirements.txt || { echo "Failed to download requirements.txt"; exit 1; }
wget -q https://raw.githubusercontent.com/cloud-ark/kubeplus/master/provider-kubeconfig.py || { echo "Failed to download provider-kubeconfig.py"; exit 1; }
fi
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
apiserver=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')
python3 provider-kubeconfig.py -s $apiserver create $KUBEPLUS_NAMESPACE
deactivate
}
if $INSTALL_KUBEPLUS_PLUGIN; then
echo "Installing KubePlus Plugin"
if ! $KUBEPLUS_CI; then
wget -q https://github.com/cloud-ark/kubeplus/raw/master/kubeplus-kubectl-plugins.tar.gz || { echo "Failed to download kubeplus-kubectl-plugins.tar.gz"; exit 1; }
tar -zxvf kubeplus-kubectl-plugins.tar.gz
fi
export KUBEPLUS_HOME=$(pwd)
export PATH=$KUBEPLUS_HOME/plugins:$PATH
kubectl kubeplus commands
fi
# Install KubePlus if the flag is provided
if $INSTALL_KUBEPLUS; then
provider_kubeconfig
echo "Installing KubePlus in namespace: $KUBEPLUS_NAMESPACE"
if ! $KUBEPLUS_CI; then
helm install kubeplus https://github.com/cloud-ark/operatorcharts/raw/master/kubeplus-chart-4.0.0.tgz --kubeconfig=kubeplus-saas-provider.json -n $KUBEPLUS_NAMESPACE
else
helm install kubeplus ./deploy/kubeplus-chart \
--kubeconfig=kubeplus-saas-provider.json \
--set MUTATING_WEBHOOK=gcr.io/cloudark-kubeplus/pac-mutating-admission-webhook:latest \
--set PLATFORM_OPERATOR=gcr.io/cloudark-kubeplus/platform-operator:latest \
--set HELMER=gcr.io/cloudark-kubeplus/helm-pod:latest \
--set CRD_REGISTRATION_HELPER=gcr.io/cloudark-kubeplus/kubeconfiggenerator:latest \
-n $KUBEPLUS_NAMESPACE
fi
elapsed=0
while ! kubectl get pods --namespace $KUBEPLUS_NAMESPACE | grep kubeplus | grep Running; do
if [ $elapsed -ge $TIMEOUT ]; then
echo "Timed out waiting for KubePlus to start."
exit 1
fi
echo "Waiting for KubePlus to start.."
kubectl get pods --namespace $KUBEPLUS_NAMESPACE
sleep 1
elapsed=$((elapsed + 1))
done
echo "KubePlus has started successfully."
fi
# Provide additional instructions or notes
if ! $INSTALL_KUBEPLUS && ! $INSTALL_KUBEPLUS_PLUGIN; then
echo "No installation flags were provided. Please specify at least one installation flag: --kubeplus, or --kubeplus-plugin."
else
echo "Installation process completed. Check the status of the deployments using 'kubectl get pods -n <namespace>'."
fi