Skip to content
New issue

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

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

Already on GitHub? # to your account

Non-public cloud support for Azure Data Explorer scaler. #2839

Merged
merged 2 commits into from
Mar 29, 2022
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
30 changes: 19 additions & 11 deletions pkg/scalers/azure/azure_data_explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}

Expand Down
14 changes: 13 additions & 1 deletion pkg/scalers/azure_data_explorer_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/scalers/azure_data_explorer_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand Down