-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
138 lines (119 loc) · 4.28 KB
/
setup.sh
File metadata and controls
138 lines (119 loc) · 4.28 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
# Function to check if Helm release exists
check_release_status() {
helm status flame-node --namespace "$namespace" > /dev/null 2>&1
echo $?
}
# Function to select a Kubernetes context
select_k8s_context() {
contexts=($(kubectl config get-contexts -o name))
if [ ${#contexts[@]} -eq 1 ]; then
k8s_context="${contexts[0]}"
echo "Only one context available, automatically selecting: $k8s_context"
else
current_context=$(kubectl config current-context)
echo "Available contexts:"
for i in "${!contexts[@]}"; do
if [ "${contexts[i]}" == "$current_context" ]; then
echo "$((i+1))) ${contexts[i]} (current)"
else
echo "$((i+1))) ${contexts[i]}"
fi
done
read -p "Enter the number corresponding to the context to use (default is $current_context): " context_number
context_number=${context_number:-0}
if [ "$context_number" -eq 0 ]; then
k8s_context="$current_context"
else
k8s_context="${contexts[$((context_number-1))]}"
fi
fi
kubectl config use-context "$k8s_context"
echo "Switched to context: $k8s_context"
}
# Function to select a values file
select_values_file() {
values_files=($(ls values*.yaml))
if [ ${#values_files[@]} -eq 1 ]; then
values_file="${values_files[0]}"
echo "Only one values file found, automatically selecting: $values_file"
else
echo "Available values files:"
for i in "${!values_files[@]}"; do
if [ "$i" -eq 0 ]; then
echo "$((i+1))) ${values_files[i]} (default)"
else
echo "$((i+1))) ${values_files[i]}"
fi
done
read -p "Enter the number corresponding to the values file to use (default is 1): " values_option
values_option=${values_option:-1}
values_file="${values_files[$((values_option-1))]}"
fi
echo "Using values file: $values_file"
}
# Function to delete all PVCs in the namespace if requested
delete_volumes() {
read -p "Do you want to delete all PersistentVolumeClaims (PVCs) in the namespace '$namespace'? (y/n): " delete_pvcs
if [[ "$delete_pvcs" =~ ^[Yy]$ ]]; then
kubectl delete pvc --all --namespace "$namespace"
echo "All PVCs in namespace '$namespace' deleted."
else
echo "PVCs retained."
fi
}
# Select Kubernetes context
select_k8s_context
# Get namespace from command line argument or user input
namespace=${1:-}
if [ -z "$namespace" ]; then
read -p "Enter namespace (default is 'default'): " namespace
fi
namespace=${namespace:-default}
# Determine available actions based on Helm release status
release_status=$(check_release_status)
available_actions=()
if [ "$release_status" -ne 0 ]; then
available_actions+=("install")
else
available_actions+=("upgrade" "uninstall")
fi
# Get action from command line argument or user input
action=${2:-}
if [ -z "$action" ]; then
echo "Available actions:"
for i in "${!available_actions[@]}"; do
echo "$((i+1))) ${available_actions[i]}"
done
read -p "Enter the number corresponding to the action to perform (default is 1): " action_number
action_number=${action_number:-1}
action="${available_actions[$((action_number-1))]}"
fi
# If the action is not uninstall, select a values file
if [ "$action" != "uninstall" ]; then
select_values_file
fi
# Add flame/private-aim repo
helm repo add flame https://PrivateAIM.github.io/helm
# update all repos
helm repo update
# Validate and perform the selected action
if [[ " ${available_actions[*]} " == *" $action "* ]]; then
case $action in
install)
helm install flame-node --namespace "$namespace" --create-namespace -f "$values_file" flame/flame-node
;;
upgrade)
helm upgrade flame-node --namespace "$namespace" --create-namespace -f "$values_file" flame/flame-node
;;
uninstall)
helm uninstall flame-node --namespace "$namespace"
delete_volumes
;;
*)
echo "Invalid action. Please enter one of the following: ${available_actions[*]}"
;;
esac
else
echo "Invalid action. Please enter one of the following: ${available_actions[*]}"
fi