-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
48 lines (41 loc) · 1.64 KB
/
setup.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
# Namespace
NAMESPACE="jetlag"
# Function to create or update a Kubernetes secret
create_or_update_kube_secret() {
local secret_name=$1
local secret_key=$2
local secret_prompt=$3
local namespace=$4
local secret_value
# Check if the secret already exists
if kubectl get secret "$secret_name" -n "$namespace" &> /dev/null; then
# Secret exists, ask whether to replace it
read -p "Secret '$secret_name' already exists. Do you want to replace it? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Delete the existing secret
kubectl delete secret "$secret_name" -n "$namespace"
else
return
fi
fi
# Prompt for new secret value
read -sp "Enter $secret_prompt: " secret_value
echo
# Create the secret
if [[ "$secret_name" == "marcindz88-docker-registry" ]]; then
# Special handling for docker-registry secret
kubectl -n "$namespace" create secret docker-registry marcindz88-docker-registry \
--docker-server=ghcr.io \
--docker-username=marcindz88 \
--docker-password="$secret_value" \
else
# Create the secret normally for other types
kubectl create secret generic "$secret_name" --from-literal="$secret_key=$secret_value" -n "$namespace"
fi
}
## Create namespace if it doesn't exist
kubectl get namespace "$NAMESPACE" &> /dev/null || kubectl create namespace "$NAMESPACE"
create_or_update_kube_secret "marcindz88-docker-registry" "password" "GitHub Token" "$NAMESPACE"
kubectl apply -f config/ -n "$NAMESPACE"