|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2026 The Kubernetes 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 | +# kops-upgrade runs an A->B kops upgrade test. Source after lib/common.sh. |
| 18 | +# Caller passes the create-args string; sets KOPS_VERSION_{A,B} and K8S_VERSION_{A,B}. |
| 19 | +function kops-upgrade() { |
| 20 | + local create_args="$1" |
| 21 | + |
| 22 | + if [ -z "${KOPS_VERSION_A-}" ] || [ -z "${K8S_VERSION_A-}" ] || [ -z "${KOPS_VERSION_B-}" ] || [ -z "${K8S_VERSION_B-}" ]; then |
| 23 | + >&2 echo "must set all of KOPS_VERSION_A, K8S_VERSION_A, KOPS_VERSION_B, K8S_VERSION_B env vars" |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | + |
| 27 | + TEST_PACKAGE_VERSION="${K8S_VERSION_B}" |
| 28 | + |
| 29 | + if [[ "$K8S_VERSION_A" == "latest" ]]; then |
| 30 | + K8S_VERSION_A=$(curl -L https://dl.k8s.io/release/latest.txt) |
| 31 | + fi |
| 32 | + if [[ "$K8S_VERSION_B" == "latest" ]]; then |
| 33 | + K8S_VERSION_B=$(curl -L https://dl.k8s.io/release/latest.txt) |
| 34 | + TEST_PACKAGE_MARKER="latest.txt" |
| 35 | + fi |
| 36 | + if [[ "$K8S_VERSION_A" == "stable" ]]; then |
| 37 | + K8S_VERSION_A=$(curl -L https://dl.k8s.io/release/stable.txt) |
| 38 | + fi |
| 39 | + if [[ "$K8S_VERSION_B" == "stable" ]]; then |
| 40 | + K8S_VERSION_B=$(curl -L https://dl.k8s.io/release/stable.txt) |
| 41 | + TEST_PACKAGE_MARKER="stable.txt" |
| 42 | + fi |
| 43 | + if [[ "$K8S_VERSION_A" == "ci" ]]; then |
| 44 | + K8S_VERSION_A=https://storage.googleapis.com/k8s-release-dev/ci/$(curl https://storage.googleapis.com/k8s-release-dev/ci/latest.txt) |
| 45 | + fi |
| 46 | + if [[ "$K8S_VERSION_B" == "ci" ]]; then |
| 47 | + K8S_VERSION_B=https://storage.googleapis.com/k8s-release-dev/ci/$(curl https://storage.googleapis.com/k8s-release-dev/ci/latest.txt) |
| 48 | + TEST_PACKAGE_MARKER="latest.txt" |
| 49 | + TEST_PACKAGE_DIR="ci" |
| 50 | + TEST_PACKAGE_URL="https://storage.googleapis.com/k8s-release-dev" |
| 51 | + fi |
| 52 | + |
| 53 | + export KOPS_BASE_URL |
| 54 | + |
| 55 | + echo "Cleaning up any leaked resources from previous cluster" |
| 56 | + # For KOPS_VERSION_B, the value "latest" means build of the tree |
| 57 | + if [[ "${KOPS_VERSION_B}" == "latest" ]]; then |
| 58 | + kops-acquire-latest |
| 59 | + KOPS_BASE_URL_B="${KOPS_BASE_URL}" |
| 60 | + KOPS_B="${KOPS}" |
| 61 | + else |
| 62 | + KOPS_BASE_URL=$(kops-base-from-marker "${KOPS_VERSION_B}") |
| 63 | + KOPS_BASE_URL_B="${KOPS_BASE_URL}" |
| 64 | + KOPS_B=$(kops-download-from-base) |
| 65 | + CHANNELS=$(kops-channels-download-from-base) |
| 66 | + fi |
| 67 | + |
| 68 | + ${KUBETEST2} \ |
| 69 | + --down \ |
| 70 | + --kops-binary-path="${KOPS_B}" || echo "kubetest2 down failed" |
| 71 | + |
| 72 | + # First kOps version may be a released version. If so, it is prefixed with v |
| 73 | + if [[ "${KOPS_VERSION_A:0:1}" == "v" ]]; then |
| 74 | + KOPS_BASE_URL="" |
| 75 | + KOPS_A=$(kops-download-release "$KOPS_VERSION_A") |
| 76 | + KOPS="${KOPS_A}" |
| 77 | + else |
| 78 | + KOPS_BASE_URL=$(kops-base-from-marker "${KOPS_VERSION_A}") |
| 79 | + KOPS_A=$(kops-download-from-base) |
| 80 | + KOPS="${KOPS_A}" |
| 81 | + fi |
| 82 | + |
| 83 | + # TODO: Switch scripts to use KOPS_CONTROL_PLANE_COUNT |
| 84 | + if [[ -n "${KOPS_CONTROL_PLANE_SIZE:-}" ]]; then |
| 85 | + echo "Recognized (deprecated) KOPS_CONTROL_PLANE_SIZE=${KOPS_CONTROL_PLANE_SIZE}, please set KOPS_CONTROL_PLANE_COUNT instead" |
| 86 | + KOPS_CONTROL_PLANE_COUNT=${KOPS_CONTROL_PLANE_SIZE} |
| 87 | + fi |
| 88 | + |
| 89 | + # Note that we use --control-plane-size, even though it is deprecated, because we have to support old versions |
| 90 | + # in the upgrade test. |
| 91 | + ${KUBETEST2} \ |
| 92 | + --up \ |
| 93 | + --env-file="${WORKSPACE}/env" \ |
| 94 | + --kops-binary-path="${KOPS_A}" \ |
| 95 | + --kubernetes-version="${K8S_VERSION_A}" \ |
| 96 | + --control-plane-size="${KOPS_CONTROL_PLANE_COUNT:-1}" \ |
| 97 | + --template-path="${KOPS_TEMPLATE:-}" \ |
| 98 | + --create-args="${create_args}" |
| 99 | + |
| 100 | + # Source the env file to get exported variables, in particular CLUSTER_NAME and KOPS_STATE_STORE |
| 101 | + # shellcheck disable=SC1091 |
| 102 | + . "${WORKSPACE}/env" |
| 103 | + export CLUSTER_NAME KOPS_STATE_STORE |
| 104 | + |
| 105 | + # Export kubeconfig-a |
| 106 | + KUBECONFIG_A=$(mktemp -t kops.XXXXXXXXX) |
| 107 | + "${KOPS_A}" export kubecfg --name "${CLUSTER_NAME}" --admin --kubeconfig "${KUBECONFIG_A}" |
| 108 | + |
| 109 | + # Verify kubeconfig-a |
| 110 | + kubectl get nodes -owide --kubeconfig="${KUBECONFIG_A}" |
| 111 | + |
| 112 | + KOPS_BASE_URL="${KOPS_BASE_URL_B}" |
| 113 | + |
| 114 | + KOPS="${KOPS_B}" |
| 115 | + |
| 116 | + "${KOPS_B}" edit cluster "${CLUSTER_NAME}" "--set=cluster.spec.kubernetesVersion=${K8S_VERSION_B}" |
| 117 | + |
| 118 | + # Preview changes |
| 119 | + "${KOPS_B}" reconcile cluster --allow-kops-downgrade |
| 120 | + |
| 121 | + # Apply changes |
| 122 | + "${KOPS_B}" reconcile cluster --allow-kops-downgrade --yes |
| 123 | + |
| 124 | + # Verify no additional changes |
| 125 | + "${KOPS_B}" update cluster |
| 126 | + |
| 127 | + "${KOPS_B}" validate cluster |
| 128 | + |
| 129 | + # Verify kubeconfig-a still works |
| 130 | + kubectl get nodes -owide --kubeconfig="${KUBECONFIG_A}" |
| 131 | + |
| 132 | + cp "${KOPS_B}" "${WORKSPACE}/kops" |
| 133 | + export PATH="${WORKSPACE}:${PATH}" |
| 134 | + |
| 135 | + "${KOPS_B}" export kubecfg --name "${CLUSTER_NAME}" --admin |
| 136 | + |
| 137 | + if [[ -n ${KOPS_SKIP_E2E:-} ]]; then |
| 138 | + return 0 |
| 139 | + fi |
| 140 | + |
| 141 | + local test_package_args="--parallel 25" |
| 142 | + |
| 143 | + if [[ -n ${TEST_PACKAGE_MARKER-} ]]; then |
| 144 | + test_package_args+=" --test-package-marker=${TEST_PACKAGE_MARKER}" |
| 145 | + if [[ -n ${TEST_PACKAGE_DIR-} ]]; then |
| 146 | + test_package_args+=" --test-package-dir=${TEST_PACKAGE_DIR-}" |
| 147 | + fi |
| 148 | + if [[ -n ${TEST_PACKAGE_BUCKET-} ]]; then |
| 149 | + test_package_args+=" --test-package-url=${TEST_PACKAGE_URL-}" |
| 150 | + fi |
| 151 | + else |
| 152 | + test_package_args+=" --test-package-version=${TEST_PACKAGE_VERSION}" |
| 153 | + fi |
| 154 | + |
| 155 | + # shellcheck disable=SC2086 |
| 156 | + ${KUBETEST2} \ |
| 157 | + --cloud-provider="${CLOUD_PROVIDER}" \ |
| 158 | + --kops-binary-path="${KOPS}" \ |
| 159 | + --test=kops \ |
| 160 | + -- \ |
| 161 | + $test_package_args \ |
| 162 | + --parallel 25 |
| 163 | +} |
0 commit comments