From aea0f6da38430265d0529a0f4e75ff6bd32c501f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xo=C3=A1n=20Mall=C3=B3n?= Date: Thu, 23 Feb 2023 17:20:24 +0100 Subject: [PATCH 1/3] fix: change way of returns service bus namespace object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Xoán Mallón --- pkg/scalers/azure_servicebus_scaler.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/scalers/azure_servicebus_scaler.go b/pkg/scalers/azure_servicebus_scaler.go index f72a760c4f8..977d60b4c9b 100755 --- a/pkg/scalers/azure_servicebus_scaler.go +++ b/pkg/scalers/azure_servicebus_scaler.go @@ -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) { From cc793fa09ac115c3270e485a09eb93ea8956cb3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xo=C3=A1n=20Mall=C3=B3n?= Date: Thu, 23 Feb 2023 17:25:09 +0100 Subject: [PATCH 2/3] fix: add necessary update in CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Xoán Mallón --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cfeef54976..af6a936ad1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) From 2e8d081b5053f20816afc866d0971dfb8b2d2449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xo=C3=A1n=20Mall=C3=B3n?= Date: Thu, 23 Feb 2023 18:22:26 +0100 Subject: [PATCH 3/3] fix: add test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Xoán Mallón --- pkg/scalers/azure_servicebus_scaler_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/scalers/azure_servicebus_scaler_test.go b/pkg/scalers/azure_servicebus_scaler_test.go index fea6e6c242e..72b36f9e6ed 100755 --- a/pkg/scalers/azure_servicebus_scaler_test.go +++ b/pkg/scalers/azure_servicebus_scaler_test.go @@ -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" ) @@ -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:")