Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Replace last usage of Azure/go-autorest #4780

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
14 changes: 6 additions & 8 deletions azure/scope/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
azureautorest "github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/azure/auth"
)

// AzureClients contains all the Azure clients used by the scopes.
type AzureClients struct {
auth.EnvironmentSettings
EnvironmentSettings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused about how we were really using this type before if not just to store data. Isn't this a SDKv1 construct, and presumably not usable with SDKv2? Should we be utilizing this instead? https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/[email protected]/cloud

Copy link
Contributor Author

@mboersma mboersma Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also confused; AFAICT we've just been using this as an environment variable container and I've tried to keep the usages intact so as not to break things, but it may all amount to a no-op honestly.

Let me look more closely at Configuration and see if it's a more functional replacement for this go-autorest code path. Thanks @nojnhuh!


TokenCredential azcore.TokenCredential
ResourceManagerEndpoint string
Expand Down Expand Up @@ -115,8 +113,8 @@ func (c *AzureClients) setCredentialsWithProvider(ctx context.Context, subscript
return err
}

func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s auth.EnvironmentSettings, err error) {
s = auth.EnvironmentSettings{
func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s EnvironmentSettings, err error) {
s = EnvironmentSettings{
Values: map[string]string{},
}
s.Values["AZURE_ENVIRONMENT"] = environmentName
Expand All @@ -131,9 +129,9 @@ func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s aut
setValue(s, "AZURE_PASSWORD")
setValue(s, "AZURE_AD_RESOURCE")
if v := s.Values["AZURE_ENVIRONMENT"]; v == "" {
s.Environment = azureautorest.PublicCloud
s.Environment = PublicCloud
} else {
s.Environment, err = azureautorest.EnvironmentFromName(v)
s.Environment, err = EnvironmentFromName(v)
}
if s.Values["AZURE_AD_RESOURCE"] == "" {
s.Values["AZURE_AD_RESOURCE"] = s.Environment.ResourceManagerEndpoint
Expand All @@ -142,7 +140,7 @@ func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s aut
}

// setValue adds the specified environment variable value to the Values map if it exists.
func setValue(settings auth.EnvironmentSettings, key string) {
func setValue(settings EnvironmentSettings, key string) {
if v := os.Getenv(key); v != "" {
settings.Values[key] = v
}
Expand Down
25 changes: 12 additions & 13 deletions azure/scope/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
asonetworkv1api20201101 "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101"
asonetworkv1api20220701 "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701"
asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/google/go-cmp/cmp"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -958,9 +957,9 @@ func TestNatGatewaySpecs(t *testing.T) {
},
},
AzureClients: AzureClients{
EnvironmentSettings: auth.EnvironmentSettings{
EnvironmentSettings: EnvironmentSettings{
Values: map[string]string{
auth.SubscriptionID: "123",
"AZURE_SUBSCRIPTION_ID": "123",
},
},
},
Expand Down Expand Up @@ -1022,9 +1021,9 @@ func TestNatGatewaySpecs(t *testing.T) {
},
},
AzureClients: AzureClients{
EnvironmentSettings: auth.EnvironmentSettings{
EnvironmentSettings: EnvironmentSettings{
Values: map[string]string{
auth.SubscriptionID: "123",
"AZURE_SUBSCRIPTION_ID": "123",
},
},
},
Expand Down Expand Up @@ -1104,9 +1103,9 @@ func TestNatGatewaySpecs(t *testing.T) {
},
},
AzureClients: AzureClients{
EnvironmentSettings: auth.EnvironmentSettings{
EnvironmentSettings: EnvironmentSettings{
Values: map[string]string{
auth.SubscriptionID: "123",
"AZURE_SUBSCRIPTION_ID": "123",
},
},
},
Expand Down Expand Up @@ -1377,9 +1376,9 @@ func TestSubnetSpecs(t *testing.T) {
},
},
AzureClients: AzureClients{
EnvironmentSettings: auth.EnvironmentSettings{
EnvironmentSettings: EnvironmentSettings{
Values: map[string]string{
auth.SubscriptionID: "123",
"AZURE_SUBSCRIPTION_ID": "123",
},
},
},
Expand Down Expand Up @@ -1456,9 +1455,9 @@ func TestSubnetSpecs(t *testing.T) {
},
},
AzureClients: AzureClients{
EnvironmentSettings: auth.EnvironmentSettings{
EnvironmentSettings: EnvironmentSettings{
Values: map[string]string{
auth.SubscriptionID: "123",
"AZURE_SUBSCRIPTION_ID": "123",
},
},
},
Expand Down Expand Up @@ -1719,9 +1718,9 @@ func TestAzureBastionSpec(t *testing.T) {
},
},
AzureClients: AzureClients{
EnvironmentSettings: auth.EnvironmentSettings{
EnvironmentSettings: EnvironmentSettings{
Values: map[string]string{
auth.SubscriptionID: "123",
"AZURE_SUBSCRIPTION_ID": "123",
},
},
},
Expand Down
Loading