Skip to content

Commit

Permalink
Minor testing improvements (#4483)
Browse files Browse the repository at this point in the history
* Improve logging

* Improve logging and increase timeouts

* Separate out format code per component
  • Loading branch information
theunrepentantgeek authored Dec 3, 2024
1 parent ab4bf2b commit 32c6c25
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
29 changes: 27 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}}'
Expand Down Expand Up @@ -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}}'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 14 additions & 2 deletions scripts/v2/create-kind-wi-storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <<EOF > "${DIR}/openid-configuration.json"
{
Expand All @@ -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}" \
Expand Down
12 changes: 8 additions & 4 deletions scripts/v2/wait-for-operator-ready.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 32c6c25

Please sign in to comment.