From 68fd92838bbaba6ac5743eacdbd255749ab68542 Mon Sep 17 00:00:00 2001 From: Vighnesh Shenoy Date: Tue, 29 Mar 2022 10:45:11 +0530 Subject: [PATCH 1/2] Non-public cloud support for Azure Data Explorer scaler. Signed-off-by: Vighnesh Shenoy --- pkg/scalers/azure/azure_data_explorer.go | 30 ++++++++++++------- pkg/scalers/azure_data_explorer_scaler.go | 14 ++++++++- .../azure_data_explorer_scaler_test.go | 9 ++++++ 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/pkg/scalers/azure/azure_data_explorer.go b/pkg/scalers/azure/azure_data_explorer.go index ed1f3444031..65102c0dca3 100644 --- a/pkg/scalers/azure/azure_data_explorer.go +++ b/pkg/scalers/azure/azure_data_explorer.go @@ -30,15 +30,16 @@ import ( ) type DataExplorerMetadata struct { - ClientID string - ClientSecret string - DatabaseName string - Endpoint string - MetricName string - PodIdentity string - Query string - TenantID string - Threshold int64 + ClientID string + ClientSecret string + DatabaseName string + Endpoint string + MetricName string + PodIdentity string + Query string + TenantID string + Threshold int64 + ActiveDirectoryEndpoint string } var azureDataExplorerLogger = logf.Log.WithName("azure_data_explorer_scaler") @@ -61,14 +62,21 @@ func getDataExplorerAuthConfig(metadata *DataExplorerMetadata) (*auth.Authorizer var authConfig auth.AuthorizerConfig if metadata.PodIdentity != "" { - authConfig = auth.NewMSIConfig() + config := auth.NewMSIConfig() + config.Resource = metadata.Endpoint azureDataExplorerLogger.V(1).Info("Creating Azure Data Explorer Client using Pod Identity") + + authConfig = config return &authConfig, nil } if metadata.ClientID != "" && metadata.ClientSecret != "" && metadata.TenantID != "" { - authConfig = auth.NewClientCredentialsConfig(metadata.ClientID, metadata.ClientSecret, metadata.TenantID) + config := auth.NewClientCredentialsConfig(metadata.ClientID, metadata.ClientSecret, metadata.TenantID) + config.Resource = metadata.Endpoint + config.AADEndpoint = metadata.ActiveDirectoryEndpoint azureDataExplorerLogger.V(1).Info("Creating Azure Data Explorer Client using clientID, clientSecret and tenantID") + + authConfig = config return &authConfig, nil } diff --git a/pkg/scalers/azure_data_explorer_scaler.go b/pkg/scalers/azure_data_explorer_scaler.go index 35a26cf8613..7b479b73b40 100644 --- a/pkg/scalers/azure_data_explorer_scaler.go +++ b/pkg/scalers/azure_data_explorer_scaler.go @@ -22,6 +22,7 @@ import ( "strconv" "github.com/Azure/azure-kusto-go/kusto" + az "github.com/Azure/go-autorest/autorest/azure" "k8s.io/api/autoscaling/v2beta2" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -103,12 +104,23 @@ func parseAzureDataExplorerMetadata(config *ScalerConfig) (*azure.DataExplorerMe // Generate metricName. metadata.MetricName = GenerateMetricNameWithIndex(config.ScalerIndex, kedautil.NormalizeString(fmt.Sprintf("%s-%s", adxName, metadata.DatabaseName))) + activeDirectoryEndpointProvider := func(env az.Environment) (string, error) { + return env.ActiveDirectoryEndpoint, nil + } + activeDirectoryEndpoint, err := azure.ParseEnvironmentProperty(config.TriggerMetadata, "activeDirectoryEndpoint", activeDirectoryEndpointProvider) + if err != nil { + return nil, err + } + metadata.ActiveDirectoryEndpoint = activeDirectoryEndpoint + dataExplorerLogger.V(1).Info("Parsed azureDataExplorerMetadata", "database", metadata.DatabaseName, "endpoint", metadata.Endpoint, "metricName", metadata.MetricName, "query", metadata.Query, - "threshold", metadata.Threshold) + "threshold", metadata.Threshold, + "activeDirectoryEndpoint", metadata.ActiveDirectoryEndpoint, + ) return metadata, nil } diff --git a/pkg/scalers/azure_data_explorer_scaler_test.go b/pkg/scalers/azure_data_explorer_scaler_test.go index 00c82709f60..432ce71561e 100644 --- a/pkg/scalers/azure_data_explorer_scaler_test.go +++ b/pkg/scalers/azure_data_explorer_scaler_test.go @@ -70,6 +70,15 @@ var testDataExplorerMetadataWithClientAndSecret = []parseDataExplorerMetadataTes {map[string]string{"tenantId": azureTenantID, "clientId": aadAppClientID, "clientSecret": aadAppSecret, "endpoint": dataExplorerEndpoint, "databaseName": databaseName, "query": "", "threshold": dataExplorerThreshold}, true}, // Missing threshold - fail {map[string]string{"tenantId": azureTenantID, "clientId": aadAppClientID, "clientSecret": aadAppSecret, "endpoint": dataExplorerEndpoint, "databaseName": databaseName, "query": dataExplorerQuery, "threshold": ""}, true}, + // known cloud + {map[string]string{"tenantId": azureTenantID, "clientId": aadAppClientID, "clientSecret": aadAppSecret, "endpoint": dataExplorerEndpoint, "databaseName": databaseName, "query": dataExplorerQuery, "threshold": dataExplorerThreshold, + "cloud": "azureChinaCloud"}, false}, + // private cloud + {map[string]string{"tenantId": azureTenantID, "clientId": aadAppClientID, "clientSecret": aadAppSecret, "endpoint": dataExplorerEndpoint, "databaseName": databaseName, "query": dataExplorerQuery, "threshold": dataExplorerThreshold, + "cloud": "private", "activeDirectoryEndpoint": activeDirectoryEndpoint}, false}, + // private cloud - missing active directory endpoint - fail + {map[string]string{"tenantId": azureTenantID, "clientId": aadAppClientID, "clientSecret": aadAppSecret, "endpoint": dataExplorerEndpoint, "databaseName": databaseName, "query": dataExplorerQuery, "threshold": dataExplorerThreshold, + "cloud": "private"}, true}, // All parameters set - pass {map[string]string{"tenantId": azureTenantID, "clientId": aadAppClientID, "clientSecret": aadAppSecret, "endpoint": dataExplorerEndpoint, "databaseName": databaseName, "query": dataExplorerQuery, "threshold": dataExplorerThreshold}, false}, } From d3531e45e9cca20870ab4da0f8b48073e418828f Mon Sep 17 00:00:00 2001 From: Vighnesh Shenoy Date: Tue, 29 Mar 2022 10:51:52 +0530 Subject: [PATCH 2/2] Update changelog. Signed-off-by: Vighnesh Shenoy --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc049c06a6f..3370a9bd195 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ ### New - **General:** Introduce new AWS DynamoDB Scaler ([#2486](https://github.com/kedacore/keda/issues/2482)) -- **General:** Introduce new Azure Data Explorer Scaler ([#1488](https://github.com/kedacore/keda/issues/1488)) +- **General:** Introduce new Azure Data Explorer Scaler ([#1488](https://github.com/kedacore/keda/issues/1488)|[#2734](https://github.com/kedacore/keda/issues/2734)) - **General:** Introduce new GCP Stackdriver Scaler ([#2661](https://github.com/kedacore/keda/issues/2661)) - **General:** Introduce new GCP Storage Scaler ([#2628](https://github.com/kedacore/keda/issues/2628)) - **General:** Introduce ARM-based container image for KEDA ([#2263](https://github.com/kedacore/keda/issues/2263)|[#2262](https://github.com/kedacore/keda/issues/2262))