Skip to content

Commit

Permalink
Merge pull request #1334 from CecileRobertMichon/fix-scripts
Browse files Browse the repository at this point in the history
Small improvements in ci-entrypoint script
  • Loading branch information
k8s-ci-robot authored Apr 24, 2021
2 parents adaf9c6 + 35f86c2 commit f8b2304
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions hack/ensure-acr-cleanup-schedule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions hack/ensure-acr-login.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 2 additions & 9 deletions scripts/ci-conformance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
10 changes: 2 additions & 8 deletions scripts/ci-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion scripts/ci-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ 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() {
# 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)"
Expand All @@ -60,10 +68,10 @@ 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}"
export REGISTRY="${REGISTRY:-capz}"
export EXP_CLUSTER_RESOURCE_SET="true"
${REPO_ROOT}/hack/create-dev-cluster.sh
}
Expand Down

0 comments on commit f8b2304

Please sign in to comment.