Skip to content
Open
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: 7 additions & 1 deletion pkg/util/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"k8s.io/apimachinery/pkg/util/wait"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
armsdk "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
Expand Down Expand Up @@ -224,7 +225,12 @@ func New(log *logrus.Entry, conf *ClusterConfig) (*Cluster, error) {

options := azEnvironment.EnvironmentCredentialOptions()

spTokenCredential, err := azidentity.NewEnvironmentCredential(options)
var spTokenCredential azcore.TokenCredential
if os.Getenv("AZURE_TOKEN_CREDENTIALS") != "" {
spTokenCredential, err = azEnvironment.NewTokenCredential()
} else {
spTokenCredential, err = azidentity.NewEnvironmentCredential(options)
}
if err != nil {
return nil, err
}
Expand Down
28 changes: 21 additions & 7 deletions test/e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"sigs.k8s.io/controller-runtime/pkg/client"

"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/msi/armmsi"
"github.com/Azure/go-autorest/autorest/azure"
Expand Down Expand Up @@ -304,9 +305,17 @@ func resourceIDFromEnv() string {
_env.SubscriptionID(), vnetResourceGroup, clusterName)
}

func newClientSet(ctx context.Context) (*clientSet, error) {
func newE2ETokenCredential() (azcore.TokenCredential, error) {
if os.Getenv("AZURE_TOKEN_CREDENTIALS") != "" {
return _env.Environment().NewTokenCredential()
}

options := _env.Environment().EnvironmentCredentialOptions()
tokenCredential, err := azidentity.NewEnvironmentCredential(options)
return azidentity.NewEnvironmentCredential(options)
}

func newClientSet(ctx context.Context) (*clientSet, error) {
tokenCredential, err := newE2ETokenCredential()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -586,15 +595,21 @@ func newClientSet(ctx context.Context) (*clientSet, error) {

func setupE2EInfrastructure(ctx context.Context) error {
if err := env.ValidateVars(
"AZURE_CLIENT_ID",
"AZURE_CLIENT_SECRET",
"AZURE_SUBSCRIPTION_ID",
"AZURE_TENANT_ID",
"CLUSTER",
"LOCATION"); err != nil {
return err
}

if os.Getenv("AZURE_TOKEN_CREDENTIALS") == "" {
if err := env.ValidateVars(
"AZURE_TENANT_ID",
"AZURE_CLIENT_ID",
"AZURE_CLIENT_SECRET"); err != nil {
return fmt.Errorf("AZURE_TOKEN_CREDENTIALS not set, and one or more of AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET is missing: %w", err)
}
}

// Core ARO env
var err error
_env, err = env.NewCoreForCI(ctx, log, env.SERVICE_E2E)
Expand All @@ -609,8 +624,7 @@ func setupE2EInfrastructure(ctx context.Context) error {
}

// Build a bare‐bones Azure SDK client for OpenshiftClusters
credOptions := _env.Environment().EnvironmentCredentialOptions()
tokenCred, err := azidentity.NewEnvironmentCredential(credOptions)
tokenCred, err := newE2ETokenCredential()
if err != nil {
return err
}
Expand Down
Loading