-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathrun.sh
executable file
·141 lines (114 loc) · 4.76 KB
/
run.sh
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
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
# Copyright 2021 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o nounset
set -o errexit
set -o pipefail
# Sets up the end-to-end test environment by:
# - creating a kind cluster
# - deploying cert-manager
# - deploying cert-manager-csi-driver
# The end-to-end test suite will then be run against this environment.
# The cluster will be deleted after tests have run.
REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.."
cd "$REPO_ROOT"
ARTIFACTS="${ARTIFACTS:-$REPO_ROOT/_artifacts}"
BIN_DIR="$REPO_ROOT/bin"
mkdir -p "$BIN_DIR"
# install_multiplatform will install a binary for either Linux of macOS
# $1 = path to install to
# $2 = filename to save as
# $3 = linux-specific URL
# $4 = mac-specific URL
install_multiplatform() {
case "$(uname -s)" in
Darwin)
curl -Lo "$1/$2" "$4"
;;
Linux)
curl -Lo "$1/$2" "$3"
;;
*)
echo 'Unsupported OS!'
exit 1
;;
esac
chmod +x "$1/$2"
}
if ! command -v kubectl; then
echo "'kubectl' command not found - installing..."
install_multiplatform "${BIN_DIR}" kubectl "https://dl.k8s.io/release/v1.23.6/bin/linux/amd64/kubectl" "https://dl.k8s.io/release/v1.23.6/bin/darwin/amd64/kubectl"
fi
if ! command -v go; then
echo "'go' command not found - please install from https://golang.org"
exit 1
fi
if ! command -v docker; then
echo "'docker' command not found - please install from https://docker.com"
exit 1
fi
KIND_BIN="$BIN_DIR/kind"
if ! command -v $KIND_BIN; then
echo "'kind' not available in '$BIN_DIR', please run 'make depend'"
exit 1
fi
HELM_BIN="$BIN_DIR/helm"
if ! command -v $HELM_BIN; then
echo "'helm' not available in '$BIN_DIR', please run 'make depend'"
exit 1
fi
export PATH="$BIN_DIR:$PATH"
CLUSTER_NAME="cert-manager-csi-driver-cluster"
exit_command() {
$KIND_BIN export logs "${ARTIFACTS}" --name="$CLUSTER_NAME"
if [ -z "${SKIP_CLEANUP:-}" ]; then
$KIND_BIN delete cluster --name="$CLUSTER_NAME"
else
echo "Skipping cleanup due to SKIP_CLEANUP flag set - run 'kind delete cluster --name=$CLUSTER_NAME' to cleanup"
fi
}
trap exit_command EXIT
echo "Pre-creating 'kind' docker network to avoid networking issues in CI"
# When running in our CI environment the Docker network's subnet choice will cause issues with routing
# This works this around till we have a way to properly patch this.
docker network create --driver=bridge --subnet=192.168.0.0/16 --gateway 192.168.0.1 kind || true
# Sleep for 2s to avoid any races between docker's network subcommand and 'kind create'
sleep 2
echo "Creating kind cluster named '$CLUSTER_NAME'"
# Kind image with Kubernetes v1.24.1
$KIND_BIN create cluster --image=kindest/node@sha256:fd82cddc87336d91aa0a2fc35f3c7a9463c53fd8e9575e9052d2c75c61f5b083 --name="$CLUSTER_NAME"
export KUBECONFIG="$($KIND_BIN get kubeconfig-path --name="$CLUSTER_NAME")"
CERT_MANAGER_MANIFEST_URL="https://github.com/cert-manager/cert-manager/releases/download/v1.8.0/cert-manager.yaml"
echo "Installing cert-manager in test cluster using manifest URL '$CERT_MANAGER_MANIFEST_URL'"
kubectl create -f "$CERT_MANAGER_MANIFEST_URL"
CERT_MANAGER_CSI_DOCKER_IMAGE="quay.io/jetstack/cert-manager-csi-driver"
CERT_MANAGER_CSI_DOCKER_TAG="canary"
echo "Building cert-manager-csi-driver container"
docker build -t "$CERT_MANAGER_CSI_DOCKER_IMAGE:$CERT_MANAGER_CSI_DOCKER_TAG" .
echo "Loading '$CERT_MANAGER_CSI_DOCKER_IMAGE:$CERT_MANAGER_CSI_DOCKER_TAG' image into kind cluster"
$KIND_BIN load docker-image --name="$CLUSTER_NAME" "$CERT_MANAGER_CSI_DOCKER_IMAGE:$CERT_MANAGER_CSI_DOCKER_TAG"
echo "Deploying cert-manager-csi-driver into test cluster"
$HELM_BIN upgrade --install -n cert-manager cert-manager-csi-driver ./deploy/charts/csi-driver --set image.repository=$CERT_MANAGER_CSI_DOCKER_IMAGE --set image.tag=$CERT_MANAGER_CSI_DOCKER_TAG
echo "Waiting 30s to allow Deployment & DaemonSet controllers to create pods"
sleep 30
kubectl get pods -A
echo "Waiting for all pods to be ready..."
kubectl wait --for=condition=Ready pod --all --all-namespaces --timeout=5m
echo "Executing end-to-end test suite"
# Export variables used by test suite
export REPO_ROOT
export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}"
export CLUSTER_NAME
export KUBECTL=$(command -v kubectl)
go test -v -timeout 30m "./test/e2e/suite"