From 5a2e980f49e8790452822bff8186212a39818af9 Mon Sep 17 00:00:00 2001 From: Xingfei Xu Date: Wed, 25 Nov 2026 00:53:19 +0000 Subject: [PATCH 1/2] test: pass helm image tags as strings A short commit SHA made only of digits, such as 6124884, is parsed by helm as a number and rendered as 6.124884e+06 after helm upgrade --reuse-values, which breaks the image reference (InvalidImageName). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- test/scripts/bootstrap.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/scripts/bootstrap.sh b/test/scripts/bootstrap.sh index 4cc15b20..c9aa91ff 100644 --- a/test/scripts/bootstrap.sh +++ b/test/scripts/bootstrap.sh @@ -342,10 +342,10 @@ kubectl apply -f `go env GOPATH`/pkg/mod/go.goms.io/fleet@v0.18.16/config/crd/ba helm install hub-net-controller-manager \ ./charts/hub-net-controller-manager/ \ --set image.repository=$REGISTRY/hub-net-controller-manager \ - --set image.tag=$TAG \ + --set-string image.tag="$TAG" \ --set crdInstaller.enabled=true \ --set crdInstaller.image.repository=$REGISTRY/net-crd-installer \ - --set crdInstaller.image.tag=$TAG \ + --set-string crdInstaller.image.tag="$TAG" \ --set crdInstaller.isE2ETest=true \ $( [ "$ENABLE_TRAFFIC_MANAGER" = "true" ] && echo "--set enableTrafficManagerFeature=true -f hub_azure_config.yaml" ) @@ -354,7 +354,7 @@ kubectl config use-context $MEMBER_CLUSTER_1-admin helm install mcs-controller-manager \ ./charts/mcs-controller-manager \ --set image.repository=$REGISTRY/mcs-controller-manager \ - --set image.tag=$TAG \ + --set-string image.tag="$TAG" \ --set config.hubURL=$HUB_URL \ --set config.provider=azure \ --set config.memberClusterName=$MEMBER_CLUSTER_1 \ @@ -362,10 +362,10 @@ helm install mcs-controller-manager \ $( [ "$AZURE_NETWORK_SETTING" = "unsupported" ] && echo "--set enableNetworkingFeatures=false" ) helm install member-net-controller-manager ./charts/member-net-controller-manager/ \ --set image.repository=$REGISTRY/member-net-controller-manager \ - --set image.tag=$TAG \ + --set-string image.tag="$TAG" \ --set crdInstaller.enabled=true \ --set crdInstaller.image.repository=$REGISTRY/net-crd-installer \ - --set crdInstaller.image.tag=$TAG \ + --set-string crdInstaller.image.tag="$TAG" \ --set crdInstaller.isE2ETest=true \ --set config.hubURL=$HUB_URL \ --set config.provider=azure \ @@ -378,7 +378,7 @@ kubectl config use-context $MEMBER_CLUSTER_2-admin helm install mcs-controller-manager \ ./charts/mcs-controller-manager \ --set image.repository=$REGISTRY/mcs-controller-manager \ - --set image.tag=$TAG \ + --set-string image.tag="$TAG" \ --set config.hubURL=$HUB_URL \ --set config.provider=azure \ --set config.memberClusterName=$MEMBER_CLUSTER_2 \ @@ -386,10 +386,10 @@ helm install mcs-controller-manager \ $( [ "$AZURE_NETWORK_SETTING" = "unsupported" ] && echo "--set enableNetworkingFeatures=false" ) helm install member-net-controller-manager ./charts/member-net-controller-manager/ \ --set image.repository=$REGISTRY/member-net-controller-manager \ - --set image.tag=$TAG \ + --set-string image.tag="$TAG" \ --set crdInstaller.enabled=true \ --set crdInstaller.image.repository=$REGISTRY/net-crd-installer \ - --set crdInstaller.image.tag=$TAG \ + --set-string crdInstaller.image.tag="$TAG" \ --set crdInstaller.isE2ETest=true \ --set config.hubURL=$HUB_URL \ --set config.provider=azure \ @@ -416,17 +416,17 @@ then helm install mcs-controller-manager \ ./charts/mcs-controller-manager \ --set image.repository=$REGISTRY/mcs-controller-manager \ - --set image.tag=$TAG \ + --set-string image.tag="$TAG" \ --set config.hubURL=$HUB_URL \ --set config.provider=azure \ --set config.memberClusterName=$MEMBER_CLUSTER_3 \ --set azure.clientid=$CLIENT_ID_FOR_MEMBER_3 helm install member-net-controller-manager ./charts/member-net-controller-manager/ \ --set image.repository=$REGISTRY/member-net-controller-manager \ - --set image.tag=$TAG \ + --set-string image.tag="$TAG" \ --set crdInstaller.enabled=true \ --set crdInstaller.image.repository=$REGISTRY/net-crd-installer \ - --set crdInstaller.image.tag=$TAG \ + --set-string crdInstaller.image.tag="$TAG" \ --set crdInstaller.isE2ETest=true \ --set config.hubURL=$HUB_URL \ --set config.provider=azure \ @@ -437,17 +437,17 @@ then helm install mcs-controller-manager \ ./charts/mcs-controller-manager \ --set image.repository=$REGISTRY/mcs-controller-manager \ - --set image.tag=$TAG \ + --set-string image.tag="$TAG" \ --set config.hubURL=$HUB_URL \ --set config.provider=azure \ --set config.memberClusterName=$MEMBER_CLUSTER_4 \ --set azure.clientid=$CLIENT_ID_FOR_MEMBER_4 helm install member-net-controller-manager ./charts/member-net-controller-manager/ \ --set image.repository=$REGISTRY/member-net-controller-manager \ - --set image.tag=$TAG \ + --set-string image.tag="$TAG" \ --set crdInstaller.enabled=true \ --set crdInstaller.image.repository=$REGISTRY/net-crd-installer \ - --set crdInstaller.image.tag=$TAG \ + --set-string crdInstaller.image.tag="$TAG" \ --set crdInstaller.isE2ETest=true \ --set config.hubURL=$HUB_URL \ --set config.provider=azure \ From 5e9f4c4deb3559f41e6156aaa5219eb1adee6a05 Mon Sep 17 00:00:00 2001 From: Xingfei Xu Date: Wed, 25 Nov 2026 00:53:19 +0000 Subject: [PATCH 2/2] test: grant the E2E caller access to Traffic Manager endpoint IPs traffic_manager_test.go updates Traffic Manager endpoints directly, which requires joining the members' public IPs in their node resource groups. With least-privilege Contributor scoped to the shared resource group this returned LinkedAuthorizationFailed, so setup now grants E2E_TEST_PRINCIPAL_ID Network Contributor on both member node resource groups. The pipeline derives E2E_TEST_PRINCIPAL_ID from the signed-in token so it always matches the service connection in use, and defaults to the dedicated aks-devinfra-fleet-networking-e2e-wif connection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .pipeline/e2e-tests.yaml | 8 ++++++-- test/README.md | 11 +++++++---- test/scripts/bootstrap.sh | 14 ++++++++++++++ test/scripts/caller-object-id.sh | 10 ++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100755 test/scripts/caller-object-id.sh diff --git a/.pipeline/e2e-tests.yaml b/.pipeline/e2e-tests.yaml index f24e173d..b22d3dd8 100644 --- a/.pipeline/e2e-tests.yaml +++ b/.pipeline/e2e-tests.yaml @@ -10,7 +10,7 @@ pr: none parameters: - name: serviceConnection type: string - default: 'aks fleetnetworking' + default: 'aks-devinfra-fleet-networking-e2e-wif' - name: scenarios type: object default: @@ -132,7 +132,9 @@ jobs: echo "error: service connection subscription does not match the E2E subscription" >&2 exit 1 fi - # E2E_TEST_PRINCIPAL_ID is a pipeline variable and must match the service connection. + # Role assignments to the test principal follow the service connection that runs this job. + E2E_TEST_PRINCIPAL_ID="$(bash test/scripts/caller-object-id.sh)" + export E2E_TEST_PRINCIPAL_ID make e2e-setup - bash: | @@ -196,4 +198,6 @@ jobs: keepAzSessionActive: true inlineScript: | set -euo pipefail + E2E_TEST_PRINCIPAL_ID="$(bash test/scripts/caller-object-id.sh)" + export E2E_TEST_PRINCIPAL_ID make e2e-cleanup diff --git a/test/README.md b/test/README.md index 19ec3746..65529304 100644 --- a/test/README.md +++ b/test/README.md @@ -39,7 +39,8 @@ export AZURE_RESOURCE_GROUP= export E2E_RUN_ID= # Recommended: use a separate kubeconfig for this run. export KUBECONFIG= -# Required only when AFD automatic approval is enabled: +# Required for Traffic Manager and for AFD automatic approval: the object ID of the signed-in +# service principal (Azure Pipelines derives it with test/scripts/caller-object-id.sh). export E2E_TEST_PRINCIPAL_ID= ``` @@ -101,7 +102,9 @@ export ENABLE_TRAFFIC_MANAGER=true The setup configures the additional AKS identities, Azure role assignments, and controller feature flags required by `test/e2e/traffic_manager_test.go`. Tests in that file skip when -`ENABLE_TRAFFIC_MANAGER` is not `true`. +`ENABLE_TRAFFIC_MANAGER` is not `true`. Because some tests update Traffic Manager endpoints that +target the members' public IPs directly, setup also grants `E2E_TEST_PRINCIPAL_ID` Network +Contributor on both member node resource groups. ### Azure Front Door and Gateway API @@ -798,5 +801,5 @@ Delete only this run's verified resources; the shared resource group remains: make e2e-cleanup ``` -Cleanup requires the same `AZURE_RESOURCE_GROUP`, `E2E_RUN_ID`, `KUBECONFIG` and, for AFD -auto-approval, `E2E_TEST_PRINCIPAL_ID` used by setup. +Cleanup requires the same `AZURE_RESOURCE_GROUP`, `E2E_RUN_ID`, `KUBECONFIG` and, for Traffic +Manager or AFD auto-approval, `E2E_TEST_PRINCIPAL_ID` used by setup. diff --git a/test/scripts/bootstrap.sh b/test/scripts/bootstrap.sh index c9aa91ff..dc67297a 100644 --- a/test/scripts/bootstrap.sh +++ b/test/scripts/bootstrap.sh @@ -24,6 +24,12 @@ if [ "$ENABLE_TRAFFIC_MANAGER" == "true" ] && [ "$AZURE_NETWORK_SETTING" != "sha exit 1 fi +if [[ "$ENABLE_TRAFFIC_MANAGER" == true && + ! "${E2E_TEST_PRINCIPAL_ID:-}" =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ ]]; then + echo "error: Traffic Manager E2E requires E2E_TEST_PRINCIPAL_ID" >&2 + exit 1 +fi + if [[ "$ENABLE_AZURE_FRONT_DOOR" == true ]]; then for tool in az jq helm kubectl go docker; do if ! command -v "$tool" >/dev/null; then @@ -201,6 +207,10 @@ EOF echo "Assigning roles to member-1 kubelet identity on the MC_resourceGroup of the member cluster" az role assignment create --role "Network Contributor" --assignee-object-id ${MEMBER_CLUSTER_1_KUBELET_PRINCIPAL_ID} --assignee-principal-type ServicePrincipal --scope "/subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${AKS_MEMBER_1_NODE_RESOURCE_GROUP}" > /dev/null + # The tests update Traffic Manager endpoints that target this member's public IPs, which requires joining them. + echo "Assigning Network Contributor to the E2E test principal on the MC_resourceGroup of member-1" + az role assignment create --role "Network Contributor" --assignee-object-id "${E2E_TEST_PRINCIPAL_ID}" --assignee-principal-type ServicePrincipal --scope "/subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${AKS_MEMBER_1_NODE_RESOURCE_GROUP}" > /dev/null + # Creating azure configuration file for the controllers echo "Generating azure configuration file:" $(pwd)/member_1_azure_config.yaml cat << EOF > $(pwd)/member_1_azure_config.yaml @@ -223,6 +233,10 @@ EOF echo "Assigning roles to member-2 kubelet identity on the MC_resourceGroup of the member cluster" az role assignment create --role "Network Contributor" --assignee-object-id ${MEMBER_CLUSTER_2_KUBELET_PRINCIPAL_ID} --assignee-principal-type ServicePrincipal --scope "/subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${AKS_MEMBER_2_NODE_RESOURCE_GROUP}" > /dev/null + # The tests update Traffic Manager endpoints that target this member's public IPs, which requires joining them. + echo "Assigning Network Contributor to the E2E test principal on the MC_resourceGroup of member-2" + az role assignment create --role "Network Contributor" --assignee-object-id "${E2E_TEST_PRINCIPAL_ID}" --assignee-principal-type ServicePrincipal --scope "/subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${AKS_MEMBER_2_NODE_RESOURCE_GROUP}" > /dev/null + # Creating azure configuration file for the controllers echo "Generating azure configuration file:" $(pwd)/member_2_azure_config.yaml cat << EOF > $(pwd)/member_2_azure_config.yaml diff --git a/test/scripts/caller-object-id.sh b/test/scripts/caller-object-id.sh new file mode 100755 index 00000000..330bf338 --- /dev/null +++ b/test/scripts/caller-object-id.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Prints the object ID of the principal the Azure CLI is signed in as, read from its ARM access token, +# so that role assignments to the E2E test principal follow the service connection that runs the job. +set -o errexit +set -o nounset +set -o pipefail + +token="$(az account get-access-token --query accessToken -o tsv)" +jq -Rr 'split(".")[1] | gsub("-"; "+") | gsub("_"; "/") | (. + "===") | .[0:(length - (length % 4))] | + @base64d | fromjson | .oid' <<<"$token"