-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathdeploy-chart-test.sh
More file actions
executable file
·133 lines (108 loc) · 3.7 KB
/
deploy-chart-test.sh
File metadata and controls
executable file
·133 lines (108 loc) · 3.7 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
set -euo pipefail
# deploy-public-chart-test.sh
#
# SUMMARY
#
# Deploys a public chart into Kubernetes for testing purposes.
# Uses the same installation method our users would use.
#
# This script implements cli interface required by the kubernetes E2E
# tests.
#
# USAGE
#
# Deploy:
#
# $ CHART_REPO=https://helm.testmaterial.tld scripts/deploy-public-chart-test.sh up test-namespace-qwerty chart release
#
# Teardown:
#
# $ scripts/deploy-public-chart-test.sh down test-namespace-qwerty chart
#
cd "$(dirname "${BASH_SOURCE[0]}")/.."
# Command to perform.
COMMAND="${1:?"Specify the command (up/down) as the first argument"}"
# A Kubernetes namespace to deploy to.
NAMESPACE="${2:?"Specify the namespace as the second argument"}"
# The helm chart to manage
HELM_CHART="${3:?"Specify the helm chart name as the third argument"}"
# Release name for chart install
RELEASE_NAME="${4:?"Specify the release name as the fourth argument"}"
# Allow overriding kubectl with something like `minikube kubectl --`.
VECTOR_TEST_KUBECTL="${VECTOR_TEST_KUBECTL:-"kubectl"}"
# Allow overriding helm with a custom command.
VECTOR_TEST_HELM="${VECTOR_TEST_HELM:-"helm"}"
# Allow optionally installing custom resource configs.
CUSTOM_RESOURCE_CONFIGS_FILE="${CUSTOM_RESOURCE_CONFIGS_FILE:-""}"
# Allow optionally passing custom Helm values.
CUSTOM_HELM_VALUES_FILES="${CUSTOM_HELM_VALUES_FILES:-""}"
# Allow overriding the local repo name, useful to use multiple external repo
CUSTOM_HELM_REPO_LOCAL_NAME="${CUSTOM_HELM_REPO_LOCAL_NAME:-"local_repo"}"
split-container-image() {
local INPUT="$1"
CONTAINER_IMAGE_REPOSITORY="${INPUT%:*}"
CONTAINER_IMAGE_TAG="${INPUT##*:}"
}
up() {
# A Vector container image to use.
CONTAINER_IMAGE="${CONTAINER_IMAGE:?"You must assign CONTAINER_IMAGE variable with the Vector container image name"}"
# Support both remote repos (https://...) and local chart paths
if [[ "$CHART_REPO" == http* ]]; then
$VECTOR_TEST_HELM repo add "$CUSTOM_HELM_REPO_LOCAL_NAME" "$CHART_REPO" --force-update || true
$VECTOR_TEST_HELM repo update
HELM_INSTALL_TARGET="$CUSTOM_HELM_REPO_LOCAL_NAME/$HELM_CHART"
else
HELM_INSTALL_TARGET="$CHART_REPO"
fi
$VECTOR_TEST_KUBECTL create namespace "$NAMESPACE" --dry-run -o yaml | $VECTOR_TEST_KUBECTL apply -f -
if [[ -n "$CUSTOM_RESOURCE_CONFIGS_FILE" ]]; then
$VECTOR_TEST_KUBECTL create --namespace "$NAMESPACE" -f "$CUSTOM_RESOURCE_CONFIGS_FILE"
fi
HELM_VALUES=()
for file in $CUSTOM_HELM_VALUES_FILES ; do
HELM_VALUES+=(
--values "$file"
)
done
split-container-image "$CONTAINER_IMAGE"
if [[ -z "${VECTOR_TEST_SKIP_LOG_ENV:-}" ]]; then
# Set a reasonable log level to avoid issues with internal logs
# overwriting console output.
HELM_VALUES+=(
--set "env[0].name=VECTOR_LOG"
--set "env[0].value=info"
)
fi
HELM_VALUES+=(
--set "image.repository=$CONTAINER_IMAGE_REPOSITORY"
--set "image.tag=$CONTAINER_IMAGE_TAG"
)
set -x
$VECTOR_TEST_HELM install \
--atomic \
--namespace "$NAMESPACE" \
"${HELM_VALUES[@]}" \
"$RELEASE_NAME" \
"$HELM_INSTALL_TARGET"
{ set +x; } &>/dev/null
}
down() {
if [[ -n "$CUSTOM_RESOURCE_CONFIGS_FILE" ]]; then
$VECTOR_TEST_KUBECTL delete --namespace "$NAMESPACE" -f "$CUSTOM_RESOURCE_CONFIGS_FILE"
fi
if $VECTOR_TEST_HELM status --namespace "$NAMESPACE" "$HELM_CHART" &>/dev/null; then
$VECTOR_TEST_HELM delete --namespace "$NAMESPACE" "$HELM_CHART"
fi
if $VECTOR_TEST_KUBECTL get namespace "$NAMESPACE" &>/dev/null; then
$VECTOR_TEST_KUBECTL delete namespace "$NAMESPACE"
fi
}
case "$COMMAND" in
up|down)
"$COMMAND" "$@"
;;
*)
echo "Invalid command: $COMMAND" >&2
exit 1
esac