|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2024 The Kubernetes Authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# hack script for running a kind e2e |
| 17 | +# must be run with a kubernetes checkout in $PWD (IE from the checkout) |
| 18 | +# Usage: SKIP="ginkgo skip regex" FOCUS="ginkgo focus regex" kind-e2e.sh |
| 19 | + |
| 20 | +set -o errexit -o nounset -o xtrace |
| 21 | + |
| 22 | +# Settings: |
| 23 | +# SKIP: ginkgo skip regex |
| 24 | +# FOCUS: ginkgo focus regex |
| 25 | +# LABEL_FILTER: ginkgo label query for selecting tests (see "Spec Labels" in https://onsi.github.io/ginkgo/#filtering-specs) |
| 26 | +# |
| 27 | +# The default is to focus on conformance tests. Serial tests get skipped when |
| 28 | +# parallel testing is enabled. Using LABEL_FILTER instead of combining SKIP and |
| 29 | +# FOCUS is recommended (more expressive, easier to read than regexp). |
| 30 | +# |
| 31 | +# GA_ONLY: true - limit to GA APIs/features as much as possible |
| 32 | +# false - (default) APIs and features left at defaults |
| 33 | +# FEATURE_GATES: |
| 34 | +# JSON or YAML encoding of a string/bool map: {"FeatureGateA": true, "FeatureGateB": false} |
| 35 | +# Enables or disables feature gates in the entire cluster. |
| 36 | +# Cannot be used when GA_ONLY=true. |
| 37 | +# RUNTIME_CONFIG: |
| 38 | +# JSON or YAML encoding of a string/string (!) map: {"apia.example.com/v1alpha1": "true", "apib.example.com/v1beta1": "false"} |
| 39 | +# Enables API groups in the apiserver via --runtime-config. |
| 40 | +# Cannot be used when GA_ONLY=true. |
| 41 | + |
| 42 | +COMMON_SCRIPT="${COMMON_SCRIPT:-${PWD}/../test-infra/experiment/compatibility-versions/common.sh}" |
| 43 | +source "${COMMON_SCRIPT}" |
| 44 | + |
| 45 | +# setup signal handlers |
| 46 | +# shellcheck disable=SC2317 # this is not unreachable code |
| 47 | +signal_handler() { |
| 48 | + if [ -n "${GINKGO_PID:-}" ]; then |
| 49 | + kill -TERM "$GINKGO_PID" || true |
| 50 | + fi |
| 51 | + cleanup |
| 52 | +} |
| 53 | +trap signal_handler INT TERM |
| 54 | + |
| 55 | +main() { |
| 56 | + # create temp dir and setup cleanup |
| 57 | + TMP_DIR=$(mktemp -d -p /tmp kind-e2e-XXXXXX) |
| 58 | + echo "Created temporary directory: ${TMP_DIR}" |
| 59 | + |
| 60 | + # ensure artifacts (results) directory exists when not in CI |
| 61 | + export ARTIFACTS="${ARTIFACTS:-${PWD}/_artifacts}" |
| 62 | + mkdir -p "${ARTIFACTS}" |
| 63 | + |
| 64 | + export VERSION_DELTA=${VERSION_DELTA:-1} |
| 65 | + |
| 66 | + WORKSPACE_STATUS=$(./hack/print-workspace-status.sh) |
| 67 | + GIT_VERSION=$(echo "$WORKSPACE_STATUS" | awk '/^gitVersion / {print $2}') |
| 68 | + # Check if gitVersion contains alpha.0 and increment VERSION_DELTA if needed |
| 69 | + # If the current version is alpha.0, it means the previous *stable* or developed |
| 70 | + # branch is actually n-2 relative to the current minor number for compatibility purposes. |
| 71 | + if [[ "${GIT_VERSION}" == *alpha.0* ]]; then |
| 72 | + echo "Detected alpha.0 in gitVersion (${GIT_VERSION}), treating as still the previous minor version." |
| 73 | + VERSION_DELTA=$((VERSION_DELTA + 1)) |
| 74 | + echo "Adjusted VERSION_DELTA: ${VERSION_DELTA}" |
| 75 | + fi |
| 76 | + |
| 77 | + MAJOR_VERSION=$(echo "$WORKSPACE_STATUS" | awk '/^STABLE_BUILD_MAJOR_VERSION / {print $2}') |
| 78 | + MINOR_VERSION=$(echo "$WORKSPACE_STATUS" | awk '/^STABLE_BUILD_MINOR_VERSION / {split($2, minor, "+"); print minor[1]}') |
| 79 | + export CURRENT_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}" |
| 80 | + export PREV_VERSION="${MAJOR_VERSION}.$((MINOR_VERSION - VERSION_DELTA))" |
| 81 | + export EMULATED_VERSION="${PREV_VERSION}" |
| 82 | + |
| 83 | + # export the KUBECONFIG to a unique path for testing |
| 84 | + KUBECONFIG="${HOME}/.kube/kind-test-config" |
| 85 | + export KUBECONFIG |
| 86 | + echo "exported KUBECONFIG=${KUBECONFIG}" |
| 87 | + |
| 88 | + # debug kind version |
| 89 | + kind version |
| 90 | + |
| 91 | + # in CI attempt to release some memory after building |
| 92 | + if [ -n "${KUBETEST_IN_DOCKER:-}" ]; then |
| 93 | + sync || true |
| 94 | + echo 1 > /proc/sys/vm/drop_caches || true |
| 95 | + fi |
| 96 | + |
| 97 | + res=0 |
| 98 | + create_cluster || res=$? |
| 99 | + |
| 100 | + |
| 101 | + # Perform the upgrade. Assume kind-upgrade.sh is in the same directory as this script. |
| 102 | + UPGRADE_SCRIPT="${UPGRADE_SCRIPT:-${PWD}/../test-infra/experiment/compatibility-versions/kind-upgrade.sh}" |
| 103 | + echo "Upgrading cluster with ${UPGRADE_SCRIPT}" |
| 104 | + |
| 105 | + upgrade_cluster_components || res=$? |
| 106 | + # If upgrade fails, we shouldn't run tests but should still clean up. |
| 107 | + if [[ "$res" -ne 0 ]]; then |
| 108 | + cleanup |
| 109 | + exit $res |
| 110 | + fi |
| 111 | + |
| 112 | + EMULATED_VERSION_UPGRADE_SCRIPT="${EMULATED_VERSION_UPGRADE_SCRIPT:-${PWD}/../test-infra/experiment/compatibility-versions/emulated-version-upgrade.sh}" |
| 113 | + echo "Upgrading cluster with ${EMULATED_VERSION_UPGRADE_SCRIPT}" |
| 114 | + "${EMULATED_VERSION_UPGRADE_SCRIPT}" | tee "${ARTIFACTS}/emulated-upgrade-output.txt" |
| 115 | + |
| 116 | + # Clone the previous versions Kubernetes release branch |
| 117 | + # TODO(aaron-prindle) extend the branches to test from n-1 -> n-1..3 as more k8s releases are done that support compatibility versions |
| 118 | + export PREV_RELEASE_BRANCH="release-${EMULATED_VERSION}" |
| 119 | + # Define the path within the temp directory for the cloned repo |
| 120 | + PREV_RELEASE_REPO_PATH="${TMP_DIR}/prev-release-k8s" |
| 121 | + echo "Cloning branch ${PREV_RELEASE_BRANCH} into ${PREV_RELEASE_REPO_PATH}" |
| 122 | + git clone --filter=blob:none --single-branch --branch "${PREV_RELEASE_BRANCH}" https://github.com/kubernetes/kubernetes.git "${PREV_RELEASE_REPO_PATH}" |
| 123 | + |
| 124 | + # enter the cloned prev repo branch (in temp) and run tests |
| 125 | + pushd "${PREV_RELEASE_REPO_PATH}" |
| 126 | + build_prev_version_bins || res=$? |
| 127 | + run_prev_version_tests || res=$? |
| 128 | + popd |
| 129 | + |
| 130 | + |
| 131 | + cleanup || res=$? |
| 132 | + exit $res |
| 133 | +} |
| 134 | + |
| 135 | +main |
0 commit comments