Skip to content

Commit

Permalink
test: set azure client for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiying-lin committed Dec 23, 2024
1 parent a3d3bd7 commit bd30225
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 273 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
REQUEST_TOKEN=$ACTIONS_ID_TOKEN_REQUEST_TOKEN
REQUEST_URI=$ACTIONS_ID_TOKEN_REQUEST_URL
FED_TOKEN=$(curl -H "Authorization: bearer $REQUEST_TOKEN" "${REQUEST_URI}&audience=api://AzureADTokenExchange" | jq .value -r)
echo "FED_TOKEN=$FED_TOKEN" >> $GITHUB_ENV
az login --service-principal -u ${{ secrets.E2E_AZURE_CLIENT_ID }} -t ${{ secrets.AZURE_TENANT_ID }} --federated-token $FED_TOKEN --output none
sleep 240
done &
Expand All @@ -108,6 +109,9 @@ jobs:
AZURE_NETWORK_SETTING: ${{ matrix.network-setting }}
AZURE_RESOURCE_GROUP: ${{ env.AZURE_RESOURCE_GROUP }}
ENABLE_TRAFFIC_MANAGER: ${{ matrix.enable-traffic-manager }}
AZURE_CLIENT_ID: ${{ secrets.E2E_AZURE_CLIENT_ID}}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
FED_TOKEN: ${{ env.FED_TOKEN }}
- name: Cleanup e2e
if: always()
run: |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.7

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4 v4.3.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/trafficmanager/armtrafficmanager v1.3.0
github.com/google/go-cmp v0.6.0
Expand All @@ -26,7 +27,6 @@ require go.goms.io/fleet v0.11.4

require (
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.2.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 v5.7.0 // indirect
Expand Down
16 changes: 13 additions & 3 deletions pkg/controllers/hub/trafficmanagerprofile/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const (
DNSRelativeNameFormat = "%s-%s"
// AzureResourceProfileNameFormat is the name format of the Azure Traffic Manager Profile created by the fleet controller.
AzureResourceProfileNameFormat = "fleet-%s"

// DefaultDNSTTL is in seconds. This informs the local DNS resolvers and DNS clients how long to cache DNS responses
// provided by this Traffic Manager profile.
// Defaults to 60 which is the same as the portal's default config.
DefaultDNSTTL = int64(60)
)

var (
Expand Down Expand Up @@ -166,12 +171,12 @@ func (r *Reconciler) handleUpdate(ctx context.Context, profile *fleetnetv1alpha1
return r.updateProfileStatus(ctx, profile, res.Profile, updateErr)
}

// EqualAzureTrafficManagerProfile compares only few fields of the current and desired Azure Traffic Manager profiles
// EqualAzureTrafficManagerProfile compares only few fields of the buildCurrentFunc and desired Azure Traffic Manager profiles
// by ignoring others.
// The desired profile is built by the controllers and all the required fields should not be nil.
func EqualAzureTrafficManagerProfile(current, desired armtrafficmanager.Profile) bool {
// location and dnsConfig is not immutable
if current.Properties == nil || current.Properties.MonitorConfig == nil || current.Properties.ProfileStatus == nil || current.Properties.TrafficRoutingMethod == nil {
// location and dnsConfig (excluding TTL) is not immutable
if current.Properties == nil || current.Properties.MonitorConfig == nil || current.Properties.ProfileStatus == nil || current.Properties.TrafficRoutingMethod == nil || current.Properties.DNSConfig == nil {
return false
}

Expand All @@ -194,6 +199,10 @@ func EqualAzureTrafficManagerProfile(current, desired armtrafficmanager.Profile)
return false
}

if current.Properties.DNSConfig.TTL == nil || *current.Properties.DNSConfig.TTL != *desired.Properties.DNSConfig.TTL {
return false
}

if current.Tags == nil {
return false
}
Expand Down Expand Up @@ -271,6 +280,7 @@ func generateAzureTrafficManagerProfile(profile *fleetnetv1alpha1.TrafficManager
Properties: &armtrafficmanager.ProfileProperties{
DNSConfig: &armtrafficmanager.DNSConfig{
RelativeName: ptr.To(fmt.Sprintf(DNSRelativeNameFormat, profile.Namespace, profile.Name)),
TTL: ptr.To(DefaultDNSTTL), // no default value on the server side, using 60s same as portal's default config
},
MonitorConfig: &armtrafficmanager.MonitorConfig{
IntervalInSeconds: mc.IntervalInSeconds,
Expand Down
Loading

0 comments on commit bd30225

Please sign in to comment.