forked from abompotas/k8s-overleaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-secret.sh
More file actions
executable file
·73 lines (62 loc) · 1.65 KB
/
create-secret.sh
File metadata and controls
executable file
·73 lines (62 loc) · 1.65 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
#!/bin/bash
# Function to print usage
usage() {
echo "Usage: bash create-secret.sh -tls {xxxxx.zip} -host {act.buaa.edu.cn} -n {namespace} {secret_name}"
exit 1
}
# Parse command line arguments
while [ $# -gt 0 ]; do
case "$1" in
-tls)
zip_file="$2"
shift 2
;;
-n)
namespace="$2"
shift 2
;;
-host)
host="$2"
shift 2
;;
*)
secret_name="$1"
shift
;;
esac
done
# Check if mandatory arguments are provided
if [ -z "$zip_file" ] || [ -z "$namespace" ] || [ -z "$secret_name" ]; then
usage
fi
# Unzip the file to $host
# if the filename ends with .zip
# if the filename ends with .tgz
# if the filename ends with .tar.gz
if [[ "$zip_file" == *.zip ]]; then
unzip -o "$zip_file"
elif [[ "$zip_file" == *.tgz ]]; then
tar -xzf "$zip_file"
elif [[ "$zip_file" == *.tar.gz ]]; then
tar -xzf "$zip_file"
else
echo "Error: Invalid file format. Please provide a zip, tgz, or tar.gz file."
exit 1
fi
# Check if necessary files are present
if [ ! -f "$host/$host.key" ] || [ ! -f "$host/fullchain.cer" ]; then
echo "Error: Required files are missing in the zip file."
exit 1
fi
# Create the Kubernetes secret in yaml format
kubectl delete secret -n "$namespace" "$secret_name"
kubectl create secret tls "$secret_name" --key $host/$host.key --cert $host/fullchain.cer -n "$namespace"
# Check if secret creation was successful
if [ $? -eq 0 ]; then
echo "Secret '$secret_name' created successfully in namespace '$namespace'."
else
echo "Error: Failed to create secret."
exit 1
fi
# Delete the unzipped files
rm -rf $host