|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 The KCP Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-e2e}" |
| 20 | +DATA_DIR=".e2e-$KIND_CLUSTER_NAME" |
| 21 | +OPERATOR_PID=0 |
| 22 | + |
| 23 | +mkdir -p "$DATA_DIR" |
| 24 | +echo "Logs are stored in $DATA_DIR/." |
| 25 | +DATA_DIR="$(realpath "$DATA_DIR")" |
| 26 | + |
| 27 | +# create a local kind cluster |
| 28 | + |
| 29 | +export KUBECONFIG="$DATA_DIR/kind.kubeconfig" |
| 30 | +echo "Creating kind cluster $KIND_CLUSTER_NAME…" |
| 31 | +kind create cluster --name "$KIND_CLUSTER_NAME" |
| 32 | +chmod 600 "$KUBECONFIG" |
| 33 | + |
| 34 | +teardown_kind() { |
| 35 | + echo "Stopping kcp-operator…" |
| 36 | + kill -TERM $OPERATOR_PID |
| 37 | + wait $OPERATOR_PID |
| 38 | + |
| 39 | + kind delete cluster --name "$KIND_CLUSTER_NAME" |
| 40 | + rm "$KUBECONFIG" |
| 41 | +} |
| 42 | +trap teardown_kind EXIT |
| 43 | + |
| 44 | +echo "Kubeconfig is in $KUBECONFIG." |
| 45 | + |
| 46 | +# deploying operator CRDs |
| 47 | +echo "Deploying operator CRDs…" |
| 48 | +kubectl apply --kustomize config/crd |
| 49 | + |
| 50 | +# deploying cert-manager |
| 51 | +echo "Deploying cert-manager…" |
| 52 | + |
| 53 | +helm repo add jetstack https://charts.jetstack.io --force-update |
| 54 | +helm repo update |
| 55 | + |
| 56 | +helm upgrade \ |
| 57 | + --install \ |
| 58 | + --namespace cert-manager \ |
| 59 | + --create-namespace \ |
| 60 | + --version v1.18.2 \ |
| 61 | + --set crds.enabled=true \ |
| 62 | + --atomic \ |
| 63 | + cert-manager jetstack/cert-manager |
| 64 | + |
| 65 | +kubectl apply --filename hack/ci/testdata/clusterissuer.yaml |
| 66 | + |
| 67 | +# start the operator locally |
| 68 | +echo "Starting kcp-operator…" |
| 69 | +_build/manager \ |
| 70 | + -kubeconfig "$KUBECONFIG" \ |
| 71 | + -zap-log-level debug \ |
| 72 | + -zap-encoder console \ |
| 73 | + -zap-time-encoding iso8601 \ |
| 74 | + >"$DATA_DIR/kcp-operator.log" 2>&1 & |
| 75 | +OPERATOR_PID=$! |
| 76 | +echo "Running as process $OPERATOR_PID." |
| 77 | + |
| 78 | +echo "Running e2e tests…" |
| 79 | + |
| 80 | +WHAT="${WHAT:-./test/e2e/...}" |
| 81 | +TEST_ARGS="${TEST_ARGS:--timeout 2h -v}" |
| 82 | +E2E_PARALLELISM=${E2E_PARALLELISM:-2} |
| 83 | + |
| 84 | +(set -x; go test -tags e2e -p $E2E_PARALLELISM $TEST_ARGS "$WHAT") |
0 commit comments