From 32c6c2576492b09e1d653ef9a519ac6aaf4eb2a5 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 4 Dec 2024 09:12:25 +1300 Subject: [PATCH] Minor testing improvements (#4483) * Improve logging * Improve logging and increase timeouts * Separate out format code per component --- Taskfile.yml | 29 +++++++++++++++++++++++++-- scripts/v2/create-kind-wi-storage.sh | 16 +++++++++++++-- scripts/v2/wait-for-operator-ready.sh | 12 +++++++---- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 9809d6fe03a..26548677712 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -102,8 +102,9 @@ tasks: desc: Ensure all code is formatted dir: v2 cmds: - - golangci-lint run --fix ./... --timeout 5m # I don't know why fix doesn't use the configured timeout - - gofumpt -l -w . + - task: asoctl:format-code + - task: generator:format-code + - task: controller:format-code build-docs-site: cmds: @@ -163,6 +164,13 @@ tasks: OUTPUT_FILE: '{{.TEST_OUT}}/asoctl-unit-tests.md' - go test ./... -tags=noexit -race -covermode atomic -coverprofile='{{.TEST_OUT}}/asoctl-coverage.out' -json -coverpkg=./... -run '{{default ".*" .TEST_FILTER}}' > '{{.TEST_OUT}}/asoctl-unit-tests.json' + asoctl:format-code: + desc: Ensure all code for asoctl is formatted + dir: v2/cmd/asoctl/ + cmds: + - golangci-lint run --fix ./... --timeout 5m --verbose + - gofumpt -l -w . + asoctl:lint: desc: Run {{.ASOCTL_APP}} fast lint checks. dir: '{{.ASOCTL_ROOT}}' @@ -246,6 +254,13 @@ tasks: cmds: - go test ./... -run ^TestGolden -update + generator:format-code: + desc: Ensure all code for the code generator is formatted + dir: v2/tools/generator + cmds: + - golangci-lint run --fix ./... --timeout 5m --verbose + - gofumpt -l -w . + generator:lint: desc: Run {{.GENERATOR_APP}} fast lint checks. dir: '{{.GENERATOR_ROOT}}' @@ -297,6 +312,13 @@ tasks: - task: basic-checks - task: controller:lint + controller:format-code: + desc: Ensure all code for the controller is formatted + dir: v2 + cmds: + - golangci-lint run --fix ./... --timeout 5m --verbose + - gofumpt -l -w . + controller:lint: desc: Run fast lint checks. deps: @@ -844,9 +866,12 @@ tasks: deps: - az-login cmds: + - echo "Cleaning {{.KIND_WORKLOAD_IDENTITY_PATH}}" - "rm -rf {{.KIND_WORKLOAD_IDENTITY_PATH}}" - "mkdir -p {{.KIND_WORKLOAD_IDENTITY_PATH}}" + - echo "Calling create-kind-wi-storage.sh" - "{{.SCRIPTS_ROOT}}/create-kind-wi-storage.sh -d {{.KIND_WORKLOAD_IDENTITY_PATH}} -p {{.TEST_LIVE_RESOURCE_PREFIX}}" + - echo "Calling kind-with-registry.sh" - "export KIND_CLUSTER_NAME=asov2-wi && \ export SERVICE_ACCOUNT_ISSUER=$(cat {{.KIND_WORKLOAD_IDENTITY_PATH}}/azure/saissuer.txt) && \ {{.SCRIPTS_ROOT}}/kind-with-registry.sh" diff --git a/scripts/v2/create-kind-wi-storage.sh b/scripts/v2/create-kind-wi-storage.sh index 1fb6260fbbd..0a11eb30b86 100755 --- a/scripts/v2/create-kind-wi-storage.sh +++ b/scripts/v2/create-kind-wi-storage.sh @@ -41,13 +41,13 @@ RESOURCE_GROUP="${PREFIX}-rg-wi$(openssl rand -hex 6)" # If somehow the files already exist then the resource also already exists and we shouldn't do anything if [ -f "$DIR/azure/oidcid.txt" ]; then # Nothing to do, no existing rg - echo "Using existing OIDC key $(cat ${DIR}/azure/oidcid.txt)" + echo "[INF] Using existing OIDC key $(cat ${DIR}/azure/oidcid.txt)" exit 0 fi if [ -f "$DIR/azure/rg.txt" ]; then # Nothing to do, no existing rg - echo "Using existing RG $(cat ${DIR}/azure/rg.txt)" + echo "[INF] Using existing RG $(cat ${DIR}/azure/rg.txt)" exit 0 fi @@ -65,12 +65,17 @@ openssl genrsa -out "$DIR/sa.key" 2048 openssl rsa -in "$DIR/sa.key" -pubout -out "$DIR/sa.pub" if [ -z "${KIND_OIDC_STORAGE_ACCOUNT_SUBSCRIPTION-}" ]; then + echo "[DBG] KIND_OIDC_STORAGE_ACCOUNT_SUBSCRIPTION is not set, fetching the current subscription" KIND_OIDC_STORAGE_ACCOUNT_SUBSCRIPTION=$(az account show --output tsv --query id) fi +echo "[DBG] KIND_OIDC_STORAGE_ACCOUNT_SUBSCRIPTION: ${KIND_OIDC_STORAGE_ACCOUNT_SUBSCRIPTION}" + # There's already a trailing / so we don't need to add one between the web endpoint and the OIDC Identifier +echo "[DBG] Retrieving OIDC issuer URL" ISSUER_URL="$(az storage account show --subscription ${KIND_OIDC_STORAGE_ACCOUNT_SUBSCRIPTION} --name "${KIND_OIDC_STORAGE_ACCOUNT}" -o json | jq -r .primaryEndpoints.web)${OIDC_IDENTIFIER}" echo "${ISSUER_URL}" > "${DIR}/azure/saissuer.txt" +echo "[DBG] OIDC issuer URL: ${ISSUER_URL}" cat < "${DIR}/openid-configuration.json" { @@ -90,8 +95,15 @@ EOF CREATION_TIME="$(date --utc +"%Y-%m-%dT%H:%M:%SZ")" +echo "[INF] Creating resource group ${RESOURCE_GROUP}" az group create -l westus -n "${RESOURCE_GROUP}" --tags "CreatedAt=${CREATION_TIME}" +echo "[INF] Uploading OIDC configuration to storage account" +echo "[DBG] KIND_OIDC_STORAGE_ACCOUNT: ${KIND_OIDC_STORAGE_ACCOUNT}" +echo "[DBG] KIND_OIDC_STORAGE_CONTAINER: ${KIND_OIDC_STORAGE_CONTAINER}" +echo "[DBG] OIDC_IDENTIFIER: ${OIDC_IDENTIFIER}" +echo "[DBG] CREATION_TIME: ${CREATION_TIME}" + az storage blob upload \ --account-name "${KIND_OIDC_STORAGE_ACCOUNT}" \ --container-name "${KIND_OIDC_STORAGE_CONTAINER}" \ diff --git a/scripts/v2/wait-for-operator-ready.sh b/scripts/v2/wait-for-operator-ready.sh index f5460c7d871..8cf8ffe8eb6 100755 --- a/scripts/v2/wait-for-operator-ready.sh +++ b/scripts/v2/wait-for-operator-ready.sh @@ -28,27 +28,31 @@ function all_crds_have_cabundle() { for crd in $(kubectl get crd -l "app.kubernetes.io/name == azure-service-operator" -o name); do cabundle=$(kubectl get "$crd" -o jsonpath='{.spec.conversion.webhook.clientConfig.caBundle}') if [ -z "$cabundle" ]; then - echo "$crd has no CA bundle" + echo "[INF] $crd has no CA bundle" return 1 fi + + echo "[INF] $crd has CA bundle" done return 0 } function wait_for_crds_cabundle() { + echo "[INF] Waiting for all CRDs to have CA bundle..." until all_crds_have_cabundle; do sleep 5 done } function wait_for_crds_established() { - until kubectl wait --for=condition=established --timeout=1m crd -l 'app.kubernetes.io/name == azure-service-operator'; do + until kubectl wait --for=condition=established --timeout=3m crd -l 'app.kubernetes.io/name == azure-service-operator'; do + echo "[INF] CRDs not yet established, retrying..." sleep 5 done } if [[ "$CHECK_ESTABLISHED" -eq 1 ]]; then - echo "Waiting for CRDs established..." + echo "[INF] Waiting for CRDs to be established..." # This has to be a timeout wrapping kubectl wait as we're racing with CRDs being added, and kubectl wait will fail if nothing matches the -l filter export -f wait_for_crds_established timeout 2m bash -c wait_for_crds_established @@ -60,7 +64,7 @@ kubectl wait --for=condition=ready --timeout=3m pod -n "$OPERATOR_NAMESPACE" -l echo "Waiting for CRD cabundle..." export -f all_crds_have_cabundle export -f wait_for_crds_cabundle -timeout 2m bash -c wait_for_crds_cabundle +timeout 8m bash -c wait_for_crds_cabundle echo "The operator is ready" exit 0