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

fix: change way of returns service bus namespace object #4273

Merged
merged 3 commits into from
Feb 23, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Here is an overview of all new **experimental** features:
- **General**: Fix regression in fallback mechanism ([#4249](https://github.com/kedacore/keda/issues/4249))
- **General**: Prevent a panic that might occur while refreshing a scaler cache ([#4092](https://github.com/kedacore/keda/issues/4092))
- **Azure Service Bus Scaler:** Use correct auth flows with pod identity ([#4026](https://github.com/kedacore/keda/issues/4026)|[#4123](https://github.com/kedacore/keda/issues/4123))
- **Azure Service Bus Scaler:**: Change way of get service bus namespace ([#4262](https://github.com/kedacore/keda/issues/4262))
- **Cassandra Scaler**: Checking whether the port information is entered in the ClusterIPAddres is done correctly. ([#4110](https://github.com/kedacore/keda/issues/4110))
- **CPU Memory Scaler** Store forgotten logger ([#4022](https://github.com/kedacore/keda/issues/4022))
- **Datadog Scaler**: Return correct error when getting a 429 error ([#4187](https://github.com/kedacore/keda/issues/4187))
Expand Down
19 changes: 12 additions & 7 deletions pkg/scalers/azure_servicebus_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,23 @@ func (s *azureServiceBusScaler) getServiceBusAdminClient() (*admin.Client, error
if s.client != nil {
return s.client, nil
}

var err error
var client *admin.Client
switch s.podIdentity.Provider {
case "", kedav1alpha1.PodIdentityProviderNone:
return admin.NewClientFromConnectionString(s.metadata.connection, nil)
client, err = admin.NewClientFromConnectionString(s.metadata.connection, nil)
case kedav1alpha1.PodIdentityProviderAzure, kedav1alpha1.PodIdentityProviderAzureWorkload:
creds, err := azure.NewChainedCredential(s.podIdentity.IdentityID, s.podIdentity.Provider)
if err != nil {
return nil, err
creds, chainedErr := azure.NewChainedCredential(s.podIdentity.IdentityID, s.podIdentity.Provider)
if chainedErr != nil {
return nil, chainedErr
}
return admin.NewClient(s.metadata.fullyQualifiedNamespace, creds, nil)
client, err = admin.NewClient(s.metadata.fullyQualifiedNamespace, creds, nil)
default:
err = fmt.Errorf("incorrect podIdentity type")
}
return nil, fmt.Errorf("incorrect podIdentity type")

s.client = client
return client, err
}

func getQueueLength(ctx context.Context, adminClient *admin.Client, meta *azureServiceBusMetadata) (int64, error) {
Expand Down
19 changes: 19 additions & 0 deletions pkg/scalers/azure_servicebus_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"

"github.com/go-logr/logr"
"github.com/stretchr/testify/assert"

kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
)
Expand Down Expand Up @@ -189,6 +190,24 @@ func TestParseServiceBusMetadata(t *testing.T) {
}
}

func TestGetServiceBusAdminClientIsCached(t *testing.T) {
testData := azServiceBusMetricIdentifiers[0]
meta, err := parseAzureServiceBusMetadata(&ScalerConfig{ResolvedEnv: connectionResolvedEnv,
TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams,
PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.metadataTestData.podIdentity}, ScalerIndex: testData.scalerIndex},
logr.Discard())
if err != nil {
t.Fatal("Could not parse metadata:", err)
}
mockAzServiceBusScalerScaler := azureServiceBusScaler{
metadata: meta,
podIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.metadataTestData.podIdentity},
}

_, _ = mockAzServiceBusScalerScaler.getServiceBusAdminClient()
assert.NotNil(t, mockAzServiceBusScalerScaler.client)
}

func TestGetServiceBusLength(t *testing.T) {
t.Log("This test will use the environment variable SERVICEBUS_CONNECTION_STRING if it is set")
t.Log("If set, it will connect to the servicebus namespace specified by the connection string & check:")
Expand Down