From 5281531830e5e23b9e237f76a3ecae2caf7c4e04 Mon Sep 17 00:00:00 2001 From: Cecile Robert-Michon Date: Thu, 22 Apr 2021 15:45:51 -0700 Subject: [PATCH 1/3] Use a random region by default in ci-entrypoint.sh --- scripts/ci-entrypoint.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/ci-entrypoint.sh b/scripts/ci-entrypoint.sh index d2c6c59ca33..726f0675abe 100755 --- a/scripts/ci-entrypoint.sh +++ b/scripts/ci-entrypoint.sh @@ -38,6 +38,11 @@ source "${REPO_ROOT}/hack/ensure-tags.sh" # shellcheck source=../hack/parse-prow-creds.sh source "${REPO_ROOT}/hack/parse-prow-creds.sh" +get_random_region() { + local REGIONS=("northcentralus" "centralus" "canadacentral" "eastus" "eastus2" "westus2" "westeurope" "uksouth" "northeurope" "francecentral") + echo "${REGIONS[${RANDOM} % ${#REGIONS[@]}]}" +} + create_cluster() { # export cluster template which contains the manifests needed for creating the Azure cluster to run the tests if [[ -n ${CI_VERSION:-} || -n ${USE_CI_ARTIFACTS:-} ]]; then @@ -60,6 +65,7 @@ create_cluster() { export CLUSTER_NAME="capz-$(head /dev/urandom | LC_ALL=C tr -dc a-z0-9 | head -c 6 ; echo '')" export AZURE_RESOURCE_GROUP="${CLUSTER_NAME}" + export AZURE_LOCATION="${AZURE_LOCATION:-$(get_random_region)}" # Need a cluster with at least 2 nodes export CONTROL_PLANE_MACHINE_COUNT="${CONTROL_PLANE_MACHINE_COUNT:-1}" export WORKER_MACHINE_COUNT="${WORKER_MACHINE_COUNT:-2}" From 512c0dc51f37a5be380410aae3ad68e003d74dee Mon Sep 17 00:00:00 2001 From: Cecile Robert-Michon Date: Fri, 23 Apr 2021 14:33:41 -0700 Subject: [PATCH 2/3] Fix cert-manager version in Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index be838a6af27..cab5fa4bed6 100644 --- a/Makefile +++ b/Makefile @@ -447,7 +447,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(MAKE) kind-create # Install cert manager and wait for availability - kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.0.1/cert-manager.yaml + kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.1.0/cert-manager.yaml kubectl wait --for=condition=Available --timeout=5m -n cert-manager deployment/cert-manager kubectl wait --for=condition=Available --timeout=5m -n cert-manager deployment/cert-manager-cainjector kubectl wait --for=condition=Available --timeout=5m -n cert-manager deployment/cert-manager-webhook From 35f86c2ade7e9ccb814dd5a51b2bd6bfe977470d Mon Sep 17 00:00:00 2001 From: Cecile Robert-Michon Date: Fri, 23 Apr 2021 14:34:45 -0700 Subject: [PATCH 3/3] Make REGISTRY var required and update acr cleanup tasks --- hack/ensure-acr-cleanup-schedule.sh | 14 +++++++++----- hack/ensure-acr-login.sh | 30 +++++++++++++++++++++++++++++ scripts/ci-conformance.sh | 11 ++--------- scripts/ci-e2e.sh | 10 ++-------- scripts/ci-entrypoint.sh | 4 +++- 5 files changed, 46 insertions(+), 23 deletions(-) create mode 100755 hack/ensure-acr-login.sh diff --git a/hack/ensure-acr-cleanup-schedule.sh b/hack/ensure-acr-cleanup-schedule.sh index 47e95c6e555..6b67c75130e 100755 --- a/hack/ensure-acr-cleanup-schedule.sh +++ b/hack/ensure-acr-cleanup-schedule.sh @@ -18,10 +18,14 @@ set -o errexit set -o nounset set -o pipefail -e2e_registry="ci-e2e/cluster-api-azure-controller-amd64" -az acr task create --name midnight_capz_ci_e2e_purge --cmd "acr purge --filter ${e2e_registry}:.* --ago 1d --untagged" \ - --schedule "0 0 * * *" --registry capzci --context /dev/null +repos=$(az acr repository list -o tsv --name capzci) + +for repo in $repos +do + filters+="--filter $repo:.* " +done + +PURGE_CMD="acr purge $filters --ago 1d --untagged" -registry="cluster-api-azure-controller-amd64" -az acr task create --name midnight_capz_purge --cmd "acr purge --filter ${registry}:.* --ago 1d --untagged" \ +az acr task create --name midnight_capz_purge --cmd "${PURGE_CMD}" \ --schedule "0 0 * * *" --registry capzci --context /dev/null diff --git a/hack/ensure-acr-login.sh b/hack/ensure-acr-login.sh new file mode 100755 index 00000000000..8faef5cc099 --- /dev/null +++ b/hack/ensure-acr-login.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Copyright 2021 The Kubernetes 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 errexit +set -o nounset +set -o pipefail + +REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +cd "${REPO_ROOT}" || exit 1 + +if [[ "${REGISTRY:-}" =~ capzci\.azurecr\.io ]]; then + # if we are using the prow Azure Container Registry, login. + ${REPO_ROOT}/hack/ensure-azcli.sh + : "${AZURE_SUBSCRIPTION_ID:?Environment variable empty or not defined.}" + az account set -s "${AZURE_SUBSCRIPTION_ID}" + az acr login --name capzci +fi diff --git a/scripts/ci-conformance.sh b/scripts/ci-conformance.sh index 63639f09d26..74aeebcff43 100755 --- a/scripts/ci-conformance.sh +++ b/scripts/ci-conformance.sh @@ -55,15 +55,8 @@ export LOCAL_ONLY=${LOCAL_ONLY:-"false"} if [[ "${LOCAL_ONLY}" == "true" ]]; then export REGISTRY="localhost:5000/ci-e2e" else - export REGISTRY=${REGISTRY:-"capzci.azurecr.io/ci-e2e"} - - if [[ "${REGISTRY}" =~ azurecr\.io ]]; then - # if we are using Azure Container Registry, login - ${REPO_ROOT}/hack/ensure-azcli.sh - az account set -s "${AZURE_SUBSCRIPTION_ID}" - az acr login --name capzci - fi -fi + : "${REGISTRY:?Environment variable empty or not defined.}" + ${REPO_ROOT}/hack/ensure-acr-login.sh defaultTag=$(date -u '+%Y%m%d%H%M%S') export TAG="${defaultTag:-dev}" diff --git a/scripts/ci-e2e.sh b/scripts/ci-e2e.sh index 8964662032f..8cd71f17e31 100755 --- a/scripts/ci-e2e.sh +++ b/scripts/ci-e2e.sh @@ -53,14 +53,8 @@ get_random_region() { export LOCAL_ONLY=${LOCAL_ONLY:-"true"} if [[ "${LOCAL_ONLY}" == "false" ]]; then - export REGISTRY=${REGISTRY:-"capzci.azurecr.io/ci-e2e"} - - if [[ "${REGISTRY}" =~ azurecr\.io ]]; then - # if we are using Azure Container Registry, login - ${REPO_ROOT}/hack/ensure-azcli.sh - az account set -s "${AZURE_SUBSCRIPTION_ID}" - az acr login --name capzci - fi + : "${REGISTRY:?Environment variable empty or not defined.}" + ${REPO_ROOT}/hack/ensure-acr-login.sh else export REGISTRY="localhost:5000/ci-e2e" fi diff --git a/scripts/ci-entrypoint.sh b/scripts/ci-entrypoint.sh index 726f0675abe..3934963b24a 100755 --- a/scripts/ci-entrypoint.sh +++ b/scripts/ci-entrypoint.sh @@ -44,6 +44,9 @@ get_random_region() { } create_cluster() { + # setup REGISTRY for custom images. + : "${REGISTRY:?Environment variable empty or not defined.}" + ${REPO_ROOT}/hack/ensure-acr-login.sh # export cluster template which contains the manifests needed for creating the Azure cluster to run the tests if [[ -n ${CI_VERSION:-} || -n ${USE_CI_ARTIFACTS:-} ]]; then KUBERNETES_BRANCH="$(cd $(go env GOPATH)/src/k8s.io/kubernetes && git rev-parse --abbrev-ref HEAD)" @@ -69,7 +72,6 @@ create_cluster() { # Need a cluster with at least 2 nodes export CONTROL_PLANE_MACHINE_COUNT="${CONTROL_PLANE_MACHINE_COUNT:-1}" export WORKER_MACHINE_COUNT="${WORKER_MACHINE_COUNT:-2}" - export REGISTRY="${REGISTRY:-capz}" export EXP_CLUSTER_RESOURCE_SET="true" ${REPO_ROOT}/hack/create-dev-cluster.sh }