Skip to content

Commit

Permalink
feat: allow extra args for k8s agent installer script (#3946)
Browse files Browse the repository at this point in the history
  • Loading branch information
schoren authored Jul 30, 2024
1 parent ffec70a commit 69c551d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
89 changes: 77 additions & 12 deletions k8s/agent/deploy-agent.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,69 @@
NAMESPACE=$1
API_KEY=$2
AGENT_VERSION="${3:-latest}"
FILE_PATH="https://raw.githubusercontent.com/kubeshop/tracetest/main/k8s/agent/deploy-agent.yaml"
#!/bin/bash

showUsageAndExit() {
echo "Usage: ./script <namespace> <api-key> (<version>)?"
echo "Examples:"
echo "./script tracetest my-api-key"
echo "./script my-namespace my-api-key v0.13.9"

exit 1
echo "Usage: ./deploy-agent.sh <namespace> <api-key> [<version>] [--skip-verify] [--server-url <url>]"
echo "Examples:"
echo " ./deploy-agent.sh tracetest my-api-key"
echo " ./deploy-agent.sh my-namespace my-api-key v0.13.9"
echo " ./deploy-agent.sh my-namespace my-api-key --skip-verify --server-url https://tracetest.my-domain.com"
echo ""
echo "Options:"
echo " --skip-verify Skip SSL certificate verification"
echo " --server-url <url> Specify the server URL"
echo " -h, --help Show this help message and exit"
echo ""
echo "Description:"
echo " This script deploys the tracetest agent in a Kubernetes cluster."
echo " It requires a namespace and an API key to authenticate with the server."
echo " The agent version can be optionally specified. If not provided, the latest version will be used."
echo " Additional options can be used to customize the deployment."
exit 1
}

FILE_PATH="https://raw.githubusercontent.com/kubeshop/tracetest/main/k8s/agent/deploy-agent.yaml"

NAMESPACE=""
API_KEY=""
AGENT_VERSION="latest"
SKIP_VERIFY=false
SERVER_URL=""

POSITIONAL_ARGS=()

while [[ $# -gt 0 ]]; do
case $1 in
--skip-verify)
SKIP_VERIFY=true
shift
;;
--server-url)
SERVER_URL="$2"
shift
shift
;;
-h|--help)
showUsageAndExit
;;
-*|--*)
echo "Invalid flag: $1"
showUsageAndExit
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done

if [[ ${#POSITIONAL_ARGS[@]} -ge 2 ]]; then
NAMESPACE=${POSITIONAL_ARGS[0]}
API_KEY=${POSITIONAL_ARGS[1]}
fi

if [[ ${#POSITIONAL_ARGS[@]} -ge 3 ]]; then
AGENT_VERSION=${POSITIONAL_ARGS[2]}
fi

if [ -z "${NAMESPACE}" ]; then
echo "Error: Namespace is required"
showUsageAndExit
Expand All @@ -22,5 +74,18 @@ if [ -z "${API_KEY}" ]; then
showUsageAndExit
fi

kubectl create -n $NAMESPACE secret generic tracetest-agent-secret --from-literal=api-key=$API_KEY
curl $FILE_PATH | sed "s/:TAG/:$AGENT_VERSION/g" | kubectl apply -n $NAMESPACE -f -
extraCmd=()
if [ "$SKIP_VERIFY" == "true" ]; then
extraCmd+=("--skip-verify")
fi

if [ -n "$SERVER_URL" ]; then
extraCmd+=("--server-url" "$SERVER_URL")
fi


# kubectl create -n $NAMESPACE secret generic tracetest-agent-secret --from-literal=api-key=$API_KEY
curl $FILE_PATH \
| sed "s/:TAG/:$AGENT_VERSION/g" \
| sed "$(if [ ${#extraCmd[@]} -eq 0 ]; then echo '/EXTRA_CMD/d'; else echo "s|EXTRA_CMD|$(printf "\"%s\"," "${extraCmd[@]}" | sed 's/,$//')|g"; fi)" \
| kubectl apply -n $NAMESPACE -f -
1 change: 1 addition & 0 deletions k8s/agent/deploy-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ spec:
containers:
- name: tracetest-agent
image: kubeshop/tracetest-agent:TAG
command: [EXTRA_CMD]
env:
- name: TRACETEST_API_KEY
valueFrom:
Expand Down

0 comments on commit 69c551d

Please sign in to comment.