Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .pipeline/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -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
11 changes: 7 additions & 4 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export AZURE_RESOURCE_GROUP=<YOUR-TEST-RESOURCE-GROUP>
export E2E_RUN_ID=<unique-lowercase-run-id>
# Recommended: use a separate kubeconfig for this run.
export KUBECONFIG=<run-specific-kubeconfig-path>
# 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=<service-principal-object-id>
```

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
42 changes: 28 additions & 14 deletions test/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -342,10 +356,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" )

Expand All @@ -354,18 +368,18 @@ 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 \
--set azure.clientid=$CLIENT_ID_FOR_MEMBER_1 \
$( [ "$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 \
Expand All @@ -378,18 +392,18 @@ 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 \
--set azure.clientid=$CLIENT_ID_FOR_MEMBER_2 \
$( [ "$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 \
Expand All @@ -416,17 +430,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 \
Expand All @@ -437,17 +451,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 \
Expand Down
10 changes: 10 additions & 0 deletions test/scripts/caller-object-id.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading