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

Remove unused function setCredentials #4208

Merged
merged 1 commit into from
Dec 18, 2023
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
31 changes: 0 additions & 31 deletions azure/scope/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/Azure/go-autorest/autorest"
azureautorest "github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/azure/auth"
azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure"
)

// AzureClients contains all the Azure clients used by the scopes.
Expand Down Expand Up @@ -80,36 +79,6 @@ func (c *AzureClients) HashKey() string {
return base64.URLEncoding.EncodeToString(hasher.Sum(nil))
}

func (c *AzureClients) setCredentials(subscriptionID, environmentName string) error {
settings, err := c.getSettingsFromEnvironment(environmentName)
if err != nil {
return err
}

if subscriptionID == "" {
subscriptionID = settings.GetSubscriptionID()
if subscriptionID == "" {
return fmt.Errorf("error creating azure services. subscriptionID is not set in cluster or AZURE_SUBSCRIPTION_ID env var")
}
}

c.EnvironmentSettings = settings
c.ResourceManagerEndpoint = settings.Environment.ResourceManagerEndpoint
c.ResourceManagerVMDNSSuffix = settings.Environment.ResourceManagerVMDNSSuffix
c.Values[auth.ClientID] = strings.TrimSuffix(c.Values[auth.ClientID], "\n")
c.Values[auth.ClientSecret] = strings.TrimSuffix(c.Values[auth.ClientSecret], "\n")
c.Values[auth.SubscriptionID] = strings.TrimSuffix(subscriptionID, "\n")
c.Values[auth.TenantID] = strings.TrimSuffix(c.Values[auth.TenantID], "\n")

if c.Authorizer == nil {
c.Authorizer, err = azureutil.GetAuthorizer(settings)
if err != nil {
return err
}
}
return nil
}

func (c *AzureClients) setCredentialsWithProvider(ctx context.Context, subscriptionID, environmentName string, credentialsProvider CredentialsProvider) error {
if credentialsProvider == nil {
return fmt.Errorf("credentials provider cannot have an empty value")
Expand Down
81 changes: 0 additions & 81 deletions azure/scope/clients_test.go

This file was deleted.

21 changes: 7 additions & 14 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,13 @@
return nil, errors.New("failed to generate new scope from nil AzureCluster")
}

if params.AzureCluster.Spec.IdentityRef == nil {
err := params.AzureClients.setCredentials(params.AzureCluster.Spec.SubscriptionID, params.AzureCluster.Spec.AzureEnvironment)
if err != nil {
return nil, errors.Wrap(err, "failed to configure azure settings and credentials from environment")
}
} else {
credentialsProvider, err := NewAzureClusterCredentialsProvider(ctx, params.Client, params.AzureCluster)
if err != nil {
return nil, errors.Wrap(err, "failed to init credentials provider")
}
err = params.AzureClients.setCredentialsWithProvider(ctx, params.AzureCluster.Spec.SubscriptionID, params.AzureCluster.Spec.AzureEnvironment, credentialsProvider)
if err != nil {
return nil, errors.Wrap(err, "failed to configure azure settings and credentials for Identity")
}
credentialsProvider, err := NewAzureClusterCredentialsProvider(ctx, params.Client, params.AzureCluster)
if err != nil {
return nil, errors.Wrap(err, "failed to init credentials provider")
}

Check warning on line 81 in azure/scope/cluster.go

View check run for this annotation

Codecov / codecov/patch

azure/scope/cluster.go#L80-L81

Added lines #L80 - L81 were not covered by tests
err = params.AzureClients.setCredentialsWithProvider(ctx, params.AzureCluster.Spec.SubscriptionID, params.AzureCluster.Spec.AzureEnvironment, credentialsProvider)
if err != nil {
return nil, errors.Wrap(err, "failed to configure azure settings and credentials for Identity")

Check warning on line 84 in azure/scope/cluster.go

View check run for this annotation

Codecov / codecov/patch

azure/scope/cluster.go#L84

Added line #L84 was not covered by tests
}

if params.Cache == nil {
Expand Down
Loading