Skip to content

Commit

Permalink
use default cli cred
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiying-lin committed Dec 23, 2024
1 parent 1ed3239 commit 9e9f6a3
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 50 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ 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 @@ -109,9 +108,6 @@ 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 pkg/controllers/hub/trafficmanagerprofile/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *Reconciler) handleUpdate(ctx context.Context, profile *fleetnetv1alpha1
return r.updateProfileStatus(ctx, profile, res.Profile, updateErr)
}

// EqualAzureTrafficManagerProfile compares only few fields of the buildCurrentFunc and desired Azure Traffic Manager profiles
// EqualAzureTrafficManagerProfile compares only few fields of the current 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 {
Expand Down
1 change: 0 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export AZURE_SUBSCRIPTION_ID=<YOUR-SUBSCRIPTION-ID>
# and detailed explanations for each network setting are provided in the scripts under folder "test/scripts".
export AZURE_NETWORK_SETTING=shared-vnet
export ENABLE_TRAFFIC_MANAGER=true
export USE_DEFAULT_AZURE_CLIENTS=true
```

Run Makefile Target to setup e2e environment:
Expand Down
5 changes: 3 additions & 2 deletions test/common/trafficmanager/azureprovider/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ package azureprovider

import (
"context"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/trafficmanager/armtrafficmanager"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
. "github.com/onsi/gomega"

Check failure on line 15 in test/common/trafficmanager/azureprovider/profile.go

View workflow job for this annotation

GitHub Actions / Lint

dot-imports: should not use dot imports (revive)
)

Expand All @@ -29,6 +29,7 @@ type Validator struct {
ResourceGroup string
}

// ValidateProfile validates the traffic manager profile.
func (v *Validator) ValidateProfile(ctx context.Context, name string, want armtrafficmanager.Profile) {
res, err := v.ProfileClient.Get(ctx, v.ResourceGroup, name, nil)
Expect(err).Should(Succeed(), "Failed to get the traffic manager profile")
Expand Down
6 changes: 0 additions & 6 deletions test/e2e/azuretrafficmanager_utils.go

This file was deleted.

40 changes: 6 additions & 34 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ package e2e

import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/trafficmanager/armtrafficmanager"
"go.goms.io/fleet-networking/test/common/trafficmanager/azureprovider"
"os"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/trafficmanager/armtrafficmanager"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
Expand All @@ -26,20 +24,13 @@ import (
fleetv1beta1 "go.goms.io/fleet/apis/cluster/v1beta1"

fleetnetv1alpha1 "go.goms.io/fleet-networking/api/v1alpha1"
"go.goms.io/fleet-networking/test/common/trafficmanager/azureprovider"
"go.goms.io/fleet-networking/test/e2e/framework"
)

const (
// common environments required by both ci pipeline and local development
azureSubscriptionEnv = "AZURE_SUBSCRIPTION_ID"
azureTrafficManagerResourceGroupEnv = "AZURE_RESOURCE_GROUP"

// environments required by the ci pipeline
azureClientIDEnv = "AZURE_CLIENT_ID"
azureTenantIDEnv = "AZURE_TENANT_ID"
federatedTokenEnv = "FED_TOKEN"

useDefaultAzureClientsEnv = "USE_DEFAULT_AZURE_CLIENTS"
)

var (
Expand Down Expand Up @@ -87,6 +78,7 @@ var _ = BeforeSuite(func() {

testNamespace = framework.UniqueTestNamespace()
createTestNamespace(context.Background())

initAzureClients()
})

Expand All @@ -97,29 +89,9 @@ func initAzureClients() {
atmResourceGroup := os.Getenv(azureTrafficManagerResourceGroupEnv)
Expect(atmResourceGroup).ShouldNot(BeEmpty(), "Azure traffic manager resource group is not set")

//createDefaultAzureClients := os.Getenv(useDefaultAzureClientsEnv)
var cred azcore.TokenCredential
var err error
//if createDefaultAzureClients == "true" {
cred, err = azidentity.NewDefaultAzureCredential(nil)
cred, err := azidentity.NewDefaultAzureCredential(nil)
Expect(err).Should(Succeed(), "Failed to obtain default Azure credential")
//} else {
// clientID := os.Getenv(azureClientIDEnv)
// Expect(clientID).ShouldNot(BeEmpty(), "Azure client ID is not set")
// tenantID := os.Getenv(azureTenantIDEnv)
// Expect(tenantID).ShouldNot(BeEmpty(), "Azure tenant ID is not set")
//
// options := &azidentity.ClientAssertionCredentialOptions{}
// cred, err = azidentity.NewClientAssertionCredential(
// tenantID,
// clientID,
// func(ctx context.Context) (string, error) {
// return os.Getenv(federatedTokenEnv), nil
// },
// options,
// )
// Expect(err).Should(Succeed(), "Failed to obtain Azure credential")
//}

clientFactory, err := armtrafficmanager.NewClientFactory(subscriptionID, cred, nil)
Expect(err).Should(Succeed(), "Failed to create client")
atmValidator = &azureprovider.Validator{
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/traffic_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ var (
enabled = os.Getenv("ENABLE_TRAFFIC_MANAGER") == "true"
)

var _ = FDescribe("Test exporting service via Azure traffic manager", func() {
var _ = Describe("Test exporting service via Azure traffic manager", func() {
var wm *framework.WorkloadManager
var profile fleetnetv1alpha1.TrafficManagerProfile
var hubClient client.Client
//var dnsName string

BeforeEach(func() {
if !enabled {
Expand Down

0 comments on commit 9e9f6a3

Please sign in to comment.