From 520be7adba10f07340ddf483f917d7640f636257 Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik Date: Tue, 16 Jan 2024 11:29:22 +0100 Subject: [PATCH] chore: refactor `scalers` package and move `ScalersConfig` Signed-off-by: Zbynek Roubalik --- .golangci.yml | 3 + CHANGELOG.md | 1 + apis/keda/v1alpha1/zz_generated.deepcopy.go | 1 - controllers/keda/hpa_test.go | 5 +- .../keda/scaledobject_controller_test.go | 13 ++-- go.mod | 6 +- go.sum | 41 +++++++++-- pkg/metricsservice/api/metrics.pb.go | 2 +- pkg/metricsservice/api/metrics_grpc.pb.go | 2 +- pkg/scalers/activemq_scaler.go | 5 +- pkg/scalers/activemq_scaler_test.go | 14 ++-- pkg/scalers/apache_kafka_scaler.go | 7 +- pkg/scalers/apache_kafka_scaler_test.go | 12 ++-- pkg/scalers/arangodb_scaler.go | 5 +- pkg/scalers/arangodb_scaler_test.go | 8 ++- pkg/scalers/artemis_scaler.go | 5 +- pkg/scalers/artemis_scaler_test.go | 14 ++-- pkg/scalers/aws_cloudwatch_scaler.go | 5 +- pkg/scalers/aws_cloudwatch_scaler_test.go | 5 +- pkg/scalers/aws_dynamodb_scaler.go | 5 +- pkg/scalers/aws_dynamodb_scaler_test.go | 3 +- pkg/scalers/aws_dynamodb_streams_scaler.go | 5 +- .../aws_dynamodb_streams_scaler_test.go | 5 +- pkg/scalers/aws_kinesis_stream_scaler.go | 5 +- pkg/scalers/aws_kinesis_stream_scaler_test.go | 5 +- pkg/scalers/aws_sqs_queue_scaler.go | 5 +- pkg/scalers/aws_sqs_queue_scaler_test.go | 8 ++- pkg/scalers/azure_app_insights_scaler.go | 8 +-- pkg/scalers/azure_app_insights_scaler_test.go | 59 +++++++-------- pkg/scalers/azure_blob_scaler.go | 5 +- pkg/scalers/azure_blob_scaler_test.go | 5 +- pkg/scalers/azure_data_explorer_scaler.go | 7 +- .../azure_data_explorer_scaler_test.go | 9 +-- pkg/scalers/azure_eventhub_scaler.go | 9 +-- pkg/scalers/azure_eventhub_scaler_test.go | 9 +-- pkg/scalers/azure_log_analytics_scaler.go | 7 +- .../azure_log_analytics_scaler_test.go | 15 ++-- pkg/scalers/azure_monitor_scaler.go | 7 +- pkg/scalers/azure_monitor_scaler_test.go | 5 +- pkg/scalers/azure_pipelines_scaler.go | 9 +-- pkg/scalers/azure_pipelines_scaler_test.go | 8 ++- pkg/scalers/azure_queue_scaler.go | 5 +- pkg/scalers/azure_queue_scaler_test.go | 5 +- pkg/scalers/azure_servicebus_scaler.go | 5 +- pkg/scalers/azure_servicebus_scaler_test.go | 7 +- pkg/scalers/cassandra_scaler.go | 5 +- pkg/scalers/cassandra_scaler_test.go | 6 +- pkg/scalers/couchdb_scaler.go | 5 +- pkg/scalers/couchdb_scaler_test.go | 6 +- pkg/scalers/cpu_memory_scaler.go | 6 +- pkg/scalers/cpu_memory_scaler_test.go | 12 ++-- pkg/scalers/cron_scaler.go | 5 +- pkg/scalers/cron_scaler_test.go | 14 ++-- pkg/scalers/datadog_scaler.go | 7 +- pkg/scalers/datadog_scaler_test.go | 6 +- pkg/scalers/elasticsearch_scaler.go | 9 +-- pkg/scalers/elasticsearch_scaler_test.go | 10 +-- pkg/scalers/etcd_scaler.go | 7 +- pkg/scalers/etcd_scaler_test.go | 8 ++- pkg/scalers/external_mock_scaler.go | 4 +- pkg/scalers/external_scaler.go | 7 +- pkg/scalers/external_scaler_test.go | 5 +- .../externalscaler/externalscaler.pb.go | 2 +- .../externalscaler/externalscaler_grpc.pb.go | 2 +- pkg/scalers/{ => gcp}/gcp_common.go | 33 ++++----- .../{ => gcp}/gcp_stackdriver_client.go | 16 ++--- .../{ => gcp}/gcp_stackdriver_client_test.go | 4 +- pkg/scalers/gcp_cloud_tasks_scaler.go | 22 +++--- pkg/scalers/gcp_cloud_tasks_scaler_test.go | 6 +- pkg/scalers/gcp_pubsub_scaler.go | 24 ++++--- pkg/scalers/gcp_pubsub_scaler_test.go | 10 +-- pkg/scalers/gcp_stackdriver_scaler.go | 28 ++++---- pkg/scalers/gcp_stackdriver_scaler_test.go | 6 +- pkg/scalers/gcp_storage_scaler.go | 12 ++-- pkg/scalers/gcp_storage_scaler_test.go | 6 +- pkg/scalers/github_runner_scaler.go | 9 +-- pkg/scalers/github_runner_scaler_test.go | 8 ++- pkg/scalers/graphite_scaler.go | 5 +- pkg/scalers/graphite_scaler_test.go | 8 ++- pkg/scalers/huawei_cloudeye_scaler.go | 5 +- pkg/scalers/huawei_cloudeye_scaler_test.go | 6 +- pkg/scalers/ibmmq_scaler.go | 5 +- pkg/scalers/ibmmq_scaler_test.go | 8 ++- pkg/scalers/influxdb_scaler.go | 5 +- pkg/scalers/influxdb_scaler_test.go | 6 +- .../kafka_scaler_oauth_token_provider.go | 18 ++++- pkg/scalers/{ => kafka}/kafka_scram_client.go | 18 ++++- pkg/scalers/kafka_scaler.go | 20 +++--- pkg/scalers/kafka_scaler_test.go | 16 +++-- pkg/scalers/kubernetes_workload_scaler.go | 5 +- .../kubernetes_workload_scaler_test.go | 10 +-- pkg/scalers/liiklus/LiiklusService.pb.go | 2 +- pkg/scalers/liiklus/LiiklusService_grpc.pb.go | 2 +- pkg/scalers/liiklus_scaler.go | 5 +- pkg/scalers/liiklus_scaler_test.go | 9 +-- pkg/scalers/loki_scaler.go | 8 +-- pkg/scalers/loki_scaler_test.go | 6 +- pkg/scalers/metrics_api_scaler.go | 5 +- pkg/scalers/metrics_api_scaler_test.go | 10 +-- pkg/scalers/mongo_scaler.go | 5 +- pkg/scalers/mongo_scaler_test.go | 8 ++- pkg/scalers/mssql_scaler.go | 6 +- pkg/scalers/mssql_scaler_test.go | 6 +- pkg/scalers/mysql_scaler.go | 5 +- pkg/scalers/mysql_scaler_test.go | 10 +-- pkg/scalers/nats_jetstream_scaler.go | 5 +- pkg/scalers/nats_jetstream_scaler_test.go | 36 +++++----- pkg/scalers/newrelic_scaler.go | 5 +- pkg/scalers/newrelic_scaler_test.go | 6 +- pkg/scalers/openstack_metrics_scaler.go | 7 +- pkg/scalers/openstack_metrics_scaler_test.go | 9 +-- pkg/scalers/openstack_swift_scaler.go | 7 +- pkg/scalers/openstack_swift_scaler_test.go | 10 +-- pkg/scalers/postgresql_scaler.go | 5 +- pkg/scalers/postgresql_scaler_test.go | 8 ++- pkg/scalers/predictkube_scaler.go | 5 +- pkg/scalers/predictkube_scaler_test.go | 8 ++- pkg/scalers/prometheus_scaler.go | 15 ++-- pkg/scalers/prometheus_scaler_test.go | 19 ++--- pkg/scalers/pulsar_scaler.go | 5 +- pkg/scalers/pulsar_scaler_test.go | 26 +++---- pkg/scalers/rabbitmq_scaler.go | 17 ++--- pkg/scalers/rabbitmq_scaler_test.go | 19 ++--- pkg/scalers/redis_scaler.go | 7 +- pkg/scalers/redis_scaler_test.go | 10 +-- pkg/scalers/redis_streams_scaler.go | 5 +- pkg/scalers/redis_streams_scaler_test.go | 16 +++-- pkg/scalers/scaler.go | 57 ++------------- pkg/scalers/scaler_test.go | 14 ++-- pkg/scalers/scalersconfig/scalersconfig.go | 71 +++++++++++++++++++ pkg/scalers/selenium_grid_scaler.go | 5 +- pkg/scalers/selenium_grid_scaler_test.go | 24 ++++--- pkg/scalers/solace_scaler.go | 7 +- pkg/scalers/solace_scaler_test.go | 10 +-- pkg/scalers/solr_scaler.go | 5 +- pkg/scalers/solr_scaler_test.go | 6 +- pkg/scalers/stan_scaler.go | 5 +- pkg/scalers/stan_scaler_test.go | 6 +- pkg/scaling/cache/scalers_cache.go | 9 +-- pkg/scaling/scale_handler.go | 7 +- pkg/scaling/scale_handler_test.go | 65 ++++++++--------- pkg/scaling/scalers_builder.go | 7 +- .../aws/aws-sdk-go-v2/aws/config.go | 3 +- .../aws-sdk-go-v2/aws/go_module_metadata.go | 2 +- .../aws/aws-sdk-go-v2/aws/retry/middleware.go | 6 +- .../internal/configsources/CHANGELOG.md | 4 ++ .../configsources/go_module_metadata.go | 2 +- .../endpoints/awsrulesfn/partitions.json | 3 + .../internal/endpoints/v2/CHANGELOG.md | 4 ++ .../endpoints/v2/go_module_metadata.go | 2 +- vendor/modules.txt | 6 +- 151 files changed, 882 insertions(+), 609 deletions(-) rename pkg/scalers/{ => gcp}/gcp_common.go (55%) rename pkg/scalers/{ => gcp}/gcp_stackdriver_client.go (97%) rename pkg/scalers/{ => gcp}/gcp_stackdriver_client_test.go (98%) rename pkg/scalers/{ => kafka}/kafka_scaler_oauth_token_provider.go (59%) rename pkg/scalers/{ => kafka}/kafka_scram_client.go (64%) create mode 100644 pkg/scalers/scalersconfig/scalersconfig.go diff --git a/.golangci.yml b/.golangci.yml index ba682478178..17b9c182e99 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -55,6 +55,8 @@ issues: linters: - gomnd - dupl + - revive + - goconst - path: scalers_builder.go linters: - gocyclo @@ -146,6 +148,7 @@ issues: - path: controllers/keda/scaledobject_controller_test.go linters: - depguard + - goconst - path: pkg/scalers/external_scaler_test.go linters: - depguard diff --git a/CHANGELOG.md b/CHANGELOG.md index adbdf421037..13e44d3206a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,6 +164,7 @@ New deprecation(s): - **General**: Improve docker image build time through caches ([#5316](https://github.com/kedacore/keda/issues/5316)) - **General**: Reduce amount of gauge creations for OpenTelemetry metrics ([#5101](https://github.com/kedacore/keda/issues/5101)) - **General**: Removed not required RBAC permissions ([#5261](https://github.com/kedacore/keda/issues/5261)) +- **General**: Refactor `scalers` package ([#5379](https://github.com/kedacore/keda/issues/5379)) - **General**: Support profiling for KEDA components ([#4789](https://github.com/kedacore/keda/issues/4789)) - **CPU scaler**: Wait for metrics window during CPU scaler tests ([#5294](https://github.com/kedacore/keda/pull/5294)) - **Hashicorp Vault**: Improve test coverage in `pkg/scaling/resolver/hashicorpvault_handler` ([#5195](https://github.com/kedacore/keda/issues/5195)) diff --git a/apis/keda/v1alpha1/zz_generated.deepcopy.go b/apis/keda/v1alpha1/zz_generated.deepcopy.go index 7903091dc2f..46af93efa0e 100755 --- a/apis/keda/v1alpha1/zz_generated.deepcopy.go +++ b/apis/keda/v1alpha1/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2024 The KEDA Authors diff --git a/controllers/keda/hpa_test.go b/controllers/keda/hpa_test.go index 06292a5489d..ef2f780784b 100644 --- a/controllers/keda/hpa_test.go +++ b/controllers/keda/hpa_test.go @@ -31,6 +31,7 @@ import ( mock_scalers "github.com/kedacore/keda/v2/pkg/mock/mock_scaler" "github.com/kedacore/keda/v2/pkg/mock/mock_scaling" "github.com/kedacore/keda/v2/pkg/scalers" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/scaling/cache" ) @@ -133,8 +134,8 @@ func setupTest(health map[string]v1alpha1.HealthStatus, scaler *mock_scalers.Moc scalersCache := cache.ScalersCache{ Scalers: []cache.ScalerBuilder{{ Scaler: scaler, - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { - return scaler, &scalers.ScalerConfig{}, nil + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { + return scaler, &scalersconfig.ScalerConfig{}, nil }, }}, Recorder: nil, diff --git a/controllers/keda/scaledobject_controller_test.go b/controllers/keda/scaledobject_controller_test.go index b95f4f77f7a..e9266adf7cf 100644 --- a/controllers/keda/scaledobject_controller_test.go +++ b/controllers/keda/scaledobject_controller_test.go @@ -38,6 +38,7 @@ import ( "github.com/kedacore/keda/v2/pkg/mock/mock_client" "github.com/kedacore/keda/v2/pkg/mock/mock_scaling" "github.com/kedacore/keda/v2/pkg/scalers" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/scaling/cache" "github.com/kedacore/keda/v2/pkg/util" ) @@ -81,7 +82,7 @@ var _ = Describe("ScaledObjectController", func() { expectedExternalMetricNames := make([]string, 0) for i, tm := range triggerMeta { - config := &scalers.ScalerConfig{ + config := &scalersconfig.ScalerConfig{ ScalableObjectName: fmt.Sprintf("test.%d", i), ScalableObjectNamespace: "test", TriggerMetadata: tm, @@ -97,7 +98,7 @@ var _ = Describe("ScaledObjectController", func() { testScalers = append(testScalers, cache.ScalerBuilder{ Scaler: s, - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { scaler, err := scalers.NewPrometheusScaler(config) return scaler, config, err }, @@ -133,7 +134,7 @@ var _ = Describe("ScaledObjectController", func() { // Generate test data expectedExternalMetricNames := make([]string, 0) - config := &scalers.ScalerConfig{ + config := &scalersconfig.ScalerConfig{ ScalableObjectName: "test", ScalableObjectNamespace: "test", TriggerMetadata: triggerMeta[0], @@ -154,7 +155,7 @@ var _ = Describe("ScaledObjectController", func() { scalersCache := cache.ScalersCache{ Scalers: []cache.ScalerBuilder{{ Scaler: s, - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { return s, config, nil }, }}, @@ -183,7 +184,7 @@ var _ = Describe("ScaledObjectController", func() { // Generate test data testScalers := make([]cache.ScalerBuilder, 0) for i := 0; i < 4; i++ { - config := &scalers.ScalerConfig{ + config := &scalersconfig.ScalerConfig{ ScalableObjectName: fmt.Sprintf("test.%d", i), ScalableObjectNamespace: "test", TriggerMetadata: triggerMeta[0], @@ -198,7 +199,7 @@ var _ = Describe("ScaledObjectController", func() { testScalers = append(testScalers, cache.ScalerBuilder{ Scaler: s, - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { return s, config, nil }, }) diff --git a/go.mod b/go.mod index 6d9c1cf2ad7..97c837d3d48 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/Huawei/gophercloud v1.0.21 github.com/IBM/sarama v1.42.1 github.com/arangodb/go-driver v1.6.1 - github.com/aws/aws-sdk-go-v2 v1.24.0 + github.com/aws/aws-sdk-go-v2 v1.24.1 github.com/aws/aws-sdk-go-v2/config v1.26.2 github.com/aws/aws-sdk-go-v2/credentials v1.16.13 github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.32.1 @@ -175,8 +175,8 @@ require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.10 // indirect diff --git a/go.sum b/go.sum index 052ea420ce0..f4d23df20eb 100644 --- a/go.sum +++ b/go.sum @@ -910,11 +910,12 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/aws/aws-sdk-go-v2 v1.16.12/go.mod h1:C+Ym0ag2LIghJbXhfXZ0YEEp49rBWowxKzJLUoob0ts= -github.com/aws/aws-sdk-go-v2 v1.24.0 h1:890+mqQ+hTpNuw0gGP6/4akolQkSToDJgHfQE7AwGuk= -github.com/aws/aws-sdk-go-v2 v1.24.0/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4= +github.com/aws/aws-sdk-go-v2 v1.24.1 h1:xAojnj+ktS95YZlDf0zxWBkbFtymPeDP+rvUQIH3uAU= +github.com/aws/aws-sdk-go-v2 v1.24.1/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 h1:OCs21ST2LrepDfD3lwlQiOqIGp6JiEUqG84GzTDoyJs= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4/go.mod h1:usURWEKSNNAcAZuzRn/9ZYPT8aZQkR7xcCtunK/LkJo= github.com/aws/aws-sdk-go-v2/config v1.17.2/go.mod h1:jumS/AMwul4WaG8vyXsF6kUndG9zndR+yfYBwl4i9ds= @@ -927,11 +928,11 @@ github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.13/go.mod h1:y0eXmsNBFIVjUE8 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 h1:w98BT5w+ao1/r5sUuiH6JkVzjowOKeOJRHERyy1vh58= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10/go.mod h1:K2WGI7vUvkIv1HoNbfBA1bvIZ+9kL3YVmWxeKuLQsiw= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.19/go.mod h1:llxE6bwUZhuCas0K7qGiu5OgMis3N7kdWtFSxoHmJ7E= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 h1:v+HbZaCGmOwnTTVS86Fleq0vPzOd7tnJGbFhP0stNLs= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9/go.mod h1:Xjqy+Nyj7VDLBtCMkQYOw1QYfAEZCVLrfI0ezve8wd4= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 h1:vF+Zgd9s+H4vOXd5BMaPWykta2a6Ih0AKLq/X6NYKn4= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10/go.mod h1:6BkRjejp/GR4411UGqkX8+wFMbFbqsUIimfK4XjOKR4= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.13/go.mod h1:lB12mkZqCSo5PsdBFLNqc2M/OOYgNAy8UtaktyuWvE8= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 h1:N94sVhRACtXyVcjXxrwK1SKFIJrA9pOJ5yu2eSHnmls= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9/go.mod h1:hqamLz7g1/4EJP+GH5NBhcUMLjW+gKLQabgyz6/7WAU= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 h1:nYPe006ktcqUji8S2mqXf9c/7NdiKriOwMvWQHgYztw= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10/go.mod h1:6UV4SZkVvmODfXKql4LCbaZUpF7HO2BX38FgBf9ZOLw= github.com/aws/aws-sdk-go-v2/internal/ini v1.3.20/go.mod h1:bfTcsThj5a9P5pIGRy0QudJ8k4+issxXX+O6Djnd5Cs= github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 h1:GrSw8s0Gs/5zZ0SX+gX4zQjRnRsMJDJ2sLur1gRBhEM= github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY= @@ -985,7 +986,9 @@ github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl github.com/bradleyfalzon/ghinstallation/v2 v2.8.0 h1:yUmoVv70H3J4UOqxqsee39+KlXxNEDfTbAp8c/qULKk= github.com/bradleyfalzon/ghinstallation/v2 v2.8.0/go.mod h1:fmPmvCiBWhJla3zDv9ZTQSZc8AbwyRnGW1yg5ep1Pcs= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cenkalti/backoff/v3 v3.2.2 h1:cfUAAO3yvKMYKPrvhDuHSwQnhZNk/RMHKdZqKTxfm6M= github.com/cenkalti/backoff/v3 v3.2.2/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= @@ -1060,6 +1063,7 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP github.com/elastic/go-elasticsearch/v7 v7.17.10 h1:TCQ8i4PmIJuBunvBS6bwT2ybzVFxxUhhltAs3Gyu1yo= github.com/elastic/go-elasticsearch/v7 v7.17.10/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4= github.com/elazarl/goproxy v0.0.0-20220417044921-416226498f94 h1:VIy7cdK7ufs7ctpTFkXJHm1uP3dJSnCGSPysEICB1so= +github.com/elazarl/goproxy v0.0.0-20220417044921-416226498f94/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= @@ -1092,7 +1096,9 @@ github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/ github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= @@ -1142,6 +1148,7 @@ github.com/go-openapi/swag v0.22.7/go.mod h1:Gl91UqO+btAM0plGGxHqJcQZ1ZTy6jbmrid github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= @@ -1154,6 +1161,7 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw= +github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/gobuffalo/flect v1.0.2 h1:eqjPGSo2WmjgY2XlpGwo2NXgL3RucAKo4k4qQMNA5sA= github.com/gobuffalo/flect v1.0.2/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnDvkbYKHs= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= @@ -1226,6 +1234,7 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= +github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= github.com/google/cel-go v0.16.1 h1:3hZfSNiAU3KOiNtxuFXVp5WFy4hf/Ly3Sa4/7F8SXNo= github.com/google/cel-go v0.16.1/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY= github.com/google/flatbuffers v2.0.8+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= @@ -1333,6 +1342,7 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+ github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= @@ -1433,6 +1443,7 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= +github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= @@ -1466,6 +1477,7 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -1557,6 +1569,7 @@ github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c/go.mod h1:Qr6/a github.com/newrelic/newrelic-client-go v1.1.0 h1:aflNjzQ21c+2GwBVh+UbAf9lznkRfCcVABoc5UM4IXw= github.com/newrelic/newrelic-client-go v1.1.0/go.mod h1:RYMXt7hgYw7nzuXIGd2BH0F1AivgWw7WrBhNBQZEB4k= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oapi-codegen/runtime v1.1.0 h1:rJpoNUawn5XTvekgfkvSZr0RqEnoYpFkyvrzfWeFKWM= github.com/oapi-codegen/runtime v1.1.0/go.mod h1:BeSfBkWWWnAnGdyS+S/GnlbmHKzf8/hwkvelJZDeKA8= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= @@ -1565,6 +1578,7 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -1573,6 +1587,7 @@ github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8P github.com/open-policy-agent/cert-controller v0.10.1 h1:RXSYoyn8FdCenWecRP//UV5nbVfmstNpj4kHQFkvPK4= github.com/open-policy-agent/cert-controller v0.10.1/go.mod h1:4uRbBLY5DsPOog+a9pqk3JLxuuhrWsbUedQW65HcLTI= github.com/open-policy-agent/frameworks/constraint v0.0.0-20230822235116-f0b62fe1e4c4 h1:5dum5SLEz+95JDLkMls7Z7IDPjvSq3UhJSFe4f5einQ= +github.com/open-policy-agent/frameworks/constraint v0.0.0-20230822235116-f0b62fe1e4c4/go.mod h1:54/KzLMvA5ndBVpm7B1OjLeV0cUtTLTz2bZ2OtydLpU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE= github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U= @@ -1604,6 +1619,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= @@ -1644,6 +1660,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w= @@ -1660,6 +1677,7 @@ github.com/segmentio/kafka-go v0.4.47/go.mod h1:HjF6XbOKh0Pjlkr5GVZxt6CsjjwnmhVO github.com/segmentio/kafka-go/sasl/aws_msk_iam_v2 v0.1.0 h1:Fjet4CFbGyWMbvwWb42PKZwKdpDksSB7eaPi9Ap6EKY= github.com/segmentio/kafka-go/sasl/aws_msk_iam_v2 v0.1.0/go.mod h1:zk5DCsbNtQ0BhooxFaVpLBns0tArkR/xE+4oq2MvCq0= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= @@ -1674,6 +1692,7 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js= +github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= @@ -1725,8 +1744,10 @@ github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk= +github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE= +github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75/go.mod h1:KO6IkyS8Y3j8OdNO85qEYBsRPuteD+YciPomcXdrMnk= github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 h1:nrZ3ySNYwJbSpD6ce9duiP+QkD3JuLCcWkdaehUS/3Y= github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80/go.mod h1:iFyPdL66DjUD96XmzVL3ZntbzcflLnznH0fr99w5VqE= github.com/ulikunitz/unixtime v0.1.2 h1:X28zmTs0BODKZs7tgEC+WCwyV53fqgmRwwFpVKGDmso= @@ -1773,16 +1794,21 @@ gitlab.com/flimzy/testy v0.11.0 h1:YQxcTSqX/r9NYvwrNG+maswc7bw+r1Hh1RE/7e6JWQ4= gitlab.com/flimzy/testy v0.11.0/go.mod h1:tcu652e6AyD5wS8q2JRUI+j5SlwIYsl3yq3ulHyuh8M= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= +go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= go.etcd.io/etcd/api/v3 v3.5.11 h1:B54KwXbWDHyD3XYAwprxNzTe7vlhR69LuBgZnMVvS7E= go.etcd.io/etcd/api/v3 v3.5.11/go.mod h1:Ot+o0SWSyT6uHhA56al1oCED0JImsRiU9Dc26+C2a+4= go.etcd.io/etcd/client/pkg/v3 v3.5.11 h1:bT2xVspdiCj2910T0V+/KHcVKjkUrCZVtk8J2JF2z1A= go.etcd.io/etcd/client/pkg/v3 v3.5.11/go.mod h1:seTzl2d9APP8R5Y2hFL3NVlD6qC/dOT+3kvrqPyTas4= go.etcd.io/etcd/client/v2 v2.305.10 h1:MrmRktzv/XF8CvtQt+P6wLUlURaNpSDJHFZhe//2QE4= +go.etcd.io/etcd/client/v2 v2.305.10/go.mod h1:m3CKZi69HzilhVqtPDcjhSGp+kA1OmbNn0qamH80xjA= go.etcd.io/etcd/client/v3 v3.5.11 h1:ajWtgoNSZJ1gmS8k+icvPtqsqEav+iUorF7b0qozgUU= go.etcd.io/etcd/client/v3 v3.5.11/go.mod h1:a6xQUEqFJ8vztO1agJh/KQKOMfFI8og52ZconzcDJwE= go.etcd.io/etcd/pkg/v3 v3.5.10 h1:WPR8K0e9kWl1gAhB5A7gEa5ZBTNkT9NdNWrR8Qpo1CM= +go.etcd.io/etcd/pkg/v3 v3.5.10/go.mod h1:TKTuCKKcF1zxmfKWDkfz5qqYaE3JncKKZPFf8c1nFUs= go.etcd.io/etcd/raft/v3 v3.5.10 h1:cgNAYe7xrsrn/5kXMSaH8kM/Ky8mAdMqGOxyYwpP0LA= +go.etcd.io/etcd/raft/v3 v3.5.10/go.mod h1:odD6kr8XQXTy9oQnyMPBOr0TVe+gT0neQhElQ6jbGRc= go.etcd.io/etcd/server/v3 v3.5.10 h1:4NOGyOwD5sUZ22PiWYKmfxqoeh72z6EhYjNosKGLmZg= +go.etcd.io/etcd/server/v3 v3.5.10/go.mod h1:gBplPHfs6YI0L+RpGkTQO7buDbHv5HJGG/Bst0/zIPo= go.mongodb.org/mongo-driver v1.13.1 h1:YIc7HTYsKndGK4RFzJ3covLz1byri52x0IoMB0Pt/vk= go.mongodb.org/mongo-driver v1.13.1/go.mod h1:wcDf1JBCXy2mOW0bWHwO/IOYqdca1MPCwDtFu/Z9+eo= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -1830,6 +1856,7 @@ go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnw go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -2479,6 +2506,7 @@ k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kms v0.29.0 h1:KJ1zaZt74CgvgV3NR7tnURJ/mJOKC5X3nwon/WdwgxI= k8s.io/kms v0.29.0/go.mod h1:mB0f9HLxRXeXUfHfn1A7rpwOlzXI1gIWu86z6buNoYA= k8s.io/kube-aggregator v0.28.1 h1:rvG4llYnQKHjj6YjjoBPEJxfD1uH0DJwkrJTNKGAaCs= +k8s.io/kube-aggregator v0.28.1/go.mod h1:JaLizMe+AECSpO2OmrWVsvnG0V3dX1RpW+Wq/QHbu18= k8s.io/kube-openapi v0.0.0-20230901164831-6c774f458599 h1:nVKRi5eItf3x9kkIMfdT4D1/LqPzj0bLjxLYWbdUtV0= k8s.io/kube-openapi v0.0.0-20230901164831-6c774f458599/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= k8s.io/metrics v0.28.5 h1:Yh29Yi/x3ojK9ofYuY76Ny0IJdXeTZ9TiVjqAd9MssY= @@ -2539,6 +2567,7 @@ modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= modernc.org/z v1.5.1/go.mod h1:eWFB510QWW5Th9YGZT81s+LwvaAs3Q2yr4sP0rmLkv8= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= +nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/pkg/metricsservice/api/metrics.pb.go b/pkg/metricsservice/api/metrics.pb.go index 54ba64df97f..95e3100a780 100644 --- a/pkg/metricsservice/api/metrics.pb.go +++ b/pkg/metricsservice/api/metrics.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.24.4 +// protoc v4.23.2 // source: metrics.proto package api diff --git a/pkg/metricsservice/api/metrics_grpc.pb.go b/pkg/metricsservice/api/metrics_grpc.pb.go index 935372927f9..9eae639dc04 100644 --- a/pkg/metricsservice/api/metrics_grpc.pb.go +++ b/pkg/metricsservice/api/metrics_grpc.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.24.4 +// - protoc v4.23.2 // source: metrics.proto package api diff --git a/pkg/scalers/activemq_scaler.go b/pkg/scalers/activemq_scaler.go index 8aa4bcfb9dd..243ddff777d 100644 --- a/pkg/scalers/activemq_scaler.go +++ b/pkg/scalers/activemq_scaler.go @@ -16,6 +16,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -53,7 +54,7 @@ const ( ) // NewActiveMQScaler creates a new activeMQ Scaler -func NewActiveMQScaler(config *ScalerConfig) (Scaler, error) { +func NewActiveMQScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -73,7 +74,7 @@ func NewActiveMQScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseActiveMQMetadata(config *ScalerConfig) (*activeMQMetadata, error) { +func parseActiveMQMetadata(config *scalersconfig.ScalerConfig) (*activeMQMetadata, error) { meta := activeMQMetadata{} if val, ok := config.TriggerMetadata["restAPITemplate"]; ok && val != "" { diff --git a/pkg/scalers/activemq_scaler_test.go b/pkg/scalers/activemq_scaler_test.go index 90fa572b8fd..ac85316b6d7 100644 --- a/pkg/scalers/activemq_scaler_test.go +++ b/pkg/scalers/activemq_scaler_test.go @@ -5,6 +5,8 @@ import ( "fmt" "net/http" "testing" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -221,7 +223,7 @@ var testActiveMQMetadata = []parseActiveMQMetadataTestData{ func TestActiveMQDefaultCorsHeader(t *testing.T) { metadata := map[string]string{"managementEndpoint": "localhost:8161", "destinationName": "queue1", "brokerName": "broker-activemq", "username": "myUserName", "password": "myPassword"} - meta, err := parseActiveMQMetadata(&ScalerConfig{TriggerMetadata: metadata, AuthParams: nil}) + meta, err := parseActiveMQMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: metadata, AuthParams: nil}) if err != nil { t.Error("Expected success but got error", err) @@ -233,7 +235,7 @@ func TestActiveMQDefaultCorsHeader(t *testing.T) { func TestActiveMQCorsHeader(t *testing.T) { metadata := map[string]string{"managementEndpoint": "localhost:8161", "destinationName": "queue1", "brokerName": "broker-activemq", "username": "myUserName", "password": "myPassword", "corsHeader": "test"} - meta, err := parseActiveMQMetadata(&ScalerConfig{TriggerMetadata: metadata, AuthParams: nil}) + meta, err := parseActiveMQMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: metadata, AuthParams: nil}) if err != nil { t.Error("Expected success but got error", err) @@ -246,7 +248,7 @@ func TestActiveMQCorsHeader(t *testing.T) { func TestParseActiveMQMetadata(t *testing.T) { for _, testData := range testActiveMQMetadata { t.Run(testData.name, func(t *testing.T) { - metadata, err := parseActiveMQMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + metadata, err := parseActiveMQMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -280,7 +282,7 @@ var testDefaultTargetQueueSize = []parseActiveMQMetadataTestData{ func TestParseDefaultTargetQueueSize(t *testing.T) { for _, testData := range testDefaultTargetQueueSize { t.Run(testData.name, func(t *testing.T) { - metadata, err := parseActiveMQMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + metadata, err := parseActiveMQMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) switch { case err != nil && !testData.isError: t.Error("Expected success but got error", err) @@ -296,7 +298,7 @@ func TestParseDefaultTargetQueueSize(t *testing.T) { func TestActiveMQGetMetricSpecForScaling(t *testing.T) { for _, testData := range activeMQMetricIdentifiers { ctx := context.Background() - metadata, err := parseActiveMQMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}) + metadata, err := parseActiveMQMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -343,7 +345,7 @@ func TestActiveMQGetMonitoringEndpoint(t *testing.T) { "password": "pass123", } for _, testData := range getMonitoringEndpointData { - metadata, err := parseActiveMQMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: authParams, TriggerIndex: 0}) + metadata, err := parseActiveMQMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: authParams, TriggerIndex: 0}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/apache_kafka_scaler.go b/pkg/scalers/apache_kafka_scaler.go index 97dd49c6552..bc13daf3fb9 100644 --- a/pkg/scalers/apache_kafka_scaler.go +++ b/pkg/scalers/apache_kafka_scaler.go @@ -36,6 +36,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -88,7 +89,7 @@ const ( ) // NewApacheKafkaScaler creates a new apacheKafkaScaler -func NewApacheKafkaScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewApacheKafkaScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -117,7 +118,7 @@ func NewApacheKafkaScaler(ctx context.Context, config *ScalerConfig) (Scaler, er }, nil } -func parseApacheKafkaAuthParams(config *ScalerConfig, meta *apacheKafkaMetadata) error { +func parseApacheKafkaAuthParams(config *scalersconfig.ScalerConfig, meta *apacheKafkaMetadata) error { meta.enableTLS = false enableTLS := false if val, ok := config.TriggerMetadata["tls"]; ok { @@ -227,7 +228,7 @@ func parseApacheKafkaAuthParams(config *ScalerConfig, meta *apacheKafkaMetadata) return nil } -func parseApacheKafkaMetadata(config *ScalerConfig, logger logr.Logger) (apacheKafkaMetadata, error) { +func parseApacheKafkaMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (apacheKafkaMetadata, error) { meta := apacheKafkaMetadata{} switch { case config.TriggerMetadata["bootstrapServersFromEnv"] != "": diff --git a/pkg/scalers/apache_kafka_scaler_test.go b/pkg/scalers/apache_kafka_scaler_test.go index a056c11cbe5..11c2864cf34 100644 --- a/pkg/scalers/apache_kafka_scaler_test.go +++ b/pkg/scalers/apache_kafka_scaler_test.go @@ -8,6 +8,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseApacheKafkaMetadataTestData struct { @@ -241,10 +243,10 @@ var apacheKafkaMetricIdentifiers = []apacheKafkaMetricIdentifier{ func TestApacheKafkaGetBrokers(t *testing.T) { for _, testData := range parseApacheKafkaMetadataTestDataset { - meta, err := parseApacheKafkaMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validApacheKafkaWithAuthParams}, logr.Discard()) + meta, err := parseApacheKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validApacheKafkaWithAuthParams}, logr.Discard()) getBrokerApacheKafkaTestBase(t, meta, testData, err) - meta, err = parseApacheKafkaMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validApacheKafkaWithoutAuthParams}, logr.Discard()) + meta, err = parseApacheKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validApacheKafkaWithoutAuthParams}, logr.Discard()) getBrokerApacheKafkaTestBase(t, meta, testData, err) } } @@ -296,7 +298,7 @@ func getBrokerApacheKafkaTestBase(t *testing.T, meta apacheKafkaMetadata, testDa func TestApacheKafkaAuthParams(t *testing.T) { // Testing tls and sasl value in TriggerAuthentication for _, testData := range parseApacheKafkaAuthParamsTestDataset { - meta, err := parseApacheKafkaMetadata(&ScalerConfig{TriggerMetadata: validApacheKafkaMetadata, AuthParams: testData.authParams}, logr.Discard()) + meta, err := parseApacheKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: validApacheKafkaMetadata, AuthParams: testData.authParams}, logr.Discard()) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -326,7 +328,7 @@ func TestApacheKafkaAuthParams(t *testing.T) { // Testing tls and sasl value in scaledObject for id, testData := range parseApacheKafkaAuthParamsTestDataset2 { - meta, err := parseApacheKafkaMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}, logr.Discard()) + meta, err := parseApacheKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}, logr.Discard()) if err != nil && !testData.isError { t.Errorf("Test case: %#v. Expected success but got error %#v", id, err) @@ -358,7 +360,7 @@ func TestApacheKafkaAuthParams(t *testing.T) { func TestApacheKafkaGetMetricSpecForScaling(t *testing.T) { for _, testData := range apacheKafkaMetricIdentifiers { - meta, err := parseApacheKafkaMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validApacheKafkaWithAuthParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseApacheKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validApacheKafkaWithAuthParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/arangodb_scaler.go b/pkg/scalers/arangodb_scaler.go index 4a19bf77419..818f30f4eeb 100644 --- a/pkg/scalers/arangodb_scaler.go +++ b/pkg/scalers/arangodb_scaler.go @@ -14,6 +14,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" "github.com/kedacore/keda/v2/pkg/scalers/authentication" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/util" ) @@ -68,7 +69,7 @@ type arangoDBMetadata struct { } // NewArangoDBScaler creates a new arangodbScaler -func NewArangoDBScaler(config *ScalerConfig) (Scaler, error) { +func NewArangoDBScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -125,7 +126,7 @@ func getNewArangoDBClient(meta *arangoDBMetadata) (driver.Client, error) { return client, nil } -func parseArangoDBMetadata(config *ScalerConfig) (*arangoDBMetadata, error) { +func parseArangoDBMetadata(config *scalersconfig.ScalerConfig) (*arangoDBMetadata, error) { // setting default metadata meta := arangoDBMetadata{} diff --git a/pkg/scalers/arangodb_scaler_test.go b/pkg/scalers/arangodb_scaler_test.go index 70081eade20..75409295b0b 100644 --- a/pkg/scalers/arangodb_scaler_test.go +++ b/pkg/scalers/arangodb_scaler_test.go @@ -6,6 +6,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseArangoDBMetadataTestData struct { @@ -79,7 +81,7 @@ var arangoDBMetricIdentifiers = []arangoDBMetricIdentifier{ func TestParseArangoDBMetadata(t *testing.T) { for _, testData := range testArangoDBMetadata { - _, err := parseArangoDBMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, err := parseArangoDBMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.raisesError { t.Error("Expected success but got error:", err) } @@ -91,7 +93,7 @@ func TestParseArangoDBMetadata(t *testing.T) { func TestArangoDBScalerAuthParams(t *testing.T) { for _, testData := range testArangoDBAuthMetadata { - meta, err := parseArangoDBMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + meta, err := parseArangoDBMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.raisesError { t.Error("Expected success but got error", err) @@ -110,7 +112,7 @@ func TestArangoDBScalerAuthParams(t *testing.T) { func TestArangoDBGetMetricSpecForScaling(t *testing.T) { for _, testData := range arangoDBMetricIdentifiers { - meta, err := parseArangoDBMetadata(&ScalerConfig{ + meta, err := parseArangoDBMetadata(&scalersconfig.ScalerConfig{ AuthParams: testData.metadataTestData.authParams, TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex, diff --git a/pkg/scalers/artemis_scaler.go b/pkg/scalers/artemis_scaler.go index 402e8012525..05e030ccb02 100644 --- a/pkg/scalers/artemis_scaler.go +++ b/pkg/scalers/artemis_scaler.go @@ -14,6 +14,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -56,7 +57,7 @@ const ( ) // NewArtemisQueueScaler creates a new artemis queue Scaler -func NewArtemisQueueScaler(config *ScalerConfig) (Scaler, error) { +func NewArtemisQueueScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { // do we need to guarantee this timeout for a specific // reason? if not, we can have buildScaler pass in // the global client @@ -80,7 +81,7 @@ func NewArtemisQueueScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseArtemisMetadata(config *ScalerConfig) (*artemisMetadata, error) { +func parseArtemisMetadata(config *scalersconfig.ScalerConfig) (*artemisMetadata, error) { meta := artemisMetadata{} meta.queueLength = defaultArtemisQueueLength diff --git a/pkg/scalers/artemis_scaler_test.go b/pkg/scalers/artemis_scaler_test.go index ea2bfe2b841..f7dc7ab43f9 100644 --- a/pkg/scalers/artemis_scaler_test.go +++ b/pkg/scalers/artemis_scaler_test.go @@ -4,6 +4,8 @@ import ( "context" "net/http" "testing" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -86,7 +88,7 @@ var testArtemisMetadataWithAuthParams = []parseArtemisMetadataTestData{ func TestArtemisDefaultCorsHeader(t *testing.T) { metadata := map[string]string{"managementEndpoint": "localhost:8161", "queueName": "queue1", "brokerName": "broker-activemq", "brokerAddress": "test", "username": "myUserName", "password": "myPassword"} - meta, err := parseArtemisMetadata(&ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: metadata, AuthParams: nil}) + meta, err := parseArtemisMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: metadata, AuthParams: nil}) if err != nil { t.Error("Expected success but got error", err) @@ -98,7 +100,7 @@ func TestArtemisDefaultCorsHeader(t *testing.T) { func TestArtemisCorsHeader(t *testing.T) { metadata := map[string]string{"managementEndpoint": "localhost:8161", "queueName": "queue1", "brokerName": "broker-activemq", "brokerAddress": "test", "username": "myUserName", "password": "myPassword", "corsHeader": "test"} - meta, err := parseArtemisMetadata(&ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: metadata, AuthParams: nil}) + meta, err := parseArtemisMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: metadata, AuthParams: nil}) if err != nil { t.Error("Expected success but got error", err) @@ -110,7 +112,7 @@ func TestArtemisCorsHeader(t *testing.T) { func TestArtemisParseMetadata(t *testing.T) { for _, testData := range testArtemisMetadata { - _, err := parseArtemisMetadata(&ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: nil}) + _, err := parseArtemisMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: nil}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -121,7 +123,7 @@ func TestArtemisParseMetadata(t *testing.T) { // test with missing auth params should all fail for _, testData := range testArtemisMetadataWithEmptyAuthParams { - _, err := parseArtemisMetadata(&ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: emptyArtemisAuthParams}) + _, err := parseArtemisMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: emptyArtemisAuthParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -132,7 +134,7 @@ func TestArtemisParseMetadata(t *testing.T) { // test with complete auth params should not fail for _, testData := range testArtemisMetadataWithAuthParams { - _, err := parseArtemisMetadata(&ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: artemisAuthParams}) + _, err := parseArtemisMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: artemisAuthParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -145,7 +147,7 @@ func TestArtemisParseMetadata(t *testing.T) { func TestArtemisGetMetricSpecForScaling(t *testing.T) { for _, testData := range artemisMetricIdentifiers { ctx := context.Background() - meta, err := parseArtemisMetadata(&ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: nil, TriggerIndex: testData.triggerIndex}) + meta, err := parseArtemisMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleArtemisResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: nil, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/aws_cloudwatch_scaler.go b/pkg/scalers/aws_cloudwatch_scaler.go index a140557e22f..10eb10b260e 100644 --- a/pkg/scalers/aws_cloudwatch_scaler.go +++ b/pkg/scalers/aws_cloudwatch_scaler.go @@ -15,6 +15,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -57,7 +58,7 @@ type awsCloudwatchMetadata struct { } // NewAwsCloudwatchScaler creates a new awsCloudwatchScaler -func NewAwsCloudwatchScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewAwsCloudwatchScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -125,7 +126,7 @@ func createCloudwatchClient(ctx context.Context, metadata *awsCloudwatchMetadata }), nil } -func parseAwsCloudwatchMetadata(config *ScalerConfig) (*awsCloudwatchMetadata, error) { +func parseAwsCloudwatchMetadata(config *scalersconfig.ScalerConfig) (*awsCloudwatchMetadata, error) { var err error meta := awsCloudwatchMetadata{} diff --git a/pkg/scalers/aws_cloudwatch_scaler_test.go b/pkg/scalers/aws_cloudwatch_scaler_test.go index 1f57666e81e..0564f205b88 100644 --- a/pkg/scalers/aws_cloudwatch_scaler_test.go +++ b/pkg/scalers/aws_cloudwatch_scaler_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/assert" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -471,7 +472,7 @@ func (m *mockCloudwatch) GetMetricData(_ context.Context, input *cloudwatch.GetM func TestCloudwatchParseMetadata(t *testing.T) { for _, testData := range testAWSCloudwatchMetadata { - _, err := parseAwsCloudwatchMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testAWSCloudwatchResolvedEnv, AuthParams: testData.authParams}) + _, err := parseAwsCloudwatchMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testAWSCloudwatchResolvedEnv, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Errorf("%s: Expected success but got error %s", testData.comment, err) } @@ -484,7 +485,7 @@ func TestCloudwatchParseMetadata(t *testing.T) { func TestAWSCloudwatchGetMetricSpecForScaling(t *testing.T) { for _, testData := range awsCloudwatchMetricIdentifiers { ctx := context.Background() - meta, err := parseAwsCloudwatchMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testAWSCloudwatchResolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}) + meta, err := parseAwsCloudwatchMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testAWSCloudwatchResolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/aws_dynamodb_scaler.go b/pkg/scalers/aws_dynamodb_scaler.go index d5afb95eab6..72aff9beb46 100644 --- a/pkg/scalers/aws_dynamodb_scaler.go +++ b/pkg/scalers/aws_dynamodb_scaler.go @@ -16,6 +16,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -41,7 +42,7 @@ type awsDynamoDBMetadata struct { metricName string } -func NewAwsDynamoDBScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewAwsDynamoDBScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -92,7 +93,7 @@ var ( ErrAwsDynamoNoTargetValue = errors.New("no targetValue given") ) -func parseAwsDynamoDBMetadata(config *ScalerConfig) (*awsDynamoDBMetadata, error) { +func parseAwsDynamoDBMetadata(config *scalersconfig.ScalerConfig) (*awsDynamoDBMetadata, error) { meta := awsDynamoDBMetadata{} if val, ok := config.TriggerMetadata["tableName"]; ok && val != "" { diff --git a/pkg/scalers/aws_dynamodb_scaler_test.go b/pkg/scalers/aws_dynamodb_scaler_test.go index 1ebbdd2b767..a577f561e21 100644 --- a/pkg/scalers/aws_dynamodb_scaler_test.go +++ b/pkg/scalers/aws_dynamodb_scaler_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -294,7 +295,7 @@ var dynamoTestCases = []parseDynamoDBMetadataTestData{ func TestParseDynamoMetadata(t *testing.T) { for _, tc := range dynamoTestCases { t.Run(tc.name, func(t *testing.T) { - metadata, err := parseAwsDynamoDBMetadata(&ScalerConfig{ + metadata, err := parseAwsDynamoDBMetadata(&scalersconfig.ScalerConfig{ TriggerMetadata: tc.metadata, AuthParams: tc.authParams, ResolvedEnv: tc.resolvedEnv, diff --git a/pkg/scalers/aws_dynamodb_streams_scaler.go b/pkg/scalers/aws_dynamodb_streams_scaler.go index bd06a44d4c8..a8448a46408 100644 --- a/pkg/scalers/aws_dynamodb_streams_scaler.go +++ b/pkg/scalers/aws_dynamodb_streams_scaler.go @@ -13,6 +13,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -40,7 +41,7 @@ type awsDynamoDBStreamsMetadata struct { } // NewAwsDynamoDBStreamsScaler creates a new awsDynamoDBStreamsScaler -func NewAwsDynamoDBStreamsScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewAwsDynamoDBStreamsScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -73,7 +74,7 @@ func NewAwsDynamoDBStreamsScaler(ctx context.Context, config *ScalerConfig) (Sca }, nil } -func parseAwsDynamoDBStreamsMetadata(config *ScalerConfig, logger logr.Logger) (*awsDynamoDBStreamsMetadata, error) { +func parseAwsDynamoDBStreamsMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*awsDynamoDBStreamsMetadata, error) { meta := awsDynamoDBStreamsMetadata{} meta.targetShardCount = defaultTargetDBStreamsShardCount diff --git a/pkg/scalers/aws_dynamodb_streams_scaler_test.go b/pkg/scalers/aws_dynamodb_streams_scaler_test.go index e007dec019c..5c87de8d87a 100644 --- a/pkg/scalers/aws_dynamodb_streams_scaler_test.go +++ b/pkg/scalers/aws_dynamodb_streams_scaler_test.go @@ -17,6 +17,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -377,7 +378,7 @@ var awsDynamoDBStreamsGetMetricTestData = []*awsDynamoDBStreamsMetadata{ func TestParseAwsDynamoDBStreamsMetadata(t *testing.T) { for _, testData := range testAwsDynamoDBStreamMetadata { - result, err := parseAwsDynamoDBStreamsMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testAwsDynamoDBStreamAuthentication, AuthParams: testData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) + result, err := parseAwsDynamoDBStreamsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testAwsDynamoDBStreamAuthentication, AuthParams: testData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil && !testData.isError { t.Errorf("Expected success because %s got error, %s", testData.comment, err) } @@ -394,7 +395,7 @@ func TestParseAwsDynamoDBStreamsMetadata(t *testing.T) { func TestAwsDynamoDBStreamsGetMetricSpecForScaling(t *testing.T) { for _, testData := range awsDynamoDBStreamMetricIdentifiers { ctx := context.Background() - meta, err := parseAwsDynamoDBStreamsMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testAwsDynamoDBStreamAuthentication, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseAwsDynamoDBStreamsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testAwsDynamoDBStreamAuthentication, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/aws_kinesis_stream_scaler.go b/pkg/scalers/aws_kinesis_stream_scaler.go index 09ed926784e..65fb90a4e23 100644 --- a/pkg/scalers/aws_kinesis_stream_scaler.go +++ b/pkg/scalers/aws_kinesis_stream_scaler.go @@ -12,6 +12,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -50,7 +51,7 @@ type awsKinesisStreamMetadata struct { } // NewAwsKinesisStreamScaler creates a new awsKinesisStreamScaler -func NewAwsKinesisStreamScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewAwsKinesisStreamScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -77,7 +78,7 @@ func NewAwsKinesisStreamScaler(ctx context.Context, config *ScalerConfig) (Scale }, nil } -func parseAwsKinesisStreamMetadata(config *ScalerConfig, logger logr.Logger) (*awsKinesisStreamMetadata, error) { +func parseAwsKinesisStreamMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*awsKinesisStreamMetadata, error) { meta := awsKinesisStreamMetadata{} meta.targetShardCount = targetShardCountDefault diff --git a/pkg/scalers/aws_kinesis_stream_scaler_test.go b/pkg/scalers/aws_kinesis_stream_scaler_test.go index 7bdad47886c..c62a047d7d6 100644 --- a/pkg/scalers/aws_kinesis_stream_scaler_test.go +++ b/pkg/scalers/aws_kinesis_stream_scaler_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -318,7 +319,7 @@ var awsKinesisGetMetricTestData = []*awsKinesisStreamMetadata{ func TestKinesisParseMetadata(t *testing.T) { for _, testData := range testAWSKinesisMetadata { - result, err := parseAwsKinesisStreamMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testAWSKinesisAuthentication, AuthParams: testData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) + result, err := parseAwsKinesisStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testAWSKinesisAuthentication, AuthParams: testData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil && !testData.isError { t.Errorf("Expected success because %s got error, %s", testData.comment, err) } @@ -335,7 +336,7 @@ func TestKinesisParseMetadata(t *testing.T) { func TestAWSKinesisGetMetricSpecForScaling(t *testing.T) { for _, testData := range awsKinesisMetricIdentifiers { ctx := context.Background() - meta, err := parseAwsKinesisStreamMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testAWSKinesisAuthentication, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseAwsKinesisStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testAWSKinesisAuthentication, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/aws_sqs_queue_scaler.go b/pkg/scalers/aws_sqs_queue_scaler.go index f90cdb7f353..1c5976685fb 100644 --- a/pkg/scalers/aws_sqs_queue_scaler.go +++ b/pkg/scalers/aws_sqs_queue_scaler.go @@ -15,6 +15,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -47,7 +48,7 @@ type awsSqsQueueMetadata struct { } // NewAwsSqsQueueScaler creates a new awsSqsQueueScaler -func NewAwsSqsQueueScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewAwsSqsQueueScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -85,7 +86,7 @@ func (w sqsWrapperClient) GetQueueAttributes(ctx context.Context, params *sqs.Ge return w.sqsClient.GetQueueAttributes(ctx, params, optFns...) } -func parseAwsSqsQueueMetadata(config *ScalerConfig, logger logr.Logger) (*awsSqsQueueMetadata, error) { +func parseAwsSqsQueueMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*awsSqsQueueMetadata, error) { meta := awsSqsQueueMetadata{} meta.targetQueueLength = defaultTargetQueueLength meta.scaleOnInFlight = defaultScaleOnInFlight diff --git a/pkg/scalers/aws_sqs_queue_scaler_test.go b/pkg/scalers/aws_sqs_queue_scaler_test.go index cf3a51766a5..ce6ca3d5b4d 100644 --- a/pkg/scalers/aws_sqs_queue_scaler_test.go +++ b/pkg/scalers/aws_sqs_queue_scaler_test.go @@ -9,6 +9,8 @@ import ( "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/go-logr/logr" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -389,7 +391,7 @@ var awsSQSGetMetricTestData = []*parseAWSSQSMetadataTestData{ func TestSQSParseMetadata(t *testing.T) { for _, testData := range testAWSSQSMetadata { - _, err := parseAwsSqsQueueMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams}, logr.Discard()) + _, err := parseAwsSqsQueueMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams}, logr.Discard()) if err != nil && !testData.isError { t.Errorf("Expected success because %s got error, %s", testData.comment, err) } @@ -402,7 +404,7 @@ func TestSQSParseMetadata(t *testing.T) { func TestAWSSQSGetMetricSpecForScaling(t *testing.T) { for _, testData := range awsSQSMetricIdentifiers { ctx := context.Background() - meta, err := parseAwsSqsQueueMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseAwsSqsQueueMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -418,7 +420,7 @@ func TestAWSSQSGetMetricSpecForScaling(t *testing.T) { func TestAWSSQSScalerGetMetrics(t *testing.T) { for index, testData := range awsSQSGetMetricTestData { - meta, err := parseAwsSqsQueueMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams, TriggerIndex: index}, logr.Discard()) + meta, err := parseAwsSqsQueueMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams, TriggerIndex: index}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/azure_app_insights_scaler.go b/pkg/scalers/azure_app_insights_scaler.go index 59d5bb0ccb0..b7b567f7d1f 100644 --- a/pkg/scalers/azure_app_insights_scaler.go +++ b/pkg/scalers/azure_app_insights_scaler.go @@ -12,6 +12,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -51,7 +52,7 @@ type azureAppInsightsScaler struct { } // NewAzureAppInsightsScaler creates a new AzureAppInsightsScaler -func NewAzureAppInsightsScaler(config *ScalerConfig) (Scaler, error) { +func NewAzureAppInsightsScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -72,7 +73,7 @@ func NewAzureAppInsightsScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseAzureAppInsightsMetadata(config *ScalerConfig, logger logr.Logger) (*azureAppInsightsMetadata, error) { +func parseAzureAppInsightsMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*azureAppInsightsMetadata, error) { meta := azureAppInsightsMetadata{ azureAppInsightsInfo: azure.AppInsightsInfo{}, } @@ -157,8 +158,7 @@ func parseAzureAppInsightsMetadata(config *ScalerConfig, logger logr.Logger) (*a if val, ok := config.TriggerMetadata[azureAppInsightsIgnoreNullValues]; ok && val != "" { azureAppInsightsIgnoreNullValues, err := strconv.ParseBool(val) if err != nil { - return nil, fmt.Errorf("err incorrect value for azureAppInsightsIgnoreNullValues given: %s, "+ - "please use true or false", val) + return nil, fmt.Errorf("err incorrect value for azureAppInsightsIgnoreNullValues given: %s, please use true or false", val) } meta.ignoreNullValues = azureAppInsightsIgnoreNullValues } diff --git a/pkg/scalers/azure_app_insights_scaler_test.go b/pkg/scalers/azure_app_insights_scaler_test.go index acdc96ce513..e32e0e2fc11 100644 --- a/pkg/scalers/azure_app_insights_scaler_test.go +++ b/pkg/scalers/azure_app_insights_scaler_test.go @@ -9,16 +9,17 @@ import ( "github.com/go-logr/logr" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type azureAppInsightsScalerTestData struct { name string isError bool - config ScalerConfig + config scalersconfig.ScalerConfig } var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ - {name: "no target value", isError: true, config: ScalerConfig{ + {name: "no target value", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "", "tenantId": "1234", }, @@ -26,7 +27,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "target value not a number", isError: true, config: ScalerConfig{ + {name: "target value not a number", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "a1", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "", "tenantId": "1234", }, @@ -34,7 +35,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "activation target value not a number", isError: true, config: ScalerConfig{ + {name: "activation target value not a number", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "1", "activationTargetValue": "a1", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "", "tenantId": "1234", }, @@ -42,7 +43,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "empty app insights id", isError: true, config: ScalerConfig{ + {name: "empty app insights id", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "", "tenantId": "1234", }, @@ -50,7 +51,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "empty metric id", isError: true, config: ScalerConfig{ + {name: "empty metric id", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "", "tenantId": "1234", }, @@ -58,7 +59,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "empty timespan", isError: true, config: ScalerConfig{ + {name: "empty timespan", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "", "metricAggregationType": "max", "metricFilter": "", "tenantId": "1234", }, @@ -66,7 +67,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "invalid timespan", isError: true, config: ScalerConfig{ + {name: "invalid timespan", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02:03", "metricAggregationType": "max", "metricFilter": "", "tenantId": "1234", }, @@ -74,7 +75,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "empty aggregation type", isError: true, config: ScalerConfig{ + {name: "empty aggregation type", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "", "metricFilter": "", "tenantId": "1234", }, @@ -82,7 +83,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "empty tenant id", isError: true, config: ScalerConfig{ + {name: "empty tenant id", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "", "tenantId": "", }, @@ -90,7 +91,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "invalid identity", isError: true, config: ScalerConfig{ + {name: "invalid identity", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "", "tenantId": "1234", }, @@ -98,7 +99,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "", "activeDirectoryClientPassword": "pw", }, }}, - {name: "filter empty", isError: false, config: ScalerConfig{ + {name: "filter empty", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "", "tenantId": "1234", }, @@ -106,7 +107,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "filter given", isError: false, config: ScalerConfig{ + {name: "filter given", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "tenantId": "1234", }, @@ -114,49 +115,49 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", }, }}, - {name: "correct pod identity", isError: false, config: ScalerConfig{ + {name: "correct pod identity", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "tenantId": "1234", }, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzure}, }}, - {name: "invalid pod Identity", isError: true, config: ScalerConfig{ + {name: "invalid pod Identity", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "tenantId": "1234", }, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProvider("notAzure")}, }}, - {name: "correct workload identity", isError: false, config: ScalerConfig{ + {name: "correct workload identity", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "tenantId": "1234", }, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzureWorkload}, }}, - {name: "invalid workload Identity", isError: true, config: ScalerConfig{ + {name: "invalid workload Identity", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "tenantId": "1234", }, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProvider("notAzureWorkload")}, }}, - {name: "correct ignoreNullValues (true)", isError: false, config: ScalerConfig{ + {name: "correct ignoreNullValues (true)", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "tenantId": "1234", "ignoreNullValues": "true", }, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzureWorkload}, }}, - {name: "correct ignoreNullValues (false)", isError: false, config: ScalerConfig{ + {name: "correct ignoreNullValues (false)", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "tenantId": "1234", "ignoreNullValues": "false", }, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzureWorkload}, }}, - {name: "incorrect ignoreNullValues", isError: true, config: ScalerConfig{ + {name: "incorrect ignoreNullValues", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "tenantId": "1234", "ignoreNullValues": "not a boolean", }, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzureWorkload}, }}, - {name: "app insights id in auth", isError: false, config: ScalerConfig{ + {name: "app insights id in auth", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "tenantId": "1234", }, @@ -164,7 +165,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", "applicationInsightsId": "1234", }, }}, - {name: "tenant id in auth", isError: false, config: ScalerConfig{ + {name: "tenant id in auth", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "applicationInsightsId": "1234", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", }, @@ -172,7 +173,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "activeDirectoryClientId": "5678", "activeDirectoryClientPassword": "pw", "tenantId": "1234", }, }}, - {name: "from env", isError: false, config: ScalerConfig{ + {name: "from env", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "activeDirectoryClientIdFromEnv": "AD_CLIENT_ID", "activeDirectoryClientPasswordFromEnv": "AD_CLIENT_PASSWORD", "applicationInsightsIdFromEnv": "APP_INSIGHTS_ID", "tenantIdFromEnv": "TENANT_ID", @@ -182,7 +183,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "AD_CLIENT_ID": "5678", "AD_CLIENT_PASSWORD": "pw", "APP_INSIGHTS_ID": "1234", "TENANT_ID": "1234", }, }}, - {name: "from env - missing environment variable", isError: true, config: ScalerConfig{ + {name: "from env - missing environment variable", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "targetValue": "11", "metricId": "unittest/test", "metricAggregationTimespan": "01:02", "metricAggregationType": "max", "metricFilter": "cloud/roleName eq 'test'", "activeDirectoryClientIdFromEnv": "MISSING_AD_CLIENT_ID", "activeDirectoryClientPasswordFromEnv": "AD_CLIENT_PASSWORD", "applicationInsightsIdFromEnv": "APP_INSIGHTS_ID", "tenantIdFromEnv": "TENANT_ID", @@ -192,7 +193,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "AD_CLIENT_ID": "5678", "AD_CLIENT_PASSWORD": "pw", "APP_INSIGHTS_ID": "1234", "TENANT_ID": "1234", }, }}, - {name: "known Azure Cloud", isError: false, config: ScalerConfig{ + {name: "known Azure Cloud", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "metricAggregationTimespan": "00:01", "metricAggregationType": "count", "metricId": "unittest/test", "targetValue": "10", "applicationInsightsId": "appinsightid", "tenantId": "tenantid", @@ -202,7 +203,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "tenantId": "tenantId", "activeDirectoryClientId": "adClientId", "activeDirectoryClientPassword": "adClientPassword", }, }}, - {name: "private cloud", isError: false, config: ScalerConfig{ + {name: "private cloud", isError: false, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "metricAggregationTimespan": "00:01", "metricAggregationType": "count", "metricId": "unittest/test", "targetValue": "10", "applicationInsightsId": "appinsightid", "tenantId": "tenantid", @@ -212,7 +213,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "tenantId": "tenantId", "activeDirectoryClientId": "adClientId", "activeDirectoryClientPassword": "adClientPassword", }, }}, - {name: "private cloud - missing app insights resource URL", isError: true, config: ScalerConfig{ + {name: "private cloud - missing app insights resource URL", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "metricAggregationTimespan": "00:01", "metricAggregationType": "count", "metricId": "unittest/test", "targetValue": "10", "applicationInsightsId": "appinsightid", "tenantId": "tenantid", @@ -222,7 +223,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "tenantId": "tenantId", "activeDirectoryClientId": "adClientId", "activeDirectoryClientPassword": "adClientPassword", }, }}, - {name: "private cloud - missing active directory endpoint", isError: true, config: ScalerConfig{ + {name: "private cloud - missing active directory endpoint", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "metricAggregationTimespan": "00:01", "metricAggregationType": "count", "metricId": "unittest/test", "targetValue": "10", "applicationInsightsId": "appinsightid", "tenantId": "tenantid", @@ -232,7 +233,7 @@ var azureAppInsightsScalerData = []azureAppInsightsScalerTestData{ "tenantId": "tenantId", "activeDirectoryClientId": "adClientId", "activeDirectoryClientPassword": "adClientPassword", }, }}, - {name: "unsupported cloud", isError: true, config: ScalerConfig{ + {name: "unsupported cloud", isError: true, config: scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "metricAggregationTimespan": "00:01", "metricAggregationType": "count", "metricId": "unittest/test", "targetValue": "10", "applicationInsightsId": "appinsightid", "tenantId": "tenantid", diff --git a/pkg/scalers/azure_blob_scaler.go b/pkg/scalers/azure_blob_scaler.go index af61f52c269..744982a73b2 100644 --- a/pkg/scalers/azure_blob_scaler.go +++ b/pkg/scalers/azure_blob_scaler.go @@ -29,6 +29,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -49,7 +50,7 @@ type azureBlobScaler struct { } // NewAzureBlobScaler creates a new azureBlobScaler -func NewAzureBlobScaler(config *ScalerConfig) (Scaler, error) { +func NewAzureBlobScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -71,7 +72,7 @@ func NewAzureBlobScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseAzureBlobMetadata(config *ScalerConfig, logger logr.Logger) (*azure.BlobMetadata, kedav1alpha1.AuthPodIdentity, error) { +func parseAzureBlobMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*azure.BlobMetadata, kedav1alpha1.AuthPodIdentity, error) { meta := azure.BlobMetadata{} meta.TargetBlobCount = defaultTargetBlobCount meta.BlobDelimiter = defaultBlobDelimiter diff --git a/pkg/scalers/azure_blob_scaler_test.go b/pkg/scalers/azure_blob_scaler_test.go index de40e5e7995..3e49443f426 100644 --- a/pkg/scalers/azure_blob_scaler_test.go +++ b/pkg/scalers/azure_blob_scaler_test.go @@ -24,6 +24,7 @@ import ( "github.com/go-logr/logr" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testAzBlobResolvedEnv = map[string]string{ @@ -108,7 +109,7 @@ var azBlobMetricIdentifiers = []azBlobMetricIdentifier{ func TestAzBlobParseMetadata(t *testing.T) { for _, testData := range testAzBlobMetadata { - _, podIdentity, err := parseAzureBlobMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, + _, podIdentity, err := parseAzureBlobMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.podIdentity}}, logr.Discard()) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -125,7 +126,7 @@ func TestAzBlobParseMetadata(t *testing.T) { func TestAzBlobGetMetricSpecForScaling(t *testing.T) { for _, testData := range azBlobMetricIdentifiers { ctx := context.Background() - meta, podIdentity, err := parseAzureBlobMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, + meta, podIdentity, err := parseAzureBlobMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.metadataTestData.podIdentity}, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { diff --git a/pkg/scalers/azure_data_explorer_scaler.go b/pkg/scalers/azure_data_explorer_scaler.go index f9c1c31965e..d5d16a5bd53 100644 --- a/pkg/scalers/azure_data_explorer_scaler.go +++ b/pkg/scalers/azure_data_explorer_scaler.go @@ -28,6 +28,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -42,7 +43,7 @@ type azureDataExplorerScaler struct { const adxName = "azure-data-explorer" -func NewAzureDataExplorerScaler(config *ScalerConfig) (Scaler, error) { +func NewAzureDataExplorerScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -71,7 +72,7 @@ func NewAzureDataExplorerScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseAzureDataExplorerMetadata(config *ScalerConfig, logger logr.Logger) (*azure.DataExplorerMetadata, error) { +func parseAzureDataExplorerMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*azure.DataExplorerMetadata, error) { metadata, err := parseAzureDataExplorerAuthParams(config, logger) if err != nil { return nil, err @@ -138,7 +139,7 @@ func parseAzureDataExplorerMetadata(config *ScalerConfig, logger logr.Logger) (* return metadata, nil } -func parseAzureDataExplorerAuthParams(config *ScalerConfig, logger logr.Logger) (*azure.DataExplorerMetadata, error) { +func parseAzureDataExplorerAuthParams(config *scalersconfig.ScalerConfig, logger logr.Logger) (*azure.DataExplorerMetadata, error) { metadata := azure.DataExplorerMetadata{} switch config.PodIdentity.Provider { diff --git a/pkg/scalers/azure_data_explorer_scaler_test.go b/pkg/scalers/azure_data_explorer_scaler_test.go index f6748ea3095..bf545e7a7a0 100644 --- a/pkg/scalers/azure_data_explorer_scaler_test.go +++ b/pkg/scalers/azure_data_explorer_scaler_test.go @@ -24,6 +24,7 @@ import ( "github.com/go-logr/logr" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -111,7 +112,7 @@ func TestDataExplorerParseMetadata(t *testing.T) { // Auth through clientId, clientSecret and tenantId for id, testData := range testDataExplorerMetadataWithClientAndSecret { _, err := parseAzureDataExplorerMetadata( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: dataExplorerResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: map[string]string{}, @@ -129,7 +130,7 @@ func TestDataExplorerParseMetadata(t *testing.T) { // Auth through Pod Identity for _, testData := range testDataExplorerMetadataWithPodIdentity { _, err := parseAzureDataExplorerMetadata( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: dataExplorerResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: map[string]string{}, @@ -146,7 +147,7 @@ func TestDataExplorerParseMetadata(t *testing.T) { // Auth through Workload Identity for _, testData := range testDataExplorerMetadataWithPodIdentity { _, err := parseAzureDataExplorerMetadata( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: dataExplorerResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: map[string]string{}, @@ -164,7 +165,7 @@ func TestDataExplorerParseMetadata(t *testing.T) { func TestDataExplorerGetMetricSpecForScaling(t *testing.T) { for id, testData := range testDataExplorerMetricIdentifiers { meta, err := parseAzureDataExplorerMetadata( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: dataExplorerResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: map[string]string{}, diff --git a/pkg/scalers/azure_eventhub_scaler.go b/pkg/scalers/azure_eventhub_scaler.go index a8a696a872e..1e92c7ea491 100644 --- a/pkg/scalers/azure_eventhub_scaler.go +++ b/pkg/scalers/azure_eventhub_scaler.go @@ -34,6 +34,7 @@ import ( "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -65,7 +66,7 @@ type eventHubMetadata struct { } // NewAzureEventHubScaler creates a new scaler for eventHub -func NewAzureEventHubScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewAzureEventHubScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -93,7 +94,7 @@ func NewAzureEventHubScaler(ctx context.Context, config *ScalerConfig) (Scaler, } // parseAzureEventHubMetadata parses metadata -func parseAzureEventHubMetadata(logger logr.Logger, config *ScalerConfig) (*eventHubMetadata, error) { +func parseAzureEventHubMetadata(logger logr.Logger, config *scalersconfig.ScalerConfig) (*eventHubMetadata, error) { meta := eventHubMetadata{ eventHubInfo: azure.EventHubInfo{}, } @@ -111,7 +112,7 @@ func parseAzureEventHubMetadata(logger logr.Logger, config *ScalerConfig) (*even return &meta, nil } -func parseCommonAzureEventHubMetadata(config *ScalerConfig, meta *eventHubMetadata) error { +func parseCommonAzureEventHubMetadata(config *scalersconfig.ScalerConfig, meta *eventHubMetadata) error { meta.threshold = defaultEventHubMessageThreshold if val, ok := config.TriggerMetadata[thresholdMetricName]; ok { @@ -194,7 +195,7 @@ func parseCommonAzureEventHubMetadata(config *ScalerConfig, meta *eventHubMetada return nil } -func parseAzureEventHubAuthenticationMetadata(logger logr.Logger, config *ScalerConfig, meta *eventHubMetadata) error { +func parseAzureEventHubAuthenticationMetadata(logger logr.Logger, config *scalersconfig.ScalerConfig, meta *eventHubMetadata) error { meta.eventHubInfo.PodIdentity = config.PodIdentity switch config.PodIdentity.Provider { diff --git a/pkg/scalers/azure_eventhub_scaler_test.go b/pkg/scalers/azure_eventhub_scaler_test.go index 908b17bcf2b..2717ebaf84a 100644 --- a/pkg/scalers/azure_eventhub_scaler_test.go +++ b/pkg/scalers/azure_eventhub_scaler_test.go @@ -14,6 +14,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -276,7 +277,7 @@ var testEventHubScaler = azureEventHubScaler{ func TestParseEventHubMetadata(t *testing.T) { // Test first with valid resolved environment for _, testData := range parseEventHubMetadataDataset { - _, err := parseAzureEventHubMetadata(logr.Discard(), &ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: map[string]string{}}) + _, err := parseAzureEventHubMetadata(logr.Discard(), &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: map[string]string{}}) if err != nil && !testData.isError { t.Errorf("Expected success but got error: %s", err) @@ -287,7 +288,7 @@ func TestParseEventHubMetadata(t *testing.T) { } for _, testData := range parseEventHubMetadataDatasetWithPodIdentity { - _, err := parseAzureEventHubMetadata(logr.Discard(), &ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: sampleEventHubResolvedEnv, + _, err := parseAzureEventHubMetadata(logr.Discard(), &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: sampleEventHubResolvedEnv, AuthParams: map[string]string{}, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzure}}) if err != nil && !testData.isError { @@ -299,7 +300,7 @@ func TestParseEventHubMetadata(t *testing.T) { } for _, testData := range parseEventHubMetadataDatasetWithPodIdentity { - _, err := parseAzureEventHubMetadata(logr.Discard(), &ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: sampleEventHubResolvedEnv, + _, err := parseAzureEventHubMetadata(logr.Discard(), &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: sampleEventHubResolvedEnv, AuthParams: map[string]string{}, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzureWorkload}}) if err != nil && !testData.isError { @@ -646,7 +647,7 @@ func DeleteContainerInStorage(ctx context.Context, endpoint *url.URL, credential func TestEventHubGetMetricSpecForScaling(t *testing.T) { for _, testData := range eventHubMetricIdentifiers { - meta, err := parseAzureEventHubMetadata(logr.Discard(), &ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: sampleEventHubResolvedEnv, AuthParams: map[string]string{}, TriggerIndex: testData.triggerIndex}) + meta, err := parseAzureEventHubMetadata(logr.Discard(), &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: sampleEventHubResolvedEnv, AuthParams: map[string]string{}, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/azure_log_analytics_scaler.go b/pkg/scalers/azure_log_analytics_scaler.go index 2079028b544..b07abdacf57 100644 --- a/pkg/scalers/azure_log_analytics_scaler.go +++ b/pkg/scalers/azure_log_analytics_scaler.go @@ -38,6 +38,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -110,7 +111,7 @@ var logAnalyticsResourceURLInCloud = map[string]string{ } // NewAzureLogAnalyticsScaler creates a new Azure Log Analytics Scaler -func NewAzureLogAnalyticsScaler(config *ScalerConfig) (Scaler, error) { +func NewAzureLogAnalyticsScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -133,7 +134,7 @@ func NewAzureLogAnalyticsScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseAzureLogAnalyticsMetadata(config *ScalerConfig) (*azureLogAnalyticsMetadata, error) { +func parseAzureLogAnalyticsMetadata(config *scalersconfig.ScalerConfig) (*azureLogAnalyticsMetadata, error) { meta := azureLogAnalyticsMetadata{} switch config.PodIdentity.Provider { case "", kedav1alpha1.PodIdentityProviderNone: @@ -243,7 +244,7 @@ func parseAzureLogAnalyticsMetadata(config *ScalerConfig) (*azureLogAnalyticsMet // getParameterFromConfig gets the parameter from the configs, if checkAuthParams is true // then AuthParams is also check for the parameter -func getParameterFromConfig(config *ScalerConfig, parameter string, checkAuthParams bool) (string, error) { +func getParameterFromConfig(config *scalersconfig.ScalerConfig, parameter string, checkAuthParams bool) (string, error) { if val, ok := config.AuthParams[parameter]; checkAuthParams && ok && val != "" { return val, nil } else if val, ok := config.TriggerMetadata[parameter]; ok && val != "" { diff --git a/pkg/scalers/azure_log_analytics_scaler_test.go b/pkg/scalers/azure_log_analytics_scaler_test.go index 6703ba658af..4de4c714723 100644 --- a/pkg/scalers/azure_log_analytics_scaler_test.go +++ b/pkg/scalers/azure_log_analytics_scaler_test.go @@ -22,6 +22,7 @@ import ( "testing" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -129,7 +130,7 @@ var testLogAnalyticsMetadataWithPodIdentity = []parseLogAnalyticsMetadataTestDat func TestLogAnalyticsParseMetadata(t *testing.T) { for _, testData := range testLogAnalyticsMetadata { - _, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, + _, err := parseAzureLogAnalyticsMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: nil, PodIdentity: kedav1alpha1.AuthPodIdentity{}}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -141,7 +142,7 @@ func TestLogAnalyticsParseMetadata(t *testing.T) { // test with missing auth params should all fail for _, testData := range testLogAnalyticsMetadataWithEmptyAuthParams { - _, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, + _, err := parseAzureLogAnalyticsMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: emptyLogAnalyticsAuthParams, PodIdentity: kedav1alpha1.AuthPodIdentity{}}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -153,7 +154,7 @@ func TestLogAnalyticsParseMetadata(t *testing.T) { // test with complete auth params should not fail for _, testData := range testLogAnalyticsMetadataWithAuthParams { - _, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, + _, err := parseAzureLogAnalyticsMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: LogAnalyticsAuthParams, PodIdentity: kedav1alpha1.AuthPodIdentity{}}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -165,7 +166,7 @@ func TestLogAnalyticsParseMetadata(t *testing.T) { // test with podIdentity params should not fail for _, testData := range testLogAnalyticsMetadataWithPodIdentity { - _, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, + _, err := parseAzureLogAnalyticsMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: LogAnalyticsAuthParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzure}}) if err != nil && !testData.isError { @@ -178,7 +179,7 @@ func TestLogAnalyticsParseMetadata(t *testing.T) { // test with workload identity params should not fail for _, testData := range testLogAnalyticsMetadataWithPodIdentity { - _, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, + _, err := parseAzureLogAnalyticsMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: LogAnalyticsAuthParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderAzureWorkload}}) if err != nil && !testData.isError { @@ -192,7 +193,7 @@ func TestLogAnalyticsParseMetadata(t *testing.T) { func TestLogAnalyticsGetMetricSpecForScaling(t *testing.T) { for _, testData := range LogAnalyticsMetricIdentifiers { - meta, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, + meta, err := parseAzureLogAnalyticsMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: nil, PodIdentity: kedav1alpha1.AuthPodIdentity{}, TriggerIndex: testData.triggerIndex}) if err != nil { @@ -232,7 +233,7 @@ var testParseMetadataUnsafeSsl = []parseLogAnalyticsMetadataTestUnsafeSsl{ func TestLogAnalyticsParseMetadataUnsafeSsl(t *testing.T) { for _, testData := range testParseMetadataUnsafeSsl { - meta, err := parseAzureLogAnalyticsMetadata(&ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, + meta, err := parseAzureLogAnalyticsMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleLogAnalyticsResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: nil, PodIdentity: kedav1alpha1.AuthPodIdentity{}}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) diff --git a/pkg/scalers/azure_monitor_scaler.go b/pkg/scalers/azure_monitor_scaler.go index 64564babba4..2d1ad185b57 100644 --- a/pkg/scalers/azure_monitor_scaler.go +++ b/pkg/scalers/azure_monitor_scaler.go @@ -29,6 +29,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -53,7 +54,7 @@ type azureMonitorMetadata struct { } // NewAzureMonitorScaler creates a new AzureMonitorScaler -func NewAzureMonitorScaler(config *ScalerConfig) (Scaler, error) { +func NewAzureMonitorScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -74,7 +75,7 @@ func NewAzureMonitorScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseAzureMonitorMetadata(config *ScalerConfig, logger logr.Logger) (*azureMonitorMetadata, error) { +func parseAzureMonitorMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*azureMonitorMetadata, error) { meta := azureMonitorMetadata{ azureMonitorInfo: azure.MonitorInfo{}, } @@ -191,7 +192,7 @@ func parseAzureMonitorMetadata(config *ScalerConfig, logger logr.Logger) (*azure } // parseAzurePodIdentityParams gets the activeDirectory clientID and password -func parseAzurePodIdentityParams(config *ScalerConfig) (clientID string, clientPassword string, err error) { +func parseAzurePodIdentityParams(config *scalersconfig.ScalerConfig) (clientID string, clientPassword string, err error) { switch config.PodIdentity.Provider { case "", kedav1alpha1.PodIdentityProviderNone: clientID, err = getParameterFromConfig(config, "activeDirectoryClientId", true) diff --git a/pkg/scalers/azure_monitor_scaler_test.go b/pkg/scalers/azure_monitor_scaler_test.go index a328bdada05..024166599d6 100644 --- a/pkg/scalers/azure_monitor_scaler_test.go +++ b/pkg/scalers/azure_monitor_scaler_test.go @@ -23,6 +23,7 @@ import ( "github.com/go-logr/logr" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -111,7 +112,7 @@ var azMonitorMetricIdentifiers = []azMonitorMetricIdentifier{ func TestAzMonitorParseMetadata(t *testing.T) { for _, testData := range testParseAzMonitorMetadata { - _, err := parseAzureMonitorMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, + _, err := parseAzureMonitorMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.podIdentity}}, logr.Discard()) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -124,7 +125,7 @@ func TestAzMonitorParseMetadata(t *testing.T) { func TestAzMonitorGetMetricSpecForScaling(t *testing.T) { for _, testData := range azMonitorMetricIdentifiers { - meta, err := parseAzureMonitorMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, + meta, err := parseAzureMonitorMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.metadataTestData.podIdentity}, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { diff --git a/pkg/scalers/azure_pipelines_scaler.go b/pkg/scalers/azure_pipelines_scaler.go index e3b61095fe7..a6711fb0fbd 100644 --- a/pkg/scalers/azure_pipelines_scaler.go +++ b/pkg/scalers/azure_pipelines_scaler.go @@ -20,6 +20,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -156,7 +157,7 @@ type authContext struct { } // NewAzurePipelinesScaler creates a new AzurePipelinesScaler -func NewAzurePipelinesScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewAzurePipelinesScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { httpClient := kedautil.CreateHTTPClient(config.GlobalHTTPTimeout, false) logger := InitializeLogger(config, "azure_pipelines_scaler") @@ -179,7 +180,7 @@ func NewAzurePipelinesScaler(ctx context.Context, config *ScalerConfig) (Scaler, }, nil } -func getAuthMethod(logger logr.Logger, config *ScalerConfig) (string, *azidentity.ChainedTokenCredential, kedav1alpha1.AuthPodIdentity, error) { +func getAuthMethod(logger logr.Logger, config *scalersconfig.ScalerConfig) (string, *azidentity.ChainedTokenCredential, kedav1alpha1.AuthPodIdentity, error) { pat := "" if val, ok := config.AuthParams["personalAccessToken"]; ok && val != "" { // Found the personalAccessToken in a parameter from TriggerAuthentication @@ -203,7 +204,7 @@ func getAuthMethod(logger logr.Logger, config *ScalerConfig) (string, *azidentit return pat, nil, kedav1alpha1.AuthPodIdentity{}, nil } -func parseAzurePipelinesMetadata(ctx context.Context, logger logr.Logger, config *ScalerConfig, httpClient *http.Client) (*azurePipelinesMetadata, kedav1alpha1.AuthPodIdentity, error) { +func parseAzurePipelinesMetadata(ctx context.Context, logger logr.Logger, config *scalersconfig.ScalerConfig, httpClient *http.Client) (*azurePipelinesMetadata, kedav1alpha1.AuthPodIdentity, error) { meta := azurePipelinesMetadata{} meta.targetPipelinesQueueLength = defaultTargetPipelinesQueueLength @@ -391,7 +392,7 @@ func getAzurePipelineRequest(ctx context.Context, logger logr.Logger, urlString return []byte{}, fmt.Errorf("cannot create workload identity credentials: %w", err) } logger.V(1).Info("token acquired setting auth header as 'bearer XXXXXX'") - req.Header.Set("Authorization", "Bearer "+aadToken) + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", aadToken)) } r, err := httpClient.Do(req) diff --git a/pkg/scalers/azure_pipelines_scaler_test.go b/pkg/scalers/azure_pipelines_scaler_test.go index 4e6f2436bc7..f65460ac3b4 100644 --- a/pkg/scalers/azure_pipelines_scaler_test.go +++ b/pkg/scalers/azure_pipelines_scaler_test.go @@ -8,6 +8,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const loadCount = 1000 // the size of the pretend pool completed of job requests @@ -72,7 +74,7 @@ func TestParseAzurePipelinesMetadata(t *testing.T) { logger := logr.Discard() - _, _, err := parseAzurePipelinesMetadata(context.TODO(), logger, &ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams}, http.DefaultClient) + _, _, err := parseAzurePipelinesMetadata(context.TODO(), logger, &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams}, http.DefaultClient) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -126,7 +128,7 @@ func TestValidateAzurePipelinesPool(t *testing.T) { "personalAccessToken": "PAT", } logger := logr.Discard() - _, _, err := parseAzurePipelinesMetadata(context.TODO(), logger, &ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: nil, AuthParams: authParams}, http.DefaultClient) + _, _, err := parseAzurePipelinesMetadata(context.TODO(), logger, &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: nil, AuthParams: authParams}, http.DefaultClient) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -166,7 +168,7 @@ func TestAzurePipelinesGetMetricSpecForScaling(t *testing.T) { logger := logr.Discard() - meta, _, err := parseAzurePipelinesMetadata(context.TODO(), logger, &ScalerConfig{TriggerMetadata: metadata, ResolvedEnv: nil, AuthParams: authParams, TriggerIndex: testData.triggerIndex}, http.DefaultClient) + meta, _, err := parseAzurePipelinesMetadata(context.TODO(), logger, &scalersconfig.ScalerConfig{TriggerMetadata: metadata, ResolvedEnv: nil, AuthParams: authParams, TriggerIndex: testData.triggerIndex}, http.DefaultClient) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/azure_queue_scaler.go b/pkg/scalers/azure_queue_scaler.go index d77d7f08db7..6c4c0dccdfe 100644 --- a/pkg/scalers/azure_queue_scaler.go +++ b/pkg/scalers/azure_queue_scaler.go @@ -28,6 +28,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -57,7 +58,7 @@ type azureQueueMetadata struct { } // NewAzureQueueScaler creates a new scaler for queue -func NewAzureQueueScaler(config *ScalerConfig) (Scaler, error) { +func NewAzureQueueScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -79,7 +80,7 @@ func NewAzureQueueScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseAzureQueueMetadata(config *ScalerConfig, logger logr.Logger) (*azureQueueMetadata, kedav1alpha1.AuthPodIdentity, error) { +func parseAzureQueueMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*azureQueueMetadata, kedav1alpha1.AuthPodIdentity, error) { meta := azureQueueMetadata{} meta.targetQueueLength = defaultTargetQueueLength diff --git a/pkg/scalers/azure_queue_scaler_test.go b/pkg/scalers/azure_queue_scaler_test.go index 948198ab4fa..aaee8e46151 100644 --- a/pkg/scalers/azure_queue_scaler_test.go +++ b/pkg/scalers/azure_queue_scaler_test.go @@ -24,6 +24,7 @@ import ( "github.com/go-logr/logr" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testAzQueueResolvedEnv = map[string]string{ @@ -104,7 +105,7 @@ var azQueueMetricIdentifiers = []azQueueMetricIdentifier{ func TestAzQueueParseMetadata(t *testing.T) { for _, testData := range testAzQueueMetadata { - _, podIdentity, err := parseAzureQueueMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, + _, podIdentity, err := parseAzureQueueMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.podIdentity}}, logr.Discard()) @@ -122,7 +123,7 @@ func TestAzQueueParseMetadata(t *testing.T) { func TestAzQueueGetMetricSpecForScaling(t *testing.T) { for _, testData := range azQueueMetricIdentifiers { - meta, podIdentity, err := parseAzureQueueMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, + meta, podIdentity, err := parseAzureQueueMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.metadataTestData.podIdentity}, TriggerIndex: testData.triggerIndex}, logr.Discard()) diff --git a/pkg/scalers/azure_servicebus_scaler.go b/pkg/scalers/azure_servicebus_scaler.go index 861c47c1558..b3ee21614c2 100755 --- a/pkg/scalers/azure_servicebus_scaler.go +++ b/pkg/scalers/azure_servicebus_scaler.go @@ -30,6 +30,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -69,7 +70,7 @@ type azureServiceBusMetadata struct { } // NewAzureServiceBusScaler creates a new AzureServiceBusScaler -func NewAzureServiceBusScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewAzureServiceBusScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -92,7 +93,7 @@ func NewAzureServiceBusScaler(ctx context.Context, config *ScalerConfig) (Scaler } // Creates an azureServiceBusMetadata struct from input metadata/env variables -func parseAzureServiceBusMetadata(config *ScalerConfig, logger logr.Logger) (*azureServiceBusMetadata, error) { +func parseAzureServiceBusMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*azureServiceBusMetadata, error) { meta := azureServiceBusMetadata{} meta.entityType = none meta.targetLength = defaultTargetMessageCount diff --git a/pkg/scalers/azure_servicebus_scaler_test.go b/pkg/scalers/azure_servicebus_scaler_test.go index 7e76d6632c1..149538864b1 100755 --- a/pkg/scalers/azure_servicebus_scaler_test.go +++ b/pkg/scalers/azure_servicebus_scaler_test.go @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/assert" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -167,7 +168,7 @@ var getServiceBusLengthTestScalers = []azureServiceBusScaler{ func TestParseServiceBusMetadata(t *testing.T) { for index, testData := range parseServiceBusMetadataDataset { - meta, err := parseAzureServiceBusMetadata(&ScalerConfig{ResolvedEnv: sampleResolvedEnv, + meta, err := parseAzureServiceBusMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.podIdentity}, TriggerIndex: 0}, logr.Discard()) @@ -192,7 +193,7 @@ func TestParseServiceBusMetadata(t *testing.T) { func TestGetServiceBusAdminClientIsCached(t *testing.T) { testData := azServiceBusMetricIdentifiers[0] - meta, err := parseAzureServiceBusMetadata(&ScalerConfig{ResolvedEnv: connectionResolvedEnv, + meta, err := parseAzureServiceBusMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: connectionResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.metadataTestData.podIdentity}, TriggerIndex: testData.triggerIndex}, logr.Discard()) @@ -242,7 +243,7 @@ func TestGetServiceBusLength(t *testing.T) { func TestAzServiceBusGetMetricSpecForScaling(t *testing.T) { for _, testData := range azServiceBusMetricIdentifiers { - meta, err := parseAzureServiceBusMetadata(&ScalerConfig{ResolvedEnv: connectionResolvedEnv, + meta, err := parseAzureServiceBusMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: connectionResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.metadataTestData.podIdentity}, TriggerIndex: testData.triggerIndex}, logr.Discard()) diff --git a/pkg/scalers/cassandra_scaler.go b/pkg/scalers/cassandra_scaler.go index fc367473ed0..b224f99be72 100644 --- a/pkg/scalers/cassandra_scaler.go +++ b/pkg/scalers/cassandra_scaler.go @@ -12,6 +12,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -39,7 +40,7 @@ type CassandraMetadata struct { } // NewCassandraScaler creates a new Cassandra scaler. -func NewCassandraScaler(config *ScalerConfig) (Scaler, error) { +func NewCassandraScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -66,7 +67,7 @@ func NewCassandraScaler(config *ScalerConfig) (Scaler, error) { } // parseCassandraMetadata parses the metadata and returns a CassandraMetadata or an error if the ScalerConfig is invalid. -func parseCassandraMetadata(config *ScalerConfig) (*CassandraMetadata, error) { +func parseCassandraMetadata(config *scalersconfig.ScalerConfig) (*CassandraMetadata, error) { meta := CassandraMetadata{} if val, ok := config.TriggerMetadata["query"]; ok { diff --git a/pkg/scalers/cassandra_scaler_test.go b/pkg/scalers/cassandra_scaler_test.go index b791efbf08e..730055e2148 100644 --- a/pkg/scalers/cassandra_scaler_test.go +++ b/pkg/scalers/cassandra_scaler_test.go @@ -6,6 +6,8 @@ import ( "github.com/go-logr/logr" "github.com/gocql/gocql" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseCassandraMetadataTestData struct { @@ -53,7 +55,7 @@ var cassandraMetricIdentifiers = []cassandraMetricIdentifier{ func TestCassandraParseMetadata(t *testing.T) { testCaseNum := 1 for _, testData := range testCassandraMetadata { - _, err := parseCassandraMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, err := parseCassandraMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Errorf("Expected success but got error for unit test # %v", testCaseNum) } @@ -66,7 +68,7 @@ func TestCassandraParseMetadata(t *testing.T) { func TestCassandraGetMetricSpecForScaling(t *testing.T) { for _, testData := range cassandraMetricIdentifiers { - meta, err := parseCassandraMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex, AuthParams: testData.metadataTestData.authParams}) + meta, err := parseCassandraMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex, AuthParams: testData.metadataTestData.authParams}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/couchdb_scaler.go b/pkg/scalers/couchdb_scaler.go index 8a851be1af8..62ab5890493 100644 --- a/pkg/scalers/couchdb_scaler.go +++ b/pkg/scalers/couchdb_scaler.go @@ -13,6 +13,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -96,7 +97,7 @@ func (s *couchDBScaler) getQueryResult(ctx context.Context) (int64, error) { return count, nil } -func parseCouchDBMetadata(config *ScalerConfig) (*couchDBMetadata, string, error) { +func parseCouchDBMetadata(config *scalersconfig.ScalerConfig) (*couchDBMetadata, string, error) { var connStr string var err error meta := couchDBMetadata{} @@ -183,7 +184,7 @@ func parseCouchDBMetadata(config *ScalerConfig) (*couchDBMetadata, string, error return &meta, connStr, nil } -func NewCouchDBScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewCouchDBScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) diff --git a/pkg/scalers/couchdb_scaler_test.go b/pkg/scalers/couchdb_scaler_test.go index c7b69aa7157..af7ae36b9b1 100644 --- a/pkg/scalers/couchdb_scaler_test.go +++ b/pkg/scalers/couchdb_scaler_test.go @@ -7,6 +7,8 @@ import ( _ "github.com/go-kivik/couchdb/v3" "github.com/go-kivik/kivik/v3" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testCouchDBResolvedEnv = map[string]string{ @@ -72,7 +74,7 @@ var couchDBMetricIdentifiers = []couchDBMetricIdentifier{ func TestParseCouchDBMetadata(t *testing.T) { for _, testData := range testCOUCHDBMetadata { - _, _, err := parseCouchDBMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, _, err := parseCouchDBMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.raisesError { t.Error("Expected success but got error:", err) } @@ -81,7 +83,7 @@ func TestParseCouchDBMetadata(t *testing.T) { func TestCouchDBGetMetricSpecForScaling(t *testing.T) { for _, testData := range couchDBMetricIdentifiers { - meta, _, err := parseCouchDBMetadata(&ScalerConfig{ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) + meta, _, err := parseCouchDBMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/cpu_memory_scaler.go b/pkg/scalers/cpu_memory_scaler.go index 8fc81a3b998..da5119f3ec0 100644 --- a/pkg/scalers/cpu_memory_scaler.go +++ b/pkg/scalers/cpu_memory_scaler.go @@ -10,6 +10,8 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/metrics/pkg/apis/external_metrics" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type cpuMemoryScaler struct { @@ -26,7 +28,7 @@ type cpuMemoryMetadata struct { } // NewCPUMemoryScaler creates a new cpuMemoryScaler -func NewCPUMemoryScaler(resourceName v1.ResourceName, config *ScalerConfig) (Scaler, error) { +func NewCPUMemoryScaler(resourceName v1.ResourceName, config *scalersconfig.ScalerConfig) (Scaler, error) { logger := InitializeLogger(config, "cpu_memory_scaler") meta, parseErr := parseResourceMetadata(config, logger) @@ -41,7 +43,7 @@ func NewCPUMemoryScaler(resourceName v1.ResourceName, config *ScalerConfig) (Sca }, nil } -func parseResourceMetadata(config *ScalerConfig, logger logr.Logger) (*cpuMemoryMetadata, error) { +func parseResourceMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*cpuMemoryMetadata, error) { meta := &cpuMemoryMetadata{} var value string var ok bool diff --git a/pkg/scalers/cpu_memory_scaler_test.go b/pkg/scalers/cpu_memory_scaler_test.go index afb5698b46a..81f7ea9df9a 100644 --- a/pkg/scalers/cpu_memory_scaler_test.go +++ b/pkg/scalers/cpu_memory_scaler_test.go @@ -8,6 +8,8 @@ import ( "github.com/stretchr/testify/assert" v2 "k8s.io/api/autoscaling/v2" v1 "k8s.io/api/core/v1" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseCPUMemoryMetadataTestData struct { @@ -43,7 +45,7 @@ var testCPUMemoryMetadata = []parseCPUMemoryMetadataTestData{ func TestCPUMemoryParseMetadata(t *testing.T) { for _, testData := range testCPUMemoryMetadata { - config := &ScalerConfig{ + config := &scalersconfig.ScalerConfig{ TriggerMetadata: testData.metadata, MetricType: testData.metricType, } @@ -59,7 +61,7 @@ func TestCPUMemoryParseMetadata(t *testing.T) { func TestGetMetricSpecForScaling(t *testing.T) { // Using trigger.metadata.type field for type - config := &ScalerConfig{ + config := &scalersconfig.ScalerConfig{ TriggerMetadata: validCPUMemoryMetadata, } scaler, _ := NewCPUMemoryScaler(v1.ResourceCPU, config) @@ -70,7 +72,7 @@ func TestGetMetricSpecForScaling(t *testing.T) { assert.Equal(t, metricSpec[0].Resource.Target.Type, v2.UtilizationMetricType) // Using trigger.metricType field for type - config = &ScalerConfig{ + config = &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{"value": "50"}, MetricType: v2.UtilizationMetricType, } @@ -84,7 +86,7 @@ func TestGetMetricSpecForScaling(t *testing.T) { func TestGetContainerMetricSpecForScaling(t *testing.T) { // Using trigger.metadata.type field for type - config := &ScalerConfig{ + config := &scalersconfig.ScalerConfig{ TriggerMetadata: validContainerCPUMemoryMetadata, } scaler, _ := NewCPUMemoryScaler(v1.ResourceCPU, config) @@ -96,7 +98,7 @@ func TestGetContainerMetricSpecForScaling(t *testing.T) { assert.Equal(t, metricSpec[0].ContainerResource.Container, validContainerCPUMemoryMetadata["containerName"]) // Using trigger.metricType field for type - config = &ScalerConfig{ + config = &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{"value": "50", "containerName": "bar"}, MetricType: v2.UtilizationMetricType, } diff --git a/pkg/scalers/cron_scaler.go b/pkg/scalers/cron_scaler.go index f1696ddff16..782082c0098 100644 --- a/pkg/scalers/cron_scaler.go +++ b/pkg/scalers/cron_scaler.go @@ -12,6 +12,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -35,7 +36,7 @@ type cronMetadata struct { } // NewCronScaler creates a new cronScaler -func NewCronScaler(config *ScalerConfig) (Scaler, error) { +func NewCronScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -67,7 +68,7 @@ func getCronTime(location *time.Location, spec string) (int64, error) { return cronTime, nil } -func parseCronMetadata(config *ScalerConfig) (*cronMetadata, error) { +func parseCronMetadata(config *scalersconfig.ScalerConfig) (*cronMetadata, error) { if len(config.TriggerMetadata) == 0 { return nil, fmt.Errorf("invalid Input Metadata. %s", config.TriggerMetadata) } diff --git a/pkg/scalers/cron_scaler_test.go b/pkg/scalers/cron_scaler_test.go index 937a17b865c..2b9f5b810f3 100644 --- a/pkg/scalers/cron_scaler_test.go +++ b/pkg/scalers/cron_scaler_test.go @@ -7,6 +7,8 @@ import ( "github.com/go-logr/logr" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseCronMetadataTestData struct { @@ -61,7 +63,7 @@ var currentHour = time.Now().In(tz).Hour() func TestCronParseMetadata(t *testing.T) { for _, testData := range testCronMetadata { - _, err := parseCronMetadata(&ScalerConfig{TriggerMetadata: testData.metadata}) + _, err := parseCronMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -72,7 +74,7 @@ func TestCronParseMetadata(t *testing.T) { } func TestIsActive(t *testing.T) { - scaler, _ := NewCronScaler(&ScalerConfig{TriggerMetadata: validCronMetadata}) + scaler, _ := NewCronScaler(&scalersconfig.ScalerConfig{TriggerMetadata: validCronMetadata}) _, isActive, _ := scaler.GetMetricsAndActivity(context.TODO(), "ReplicaCount") if currentDay == "Thursday" { assert.Equal(t, isActive, true) @@ -82,7 +84,7 @@ func TestIsActive(t *testing.T) { } func TestIsActiveRange(t *testing.T) { - scaler, _ := NewCronScaler(&ScalerConfig{TriggerMetadata: validCronMetadata2}) + scaler, _ := NewCronScaler(&scalersconfig.ScalerConfig{TriggerMetadata: validCronMetadata2}) _, isActive, _ := scaler.GetMetricsAndActivity(context.TODO(), "ReplicaCount") if currentHour%2 == 0 { assert.Equal(t, isActive, true) @@ -92,7 +94,7 @@ func TestIsActiveRange(t *testing.T) { } func TestGetMetrics(t *testing.T) { - scaler, _ := NewCronScaler(&ScalerConfig{TriggerMetadata: validCronMetadata}) + scaler, _ := NewCronScaler(&scalersconfig.ScalerConfig{TriggerMetadata: validCronMetadata}) metrics, _, _ := scaler.GetMetricsAndActivity(context.TODO(), "ReplicaCount") assert.Equal(t, metrics[0].MetricName, "ReplicaCount") if currentDay == "Thursday" { @@ -103,7 +105,7 @@ func TestGetMetrics(t *testing.T) { } func TestGetMetricsRange(t *testing.T) { - scaler, _ := NewCronScaler(&ScalerConfig{TriggerMetadata: validCronMetadata2}) + scaler, _ := NewCronScaler(&scalersconfig.ScalerConfig{TriggerMetadata: validCronMetadata2}) metrics, _, _ := scaler.GetMetricsAndActivity(context.TODO(), "ReplicaCount") assert.Equal(t, metrics[0].MetricName, "ReplicaCount") if currentHour%2 == 0 { @@ -115,7 +117,7 @@ func TestGetMetricsRange(t *testing.T) { func TestCronGetMetricSpecForScaling(t *testing.T) { for _, testData := range cronMetricIdentifiers { - meta, err := parseCronMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) + meta, err := parseCronMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/datadog_scaler.go b/pkg/scalers/datadog_scaler.go index f53f9faf939..2e0b8882a8c 100644 --- a/pkg/scalers/datadog_scaler.go +++ b/pkg/scalers/datadog_scaler.go @@ -13,6 +13,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -49,7 +50,7 @@ func init() { } // NewDatadogScaler creates a new Datadog scaler -func NewDatadogScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewDatadogScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { logger := InitializeLogger(config, "datadog_scaler") meta, err := parseDatadogMetadata(config, logger) @@ -78,7 +79,7 @@ func parseDatadogQuery(q string) (bool, error) { return true, nil } -func parseDatadogMetadata(config *ScalerConfig, logger logr.Logger) (*datadogMetadata, error) { +func parseDatadogMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*datadogMetadata, error) { meta := datadogMetadata{} if val, ok := config.TriggerMetadata["age"]; ok { @@ -229,7 +230,7 @@ func parseDatadogMetadata(config *ScalerConfig, logger logr.Logger) (*datadogMet } // newDatddogConnection tests a connection to the Datadog API -func newDatadogConnection(ctx context.Context, meta *datadogMetadata, config *ScalerConfig) (*datadog.APIClient, error) { +func newDatadogConnection(ctx context.Context, meta *datadogMetadata, config *scalersconfig.ScalerConfig) (*datadog.APIClient, error) { ctx = context.WithValue( ctx, datadog.ContextAPIKeys, diff --git a/pkg/scalers/datadog_scaler_test.go b/pkg/scalers/datadog_scaler_test.go index 382476e6439..41e32c7f0eb 100644 --- a/pkg/scalers/datadog_scaler_test.go +++ b/pkg/scalers/datadog_scaler_test.go @@ -6,6 +6,8 @@ import ( "github.com/go-logr/logr" v2 "k8s.io/api/autoscaling/v2" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type datadogQueries struct { @@ -135,7 +137,7 @@ var testDatadogMetadata = []datadogAuthMetadataTestData{ func TestDatadogScalerAuthParams(t *testing.T) { for _, testData := range testDatadogMetadata { - _, err := parseDatadogMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams, MetricType: testData.metricType}, logr.Discard()) + _, err := parseDatadogMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams, MetricType: testData.metricType}, logr.Discard()) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -153,7 +155,7 @@ var datadogMetricIdentifiers = []datadogMetricIdentifier{ func TestDatadogGetMetricSpecForScaling(t *testing.T) { for _, testData := range datadogMetricIdentifiers { - meta, err := parseDatadogMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex, MetricType: testData.metadataTestData.metricType}, logr.Discard()) + meta, err := parseDatadogMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex, MetricType: testData.metadataTestData.metricType}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/elasticsearch_scaler.go b/pkg/scalers/elasticsearch_scaler.go index 9a806e1b47f..da7c1c2c1a8 100644 --- a/pkg/scalers/elasticsearch_scaler.go +++ b/pkg/scalers/elasticsearch_scaler.go @@ -16,6 +16,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/util" ) @@ -43,7 +44,7 @@ type elasticsearchMetadata struct { } // NewElasticsearchScaler creates a new elasticsearch scaler -func NewElasticsearchScaler(config *ScalerConfig) (Scaler, error) { +func NewElasticsearchScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -93,7 +94,7 @@ func hasEndpointsConfig(meta *elasticsearchMetadata) bool { return false } -func extractEndpointsConfig(config *ScalerConfig, meta *elasticsearchMetadata) error { +func extractEndpointsConfig(config *scalersconfig.ScalerConfig, meta *elasticsearchMetadata) error { addresses, err := GetFromAuthOrMeta(config, "addresses") if err != nil { return err @@ -115,7 +116,7 @@ func extractEndpointsConfig(config *ScalerConfig, meta *elasticsearchMetadata) e return nil } -func extractCloudConfig(config *ScalerConfig, meta *elasticsearchMetadata) error { +func extractCloudConfig(config *scalersconfig.ScalerConfig, meta *elasticsearchMetadata) error { cloudID, err := GetFromAuthOrMeta(config, "cloudID") if err != nil { return err @@ -138,7 +139,7 @@ var ( ErrElasticsearchConfigConflict = errors.New("can't provide endpoint addresses and cloud config at the same time") ) -func parseElasticsearchMetadata(config *ScalerConfig) (*elasticsearchMetadata, error) { +func parseElasticsearchMetadata(config *scalersconfig.ScalerConfig) (*elasticsearchMetadata, error) { meta := elasticsearchMetadata{} var err error diff --git a/pkg/scalers/elasticsearch_scaler_test.go b/pkg/scalers/elasticsearch_scaler_test.go index 467ac6a6ade..43f9deb0f15 100644 --- a/pkg/scalers/elasticsearch_scaler_test.go +++ b/pkg/scalers/elasticsearch_scaler_test.go @@ -7,6 +7,8 @@ import ( "testing" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseElasticsearchMetadataTestData struct { @@ -295,7 +297,7 @@ var testCases = []parseElasticsearchMetadataTestData{ func TestParseElasticsearchMetadata(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - metadata, err := parseElasticsearchMetadata(&ScalerConfig{ + metadata, err := parseElasticsearchMetadata(&scalersconfig.ScalerConfig{ TriggerMetadata: tc.metadata, AuthParams: tc.authParams, ResolvedEnv: tc.resolvedEnv, @@ -340,7 +342,7 @@ func TestUnsafeSslDefaultValue(t *testing.T) { }, expectedError: nil, } - metadata, err := parseElasticsearchMetadata(&ScalerConfig{ + metadata, err := parseElasticsearchMetadata(&scalersconfig.ScalerConfig{ TriggerMetadata: tc.metadata, AuthParams: tc.authParams, }) @@ -436,7 +438,7 @@ func TestBuildQuery(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - metadata, err := parseElasticsearchMetadata(&ScalerConfig{ + metadata, err := parseElasticsearchMetadata(&scalersconfig.ScalerConfig{ TriggerMetadata: tc.metadata, AuthParams: tc.authParams, }) @@ -454,7 +456,7 @@ func TestElasticsearchGetMetricSpecForScaling(t *testing.T) { for _, testData := range elasticsearchMetricIdentifiers { ctx := context.Background() - meta, err := parseElasticsearchMetadata(&ScalerConfig{ + meta, err := parseElasticsearchMetadata(&scalersconfig.ScalerConfig{ TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex, diff --git a/pkg/scalers/etcd_scaler.go b/pkg/scalers/etcd_scaler.go index 25d9c750c2a..83835bed93e 100644 --- a/pkg/scalers/etcd_scaler.go +++ b/pkg/scalers/etcd_scaler.go @@ -14,6 +14,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -52,7 +53,7 @@ type etcdMetadata struct { } // NewEtcdScaler creates a new etcdScaler -func NewEtcdScaler(config *ScalerConfig) (Scaler, error) { +func NewEtcdScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -75,7 +76,7 @@ func NewEtcdScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseEtcdAuthParams(config *ScalerConfig, meta *etcdMetadata) error { +func parseEtcdAuthParams(config *scalersconfig.ScalerConfig, meta *etcdMetadata) error { meta.enableTLS = false if val, ok := config.AuthParams["tls"]; ok { val = strings.TrimSpace(val) @@ -105,7 +106,7 @@ func parseEtcdAuthParams(config *ScalerConfig, meta *etcdMetadata) error { return nil } -func parseEtcdMetadata(config *ScalerConfig) (*etcdMetadata, error) { +func parseEtcdMetadata(config *scalersconfig.ScalerConfig) (*etcdMetadata, error) { meta := &etcdMetadata{} var err error meta.endpoints = strings.Split(config.TriggerMetadata[endpoints], ",") diff --git a/pkg/scalers/etcd_scaler_test.go b/pkg/scalers/etcd_scaler_test.go index 768a4e156d6..9ecdb5b602a 100644 --- a/pkg/scalers/etcd_scaler_test.go +++ b/pkg/scalers/etcd_scaler_test.go @@ -6,6 +6,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseEtcdMetadataTestData struct { @@ -76,7 +78,7 @@ var etcdMetricIdentifiers = []etcdMetricIdentifier{ func TestParseEtcdMetadata(t *testing.T) { for _, testData := range parseEtcdMetadataTestDataset { - meta, err := parseEtcdMetadata(&ScalerConfig{TriggerMetadata: testData.metadata}) + meta, err := parseEtcdMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -91,7 +93,7 @@ func TestParseEtcdMetadata(t *testing.T) { func TestParseEtcdAuthParams(t *testing.T) { for _, testData := range parseEtcdAuthParamsTestDataset { - meta, err := parseEtcdMetadata(&ScalerConfig{TriggerMetadata: validEtcdMetadata, AuthParams: testData.authParams}) + meta, err := parseEtcdMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: validEtcdMetadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -121,7 +123,7 @@ func TestParseEtcdAuthParams(t *testing.T) { func TestEtcdGetMetricSpecForScaling(t *testing.T) { for _, testData := range etcdMetricIdentifiers { - meta, err := parseEtcdMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) + meta, err := parseEtcdMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/external_mock_scaler.go b/pkg/scalers/external_mock_scaler.go index 29564c33515..1e5d7339fd1 100644 --- a/pkg/scalers/external_mock_scaler.go +++ b/pkg/scalers/external_mock_scaler.go @@ -9,6 +9,8 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/metrics/pkg/apis/external_metrics" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ( @@ -26,7 +28,7 @@ var ( type externalMockScaler struct{} -func NewExternalMockScaler(_ *ScalerConfig) (Scaler, error) { +func NewExternalMockScaler(_ *scalersconfig.ScalerConfig) (Scaler, error) { return &externalMockScaler{}, nil } diff --git a/pkg/scalers/external_scaler.go b/pkg/scalers/external_scaler.go index 6b8ab00575d..089dc0cfbfd 100644 --- a/pkg/scalers/external_scaler.go +++ b/pkg/scalers/external_scaler.go @@ -18,6 +18,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" pb "github.com/kedacore/keda/v2/pkg/scalers/externalscaler" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/util" ) @@ -54,7 +55,7 @@ const grpcConfig = `{"loadBalancingConfig": [{"round_robin":{}}]}` // NewExternalScaler creates a new external scaler - calls the GRPC interface // to create a new scaler -func NewExternalScaler(config *ScalerConfig) (Scaler, error) { +func NewExternalScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting external scaler metric type: %w", err) @@ -78,7 +79,7 @@ func NewExternalScaler(config *ScalerConfig) (Scaler, error) { } // NewExternalPushScaler creates a new externalPushScaler push scaler -func NewExternalPushScaler(config *ScalerConfig) (PushScaler, error) { +func NewExternalPushScaler(config *scalersconfig.ScalerConfig) (PushScaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting external scaler metric type: %w", err) @@ -103,7 +104,7 @@ func NewExternalPushScaler(config *ScalerConfig) (PushScaler, error) { }, nil } -func parseExternalScalerMetadata(config *ScalerConfig) (externalScalerMetadata, error) { +func parseExternalScalerMetadata(config *scalersconfig.ScalerConfig) (externalScalerMetadata, error) { meta := externalScalerMetadata{ originalMetadata: config.TriggerMetadata, } diff --git a/pkg/scalers/external_scaler_test.go b/pkg/scalers/external_scaler_test.go index 569368d92a3..f5692a6b172 100644 --- a/pkg/scalers/external_scaler_test.go +++ b/pkg/scalers/external_scaler_test.go @@ -15,6 +15,7 @@ import ( "google.golang.org/grpc/status" pb "github.com/kedacore/keda/v2/pkg/scalers/externalscaler" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var serverRootCA = `-----BEGIN CERTIFICATE----- @@ -74,7 +75,7 @@ var testExternalScalerMetadata = []parseExternalScalerMetadataTestData{ func TestExternalScalerParseMetadata(t *testing.T) { for _, testData := range testExternalScalerMetadata { - metadata, err := parseExternalScalerMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: map[string]string{}, AuthParams: testData.authParams}) + metadata, err := parseExternalScalerMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: map[string]string{}, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -101,7 +102,7 @@ func TestExternalPushScaler_Run(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) for i := 0; i < serverCount*iterationCount; i++ { id := i % serverCount - pushScaler, _ := NewExternalPushScaler(&ScalerConfig{ScalableObjectName: "app", ScalableObjectNamespace: "namespace", TriggerMetadata: map[string]string{"scalerAddress": servers[id].address}, ResolvedEnv: map[string]string{}}) + pushScaler, _ := NewExternalPushScaler(&scalersconfig.ScalerConfig{ScalableObjectName: "app", ScalableObjectNamespace: "namespace", TriggerMetadata: map[string]string{"scalerAddress": servers[id].address}, ResolvedEnv: map[string]string{}}) go pushScaler.Run(ctx, replyCh[i]) } diff --git a/pkg/scalers/externalscaler/externalscaler.pb.go b/pkg/scalers/externalscaler/externalscaler.pb.go index 53515281ab7..39ddf2b34e6 100644 --- a/pkg/scalers/externalscaler/externalscaler.pb.go +++ b/pkg/scalers/externalscaler/externalscaler.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.24.4 +// protoc v4.23.2 // source: externalscaler.proto package externalscaler diff --git a/pkg/scalers/externalscaler/externalscaler_grpc.pb.go b/pkg/scalers/externalscaler/externalscaler_grpc.pb.go index 503b5695932..5489ae58ac4 100644 --- a/pkg/scalers/externalscaler/externalscaler_grpc.pb.go +++ b/pkg/scalers/externalscaler/externalscaler_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.24.4 +// - protoc v4.23.2 // source: externalscaler.proto package externalscaler diff --git a/pkg/scalers/gcp_common.go b/pkg/scalers/gcp/gcp_common.go similarity index 55% rename from pkg/scalers/gcp_common.go rename to pkg/scalers/gcp/gcp_common.go index b50ea9882d2..b6024442175 100644 --- a/pkg/scalers/gcp_common.go +++ b/pkg/scalers/gcp/gcp_common.go @@ -1,4 +1,4 @@ -package scalers +package gcp import ( "context" @@ -10,22 +10,23 @@ import ( "golang.org/x/oauth2/google" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var ( - gcpScopeMonitoringRead = "https://www.googleapis.com/auth/monitoring.read" + GcpScopeMonitoringRead = "https://www.googleapis.com/auth/monitoring.read" - errGoogleApplicationCrendentialsNotFound = errors.New("google application credentials not found") + ErrGoogleApplicationCrendentialsNotFound = errors.New("google application credentials not found") ) -type gcpAuthorizationMetadata struct { +type AuthorizationMetadata struct { GoogleApplicationCredentials string GoogleApplicationCredentialsFile string - podIdentityProviderEnabled bool + PodIdentityProviderEnabled bool } -func (a *gcpAuthorizationMetadata) tokenSource(ctx context.Context, scopes ...string) (oauth2.TokenSource, error) { - if a.podIdentityProviderEnabled { +func (a *AuthorizationMetadata) tokenSource(ctx context.Context, scopes ...string) (oauth2.TokenSource, error) { + if a.PodIdentityProviderEnabled { return google.DefaultTokenSource(ctx, scopes...) } @@ -52,31 +53,31 @@ func (a *gcpAuthorizationMetadata) tokenSource(ctx context.Context, scopes ...st return creds.TokenSource, nil } - return nil, errGoogleApplicationCrendentialsNotFound + return nil, ErrGoogleApplicationCrendentialsNotFound } -func getGCPAuthorization(config *ScalerConfig) (*gcpAuthorizationMetadata, error) { +func GetGCPAuthorization(config *scalersconfig.ScalerConfig) (*AuthorizationMetadata, error) { if config.PodIdentity.Provider == kedav1alpha1.PodIdentityProviderGCP { - return &gcpAuthorizationMetadata{podIdentityProviderEnabled: true}, nil + return &AuthorizationMetadata{PodIdentityProviderEnabled: true}, nil } if creds := config.AuthParams["GoogleApplicationCredentials"]; creds != "" { - return &gcpAuthorizationMetadata{GoogleApplicationCredentials: creds}, nil + return &AuthorizationMetadata{GoogleApplicationCredentials: creds}, nil } if creds := config.TriggerMetadata["credentialsFromEnv"]; creds != "" { - return &gcpAuthorizationMetadata{GoogleApplicationCredentials: config.ResolvedEnv[creds]}, nil + return &AuthorizationMetadata{GoogleApplicationCredentials: config.ResolvedEnv[creds]}, nil } if credsFile := config.TriggerMetadata["credentialsFromEnvFile"]; credsFile != "" { - return &gcpAuthorizationMetadata{GoogleApplicationCredentialsFile: config.ResolvedEnv[credsFile]}, nil + return &AuthorizationMetadata{GoogleApplicationCredentialsFile: config.ResolvedEnv[credsFile]}, nil } - return nil, errGoogleApplicationCrendentialsNotFound + return nil, ErrGoogleApplicationCrendentialsNotFound } -func getGCPOAuth2HTTPTransport(config *ScalerConfig, base http.RoundTripper, scopes ...string) (http.RoundTripper, error) { - a, err := getGCPAuthorization(config) +func GetGCPOAuth2HTTPTransport(config *scalersconfig.ScalerConfig, base http.RoundTripper, scopes ...string) (http.RoundTripper, error) { + a, err := GetGCPAuthorization(config) if err != nil { return nil, err } diff --git a/pkg/scalers/gcp_stackdriver_client.go b/pkg/scalers/gcp/gcp_stackdriver_client.go similarity index 97% rename from pkg/scalers/gcp_stackdriver_client.go rename to pkg/scalers/gcp/gcp_stackdriver_client.go index ca20f3ceb5c..7dd9de3825e 100644 --- a/pkg/scalers/gcp_stackdriver_client.go +++ b/pkg/scalers/gcp/gcp_stackdriver_client.go @@ -1,4 +1,4 @@ -package scalers +package gcp import ( "context" @@ -47,7 +47,7 @@ const ( // StackDriverClient is a generic client to fetch metrics from Stackdriver. Can be used // for a stackdriver scaler in the future type StackDriverClient struct { - metricsClient *monitoring.MetricClient + MetricsClient *monitoring.MetricClient queryClient *monitoring.QueryClient credentials GoogleApplicationCredentials projectID string @@ -74,7 +74,7 @@ func NewStackDriverClient(ctx context.Context, credentials string) (*StackDriver } return &StackDriverClient{ - metricsClient: metricsClient, + MetricsClient: metricsClient, queryClient: queryClient, credentials: gcpCredentials, }, nil @@ -102,7 +102,7 @@ func NewStackDriverClientPodIdentity(ctx context.Context) (*StackDriverClient, e } return &StackDriverClient{ - metricsClient: metricsClient, + MetricsClient: metricsClient, queryClient: queryClient, projectID: project, }, nil @@ -239,7 +239,7 @@ func (s StackDriverClient) GetMetrics( req.Filter = filter // Get an iterator with the list of time series - it := s.metricsClient.ListTimeSeries(ctx, req) + it := s.MetricsClient.ListTimeSeries(ctx, req) var value float64 = -1 @@ -289,7 +289,7 @@ func (s StackDriverClient) QueryMetrics(ctx context.Context, projectID, query st resp, err := it.Next() if err == iterator.Done { - return value, fmt.Errorf("could not find stackdriver metric with filter %s", filter) + return value, fmt.Errorf("could not find stackdriver metric with query %s", req.Query) } if err != nil { @@ -318,7 +318,7 @@ func getActualProjectID(s *StackDriverClient, projectID string) string { return s.credentials.ProjectID } -// buildMQLQuery builds a Monitoring Query Language (MQL) query for the last minute (five for aggregations), +// BuildMQLQuery builds a Monitoring Query Language (MQL) query for the last minute (five for aggregations), // given a resource type, metric, resource name, and an optional aggregation // // example: @@ -329,7 +329,7 @@ func getActualProjectID(s *StackDriverClient, projectID string) string { // | align delta(3m) // | every 3m // | group_by [], count(value) -func (s StackDriverClient) buildMQLQuery(projectID, resourceType, metric, resourceName, aggregation string) (string, error) { +func (s StackDriverClient) BuildMQLQuery(projectID, resourceType, metric, resourceName, aggregation string) (string, error) { th := defaultTimeHorizon if aggregation != "" { th = aggregationTimeHorizon diff --git a/pkg/scalers/gcp_stackdriver_client_test.go b/pkg/scalers/gcp/gcp_stackdriver_client_test.go similarity index 98% rename from pkg/scalers/gcp_stackdriver_client_test.go rename to pkg/scalers/gcp/gcp_stackdriver_client_test.go index 86a7e12ffd0..9d72e55ed18 100644 --- a/pkg/scalers/gcp_stackdriver_client_test.go +++ b/pkg/scalers/gcp/gcp_stackdriver_client_test.go @@ -1,4 +1,4 @@ -package scalers +package gcp import ( "testing" @@ -60,7 +60,7 @@ func TestBuildMQLQuery(t *testing.T) { } { s := &StackDriverClient{} t.Run(tc.name, func(t *testing.T) { - q, err := s.buildMQLQuery("myproject", tc.resourceType, tc.metric, tc.resourceName, tc.aggregation) + q, err := s.BuildMQLQuery("myproject", tc.resourceType, tc.metric, tc.resourceName, tc.aggregation) if tc.isError { assert.Error(t, err) assert.Equal(t, tc.expected, err.Error()) diff --git a/pkg/scalers/gcp_cloud_tasks_scaler.go b/pkg/scalers/gcp_cloud_tasks_scaler.go index 5eaf734e737..4ce8ac567cf 100644 --- a/pkg/scalers/gcp_cloud_tasks_scaler.go +++ b/pkg/scalers/gcp_cloud_tasks_scaler.go @@ -9,6 +9,8 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/gcp" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -19,7 +21,7 @@ const ( ) type gcpCloudTasksScaler struct { - client *StackDriverClient + client *gcp.StackDriverClient metricType v2.MetricTargetType metadata *gcpCloudTaskMetadata logger logr.Logger @@ -31,12 +33,12 @@ type gcpCloudTaskMetadata struct { queueName string projectID string - gcpAuthorization *gcpAuthorizationMetadata + gcpAuthorization *gcp.AuthorizationMetadata triggerIndex int } // NewGcpCloudTasksScaler creates a new cloudTaskScaler -func NewGcpCloudTasksScaler(config *ScalerConfig) (Scaler, error) { +func NewGcpCloudTasksScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -56,7 +58,7 @@ func NewGcpCloudTasksScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseGcpCloudTasksMetadata(config *ScalerConfig) (*gcpCloudTaskMetadata, error) { +func parseGcpCloudTasksMetadata(config *scalersconfig.ScalerConfig) (*gcpCloudTaskMetadata, error) { meta := gcpCloudTaskMetadata{value: cloudTaskDefaultValue} value, valuePresent := config.TriggerMetadata["value"] @@ -97,7 +99,7 @@ func parseGcpCloudTasksMetadata(config *ScalerConfig) (*gcpCloudTaskMetadata, er return nil, fmt.Errorf("no project id given") } - auth, err := getGCPAuthorization(config) + auth, err := gcp.GetGCPAuthorization(config) if err != nil { return nil, err } @@ -108,7 +110,7 @@ func parseGcpCloudTasksMetadata(config *ScalerConfig) (*gcpCloudTaskMetadata, er func (s *gcpCloudTasksScaler) Close(context.Context) error { if s.client != nil { - err := s.client.metricsClient.Close() + err := s.client.MetricsClient.Close() s.client = nil if err != nil { s.logger.Error(err, "error closing StackDriver client") @@ -152,12 +154,12 @@ func (s *gcpCloudTasksScaler) GetMetricsAndActivity(ctx context.Context, metricN } func (s *gcpCloudTasksScaler) setStackdriverClient(ctx context.Context) error { - var client *StackDriverClient + var client *gcp.StackDriverClient var err error - if s.metadata.gcpAuthorization.podIdentityProviderEnabled { - client, err = NewStackDriverClientPodIdentity(ctx) + if s.metadata.gcpAuthorization.PodIdentityProviderEnabled { + client, err = gcp.NewStackDriverClientPodIdentity(ctx) } else { - client, err = NewStackDriverClient(ctx, s.metadata.gcpAuthorization.GoogleApplicationCredentials) + client, err = gcp.NewStackDriverClient(ctx, s.metadata.gcpAuthorization.GoogleApplicationCredentials) } if err != nil { diff --git a/pkg/scalers/gcp_cloud_tasks_scaler_test.go b/pkg/scalers/gcp_cloud_tasks_scaler_test.go index 6fd20234eab..61772272e0a 100644 --- a/pkg/scalers/gcp_cloud_tasks_scaler_test.go +++ b/pkg/scalers/gcp_cloud_tasks_scaler_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testGcpCloudTasksResolvedEnv = map[string]string{ @@ -52,7 +54,7 @@ var gcpCloudTasksMetricIdentifiers = []gcpCloudTasksMetricIdentifier{ func TestGcpCloudTasksParseMetadata(t *testing.T) { for _, testData := range testGcpCloudTasksMetadata { - _, err := parseGcpCloudTasksMetadata(&ScalerConfig{AuthParams: testData.authParams, TriggerMetadata: testData.metadata, ResolvedEnv: testGcpCloudTasksResolvedEnv}) + _, err := parseGcpCloudTasksMetadata(&scalersconfig.ScalerConfig{AuthParams: testData.authParams, TriggerMetadata: testData.metadata, ResolvedEnv: testGcpCloudTasksResolvedEnv}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -64,7 +66,7 @@ func TestGcpCloudTasksParseMetadata(t *testing.T) { func TestGcpCloudTasksGetMetricSpecForScaling(t *testing.T) { for _, testData := range gcpCloudTasksMetricIdentifiers { - meta, err := parseGcpCloudTasksMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testGcpCloudTasksResolvedEnv, TriggerIndex: testData.triggerIndex}) + meta, err := parseGcpCloudTasksMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testGcpCloudTasksResolvedEnv, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/gcp_pubsub_scaler.go b/pkg/scalers/gcp_pubsub_scaler.go index aee3f341831..6f0722a42e0 100644 --- a/pkg/scalers/gcp_pubsub_scaler.go +++ b/pkg/scalers/gcp_pubsub_scaler.go @@ -12,6 +12,8 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/gcp" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -29,7 +31,7 @@ const ( var regexpCompositeSubscriptionIDPrefix = regexp.MustCompile(compositeSubscriptionIDPrefix) type pubsubScaler struct { - client *StackDriverClient + client *gcp.StackDriverClient metricType v2.MetricTargetType metadata *pubsubMetadata logger logr.Logger @@ -43,13 +45,13 @@ type pubsubMetadata struct { // a resource is one of subscription or topic resourceType string resourceName string - gcpAuthorization *gcpAuthorizationMetadata + gcpAuthorization *gcp.AuthorizationMetadata triggerIndex int aggregation string } // NewPubSubScaler creates a new pubsubScaler -func NewPubSubScaler(config *ScalerConfig) (Scaler, error) { +func NewPubSubScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -69,7 +71,7 @@ func NewPubSubScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parsePubSubMetadata(config *ScalerConfig, logger logr.Logger) (*pubsubMetadata, error) { +func parsePubSubMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*pubsubMetadata, error) { meta := pubsubMetadata{mode: pubSubModeSubscriptionSize, value: pubSubDefaultValue} mode, modePresent := config.TriggerMetadata["mode"] @@ -135,7 +137,7 @@ func parsePubSubMetadata(config *ScalerConfig, logger logr.Logger) (*pubsubMetad meta.activationValue = activationValue } - auth, err := getGCPAuthorization(config) + auth, err := gcp.GetGCPAuthorization(config) if err != nil { return nil, err } @@ -146,7 +148,7 @@ func parsePubSubMetadata(config *ScalerConfig, logger logr.Logger) (*pubsubMetad func (s *pubsubScaler) Close(context.Context) error { if s.client != nil { - err := s.client.metricsClient.Close() + err := s.client.MetricsClient.Close() s.client = nil if err != nil { s.logger.Error(err, "error closing StackDriver client") @@ -198,12 +200,12 @@ func (s *pubsubScaler) GetMetricsAndActivity(ctx context.Context, metricName str } func (s *pubsubScaler) setStackdriverClient(ctx context.Context) error { - var client *StackDriverClient + var client *gcp.StackDriverClient var err error - if s.metadata.gcpAuthorization.podIdentityProviderEnabled { - client, err = NewStackDriverClientPodIdentity(ctx) + if s.metadata.gcpAuthorization.PodIdentityProviderEnabled { + client, err = gcp.NewStackDriverClientPodIdentity(ctx) } else { - client, err = NewStackDriverClient(ctx, s.metadata.gcpAuthorization.GoogleApplicationCredentials) + client, err = gcp.NewStackDriverClient(ctx, s.metadata.gcpAuthorization.GoogleApplicationCredentials) } if err != nil { @@ -221,7 +223,7 @@ func (s *pubsubScaler) getMetrics(ctx context.Context, metricType string) (float } } resourceID, projectID := getResourceData(s) - query, err := s.client.buildMQLQuery( + query, err := s.client.BuildMQLQuery( projectID, s.metadata.resourceType, metricType, resourceID, s.metadata.aggregation, ) if err != nil { diff --git a/pkg/scalers/gcp_pubsub_scaler_test.go b/pkg/scalers/gcp_pubsub_scaler_test.go index 3a8c05665fc..bba4516414a 100644 --- a/pkg/scalers/gcp_pubsub_scaler_test.go +++ b/pkg/scalers/gcp_pubsub_scaler_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testPubSubResolvedEnv = map[string]string{ @@ -97,7 +99,7 @@ var gcpSubscriptionDefaults = []gcpPubSubSubscription{ func TestPubSubParseMetadata(t *testing.T) { for _, testData := range testPubSubMetadata { - _, err := parsePubSubMetadata(&ScalerConfig{AuthParams: testData.authParams, TriggerMetadata: testData.metadata, ResolvedEnv: testPubSubResolvedEnv}, logr.Discard()) + _, err := parsePubSubMetadata(&scalersconfig.ScalerConfig{AuthParams: testData.authParams, TriggerMetadata: testData.metadata, ResolvedEnv: testPubSubResolvedEnv}, logr.Discard()) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -109,7 +111,7 @@ func TestPubSubParseMetadata(t *testing.T) { func TestPubSubMetadataDefaultValues(t *testing.T) { for _, testData := range gcpSubscriptionDefaults { - metaData, err := parsePubSubMetadata(&ScalerConfig{AuthParams: testData.metadataTestData.authParams, TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testPubSubResolvedEnv}, logr.Discard()) + metaData, err := parsePubSubMetadata(&scalersconfig.ScalerConfig{AuthParams: testData.metadataTestData.authParams, TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testPubSubResolvedEnv}, logr.Discard()) if err != nil { t.Error("Expected success but got error", err) } @@ -124,7 +126,7 @@ func TestPubSubMetadataDefaultValues(t *testing.T) { func TestGcpPubSubGetMetricSpecForScaling(t *testing.T) { for _, testData := range gcpPubSubMetricIdentifiers { - meta, err := parsePubSubMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testPubSubResolvedEnv, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parsePubSubMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testPubSubResolvedEnv, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -140,7 +142,7 @@ func TestGcpPubSubGetMetricSpecForScaling(t *testing.T) { func TestGcpPubSubSubscriptionName(t *testing.T) { for _, testData := range gcpResourceNameTests { - meta, err := parsePubSubMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testPubSubResolvedEnv, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parsePubSubMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testPubSubResolvedEnv, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/gcp_stackdriver_scaler.go b/pkg/scalers/gcp_stackdriver_scaler.go index 4e01ba327ea..9deedcc3066 100644 --- a/pkg/scalers/gcp_stackdriver_scaler.go +++ b/pkg/scalers/gcp_stackdriver_scaler.go @@ -10,6 +10,8 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/gcp" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -18,7 +20,7 @@ const ( ) type stackdriverScaler struct { - client *StackDriverClient + client *gcp.StackDriverClient metricType v2.MetricTargetType metadata *stackdriverMetadata logger logr.Logger @@ -32,12 +34,12 @@ type stackdriverMetadata struct { metricName string valueIfNull *float64 - gcpAuthorization *gcpAuthorizationMetadata + gcpAuthorization *gcp.AuthorizationMetadata aggregation *monitoringpb.Aggregation } // NewStackdriverScaler creates a new stackdriverScaler -func NewStackdriverScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewStackdriverScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -64,7 +66,7 @@ func NewStackdriverScaler(ctx context.Context, config *ScalerConfig) (Scaler, er }, nil } -func parseStackdriverMetadata(config *ScalerConfig, logger logr.Logger) (*stackdriverMetadata, error) { +func parseStackdriverMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*stackdriverMetadata, error) { meta := stackdriverMetadata{} meta.targetValue = defaultStackdriverTargetValue @@ -118,7 +120,7 @@ func parseStackdriverMetadata(config *ScalerConfig, logger logr.Logger) (*stackd meta.valueIfNull = &valueIfNull } - auth, err := getGCPAuthorization(config) + auth, err := gcp.GetGCPAuthorization(config) if err != nil { return nil, err } @@ -133,7 +135,7 @@ func parseStackdriverMetadata(config *ScalerConfig, logger logr.Logger) (*stackd return &meta, nil } -func parseAggregation(config *ScalerConfig, logger logr.Logger) (*monitoringpb.Aggregation, error) { +func parseAggregation(config *scalersconfig.ScalerConfig, logger logr.Logger) (*monitoringpb.Aggregation, error) { if period, ok := config.TriggerMetadata["alignmentPeriodSeconds"]; ok { if period == "" { return nil, nil @@ -149,19 +151,19 @@ func parseAggregation(config *ScalerConfig, logger logr.Logger) (*monitoringpb.A return nil, fmt.Errorf("error parsing alignmentPeriodSeconds: %w", err) } - return NewStackdriverAggregator(val, config.TriggerMetadata["alignmentAligner"], config.TriggerMetadata["alignmentReducer"]) + return gcp.NewStackdriverAggregator(val, config.TriggerMetadata["alignmentAligner"], config.TriggerMetadata["alignmentReducer"]) } return nil, nil } -func initializeStackdriverClient(ctx context.Context, gcpAuthorization *gcpAuthorizationMetadata, logger logr.Logger) (*StackDriverClient, error) { - var client *StackDriverClient +func initializeStackdriverClient(ctx context.Context, gcpAuthorization *gcp.AuthorizationMetadata, logger logr.Logger) (*gcp.StackDriverClient, error) { + var client *gcp.StackDriverClient var err error - if gcpAuthorization.podIdentityProviderEnabled { - client, err = NewStackDriverClientPodIdentity(ctx) + if gcpAuthorization.PodIdentityProviderEnabled { + client, err = gcp.NewStackDriverClientPodIdentity(ctx) } else { - client, err = NewStackDriverClient(ctx, gcpAuthorization.GoogleApplicationCredentials) + client, err = gcp.NewStackDriverClient(ctx, gcpAuthorization.GoogleApplicationCredentials) } if err != nil { @@ -173,7 +175,7 @@ func initializeStackdriverClient(ctx context.Context, gcpAuthorization *gcpAutho func (s *stackdriverScaler) Close(context.Context) error { if s.client != nil { - err := s.client.metricsClient.Close() + err := s.client.MetricsClient.Close() s.client = nil if err != nil { s.logger.Error(err, "error closing StackDriver client") diff --git a/pkg/scalers/gcp_stackdriver_scaler_test.go b/pkg/scalers/gcp_stackdriver_scaler_test.go index 80629ea21b2..bcf078749c3 100644 --- a/pkg/scalers/gcp_stackdriver_scaler_test.go +++ b/pkg/scalers/gcp_stackdriver_scaler_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testStackdriverResolvedEnv = map[string]string{ @@ -68,7 +70,7 @@ var gcpStackdriverMetricIdentifiers = []gcpStackdriverMetricIdentifier{ func TestStackdriverParseMetadata(t *testing.T) { for _, testData := range testStackdriverMetadata { - _, err := parseStackdriverMetadata(&ScalerConfig{AuthParams: testData.authParams, TriggerMetadata: testData.metadata, ResolvedEnv: testStackdriverResolvedEnv}, logr.Discard()) + _, err := parseStackdriverMetadata(&scalersconfig.ScalerConfig{AuthParams: testData.authParams, TriggerMetadata: testData.metadata, ResolvedEnv: testStackdriverResolvedEnv}, logr.Discard()) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -80,7 +82,7 @@ func TestStackdriverParseMetadata(t *testing.T) { func TestGcpStackdriverGetMetricSpecForScaling(t *testing.T) { for _, testData := range gcpStackdriverMetricIdentifiers { - meta, err := parseStackdriverMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testStackdriverResolvedEnv, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseStackdriverMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testStackdriverResolvedEnv, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/gcp_storage_scaler.go b/pkg/scalers/gcp_storage_scaler.go index 07848014b07..2eac27688ab 100644 --- a/pkg/scalers/gcp_storage_scaler.go +++ b/pkg/scalers/gcp_storage_scaler.go @@ -13,6 +13,8 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/gcp" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -33,7 +35,7 @@ type gcsScaler struct { type gcsMetadata struct { bucketName string - gcpAuthorization *gcpAuthorizationMetadata + gcpAuthorization *gcp.AuthorizationMetadata maxBucketItemsToScan int64 metricName string targetObjectCount int64 @@ -43,7 +45,7 @@ type gcsMetadata struct { } // NewGcsScaler creates a new gcsScaler -func NewGcsScaler(config *ScalerConfig) (Scaler, error) { +func NewGcsScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -61,7 +63,7 @@ func NewGcsScaler(config *ScalerConfig) (Scaler, error) { var client *storage.Client switch { - case meta.gcpAuthorization.podIdentityProviderEnabled: + case meta.gcpAuthorization.PodIdentityProviderEnabled: client, err = storage.NewClient(ctx) case meta.gcpAuthorization.GoogleApplicationCredentialsFile != "": client, err = storage.NewClient( @@ -91,7 +93,7 @@ func NewGcsScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseGcsMetadata(config *ScalerConfig, logger logr.Logger) (*gcsMetadata, error) { +func parseGcsMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*gcsMetadata, error) { meta := gcsMetadata{} meta.targetObjectCount = defaultTargetObjectCount meta.maxBucketItemsToScan = defaultMaxBucketItemsToScan @@ -145,7 +147,7 @@ func parseGcsMetadata(config *ScalerConfig, logger logr.Logger) (*gcsMetadata, e meta.blobPrefix = val } - auth, err := getGCPAuthorization(config) + auth, err := gcp.GetGCPAuthorization(config) if err != nil { return nil, err } diff --git a/pkg/scalers/gcp_storage_scaler_test.go b/pkg/scalers/gcp_storage_scaler_test.go index fe27f3ba25c..6318952e68f 100644 --- a/pkg/scalers/gcp_storage_scaler_test.go +++ b/pkg/scalers/gcp_storage_scaler_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testGcsResolvedEnv = map[string]string{ @@ -52,7 +54,7 @@ var gcpGcsMetricIdentifiers = []gcpGcsMetricIdentifier{ func TestGcsParseMetadata(t *testing.T) { for _, testData := range testGcsMetadata { - _, err := parseGcsMetadata(&ScalerConfig{AuthParams: testData.authParams, TriggerMetadata: testData.metadata, ResolvedEnv: testGcsResolvedEnv}, logr.Discard()) + _, err := parseGcsMetadata(&scalersconfig.ScalerConfig{AuthParams: testData.authParams, TriggerMetadata: testData.metadata, ResolvedEnv: testGcsResolvedEnv}, logr.Discard()) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -64,7 +66,7 @@ func TestGcsParseMetadata(t *testing.T) { func TestGcsGetMetricSpecForScaling(t *testing.T) { for _, testData := range gcpGcsMetricIdentifiers { - meta, err := parseGcsMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testGcsResolvedEnv, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseGcsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testGcsResolvedEnv, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/github_runner_scaler.go b/pkg/scalers/github_runner_scaler.go index bba7b388454..ef36292627f 100644 --- a/pkg/scalers/github_runner_scaler.go +++ b/pkg/scalers/github_runner_scaler.go @@ -15,6 +15,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -325,7 +326,7 @@ type Job struct { } // NewGitHubRunnerScaler creates a new GitHub Runner Scaler -func NewGitHubRunnerScaler(config *ScalerConfig) (Scaler, error) { +func NewGitHubRunnerScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { httpClient := kedautil.CreateHTTPClient(config.GlobalHTTPTimeout, false) metricType, err := GetMetricTargetType(config) @@ -366,7 +367,7 @@ func getValueFromMetaOrEnv(key string, metadata map[string]string, env map[strin } // getInt64ValueFromMetaOrEnv returns the value of the given key from the metadata or the environment variables -func getInt64ValueFromMetaOrEnv(key string, config *ScalerConfig) (int64, error) { +func getInt64ValueFromMetaOrEnv(key string, config *scalersconfig.ScalerConfig) (int64, error) { sInt, err := getValueFromMetaOrEnv(key, config.TriggerMetadata, config.ResolvedEnv) if err != nil { return -1, fmt.Errorf("error parsing %s: %w", key, err) @@ -379,7 +380,7 @@ func getInt64ValueFromMetaOrEnv(key string, config *ScalerConfig) (int64, error) return goodInt, nil } -func parseGitHubRunnerMetadata(config *ScalerConfig) (*githubRunnerMetadata, error) { +func parseGitHubRunnerMetadata(config *scalersconfig.ScalerConfig) (*githubRunnerMetadata, error) { meta := &githubRunnerMetadata{} meta.targetWorkflowQueueLength = defaultTargetWorkflowQueueLength @@ -437,7 +438,7 @@ func parseGitHubRunnerMetadata(config *ScalerConfig) (*githubRunnerMetadata, err return meta, nil } -func setupGitHubApp(config *ScalerConfig) (*int64, *int64, *string, error) { +func setupGitHubApp(config *scalersconfig.ScalerConfig) (*int64, *int64, *string, error) { var appID *int64 var instID *int64 var appKey *string diff --git a/pkg/scalers/github_runner_scaler_test.go b/pkg/scalers/github_runner_scaler_test.go index 2ab6f320795..2d03e81ecb1 100644 --- a/pkg/scalers/github_runner_scaler_test.go +++ b/pkg/scalers/github_runner_scaler_test.go @@ -8,6 +8,8 @@ import ( "strings" "testing" "time" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) const ghLoadCount = 2 // the size of the pretend pool completed of job requests @@ -111,9 +113,9 @@ func TestGitHubRunnerParseMetadata(t *testing.T) { t.Run(testData.testName, func(t *testing.T) { var err error if testData.hasEnvs { - _, err = parseGitHubRunnerMetadata(&ScalerConfig{ResolvedEnv: testGitHubRunnerResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testAuthParams}) + _, err = parseGitHubRunnerMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testGitHubRunnerResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testAuthParams}) } else { - _, err = parseGitHubRunnerMetadata(&ScalerConfig{ResolvedEnv: testGitHubRunnerTokenEnv, TriggerMetadata: testData.metadata, AuthParams: testAuthParams}) + _, err = parseGitHubRunnerMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testGitHubRunnerTokenEnv, TriggerMetadata: testData.metadata, AuthParams: testAuthParams}) } if testData.isError && err == nil { t.Fatal("expected error but got none") @@ -567,7 +569,7 @@ var githubRunnerMetricIdentifiers = []githubRunnerMetricIdentifier{ func TestGithubRunnerGetMetricSpecForScaling(t *testing.T) { for i, testData := range githubRunnerMetricIdentifiers { ctx := context.Background() - meta, err := parseGitHubRunnerMetadata(&ScalerConfig{ResolvedEnv: testGitHubRunnerResolvedEnv, TriggerMetadata: *testData.metadataTestData, AuthParams: testAuthParams, TriggerIndex: testData.triggerIndex}) + meta, err := parseGitHubRunnerMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testGitHubRunnerResolvedEnv, TriggerMetadata: *testData.metadataTestData, AuthParams: testAuthParams, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/graphite_scaler.go b/pkg/scalers/graphite_scaler.go index 3789cdf3912..62b564b31b4 100644 --- a/pkg/scalers/graphite_scaler.go +++ b/pkg/scalers/graphite_scaler.go @@ -13,6 +13,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -54,7 +55,7 @@ type grapQueryResult []struct { } // NewGraphiteScaler creates a new graphiteScaler -func NewGraphiteScaler(config *ScalerConfig) (Scaler, error) { +func NewGraphiteScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -75,7 +76,7 @@ func NewGraphiteScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseGraphiteMetadata(config *ScalerConfig) (*graphiteMetadata, error) { +func parseGraphiteMetadata(config *scalersconfig.ScalerConfig) (*graphiteMetadata, error) { meta := graphiteMetadata{} if val, ok := config.TriggerMetadata[graphiteServerAddress]; ok && val != "" { diff --git a/pkg/scalers/graphite_scaler_test.go b/pkg/scalers/graphite_scaler_test.go index 2f855ab6a32..99fab59270b 100644 --- a/pkg/scalers/graphite_scaler_test.go +++ b/pkg/scalers/graphite_scaler_test.go @@ -8,6 +8,8 @@ import ( "testing" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseGraphiteMetadataTestData struct { @@ -112,7 +114,7 @@ var testGrapQueryResults = []grapQueryResultTestData{ func TestGraphiteParseMetadata(t *testing.T) { for _, testData := range testGrapMetadata { - _, err := parseGraphiteMetadata(&ScalerConfig{TriggerMetadata: testData.metadata}) + _, err := parseGraphiteMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -125,7 +127,7 @@ func TestGraphiteParseMetadata(t *testing.T) { func TestGraphiteGetMetricSpecForScaling(t *testing.T) { for _, testData := range graphiteMetricIdentifiers { ctx := context.Background() - meta, err := parseGraphiteMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) + meta, err := parseGraphiteMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -143,7 +145,7 @@ func TestGraphiteGetMetricSpecForScaling(t *testing.T) { func TestGraphiteScalerAuthParams(t *testing.T) { for _, testData := range testGraphiteAuthMetadata { - meta, err := parseGraphiteMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + meta, err := parseGraphiteMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) diff --git a/pkg/scalers/huawei_cloudeye_scaler.go b/pkg/scalers/huawei_cloudeye_scaler.go index 18af51e120f..528806f5b44 100644 --- a/pkg/scalers/huawei_cloudeye_scaler.go +++ b/pkg/scalers/huawei_cloudeye_scaler.go @@ -14,6 +14,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -71,7 +72,7 @@ type huaweiAuthorizationMetadata struct { } // NewHuaweiCloudeyeScaler creates a new huaweiCloudeyeScaler -func NewHuaweiCloudeyeScaler(config *ScalerConfig) (Scaler, error) { +func NewHuaweiCloudeyeScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -91,7 +92,7 @@ func NewHuaweiCloudeyeScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseHuaweiCloudeyeMetadata(config *ScalerConfig, logger logr.Logger) (*huaweiCloudeyeMetadata, error) { +func parseHuaweiCloudeyeMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*huaweiCloudeyeMetadata, error) { meta := huaweiCloudeyeMetadata{} meta.metricCollectionTime = defaultCloudeyeMetricCollectionTime diff --git a/pkg/scalers/huawei_cloudeye_scaler_test.go b/pkg/scalers/huawei_cloudeye_scaler_test.go index 3359c3bf305..d9acf687bf0 100644 --- a/pkg/scalers/huawei_cloudeye_scaler_test.go +++ b/pkg/scalers/huawei_cloudeye_scaler_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var ( @@ -160,7 +162,7 @@ var huaweiCloudeyeMetricIdentifiers = []huaweiCloudeyeMetricIdentifier{ func TestHuaweiCloudeyeParseMetadata(t *testing.T) { for _, testData := range testHuaweiCloudeyeMetadata { - _, err := parseHuaweiCloudeyeMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}, logr.Discard()) + _, err := parseHuaweiCloudeyeMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}, logr.Discard()) if err != nil && !testData.isError { t.Errorf("%s: Expected success but got error %s", testData.comment, err) } @@ -172,7 +174,7 @@ func TestHuaweiCloudeyeParseMetadata(t *testing.T) { func TestHuaweiCloudeyeGetMetricSpecForScaling(t *testing.T) { for _, testData := range huaweiCloudeyeMetricIdentifiers { - meta, err := parseHuaweiCloudeyeMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseHuaweiCloudeyeMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/ibmmq_scaler.go b/pkg/scalers/ibmmq_scaler.go index 6be263250fc..ff33d4f8cf7 100644 --- a/pkg/scalers/ibmmq_scaler.go +++ b/pkg/scalers/ibmmq_scaler.go @@ -15,6 +15,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -61,7 +62,7 @@ type Parameters struct { } // NewIBMMQScaler creates a new IBM MQ scaler -func NewIBMMQScaler(config *ScalerConfig) (Scaler, error) { +func NewIBMMQScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -86,7 +87,7 @@ func (s *IBMMQScaler) Close(context.Context) error { } // parseIBMMQMetadata checks the existence of and validates the MQ connection data provided -func parseIBMMQMetadata(config *ScalerConfig) (*IBMMQMetadata, error) { +func parseIBMMQMetadata(config *scalersconfig.ScalerConfig) (*IBMMQMetadata, error) { meta := IBMMQMetadata{} if val, ok := config.TriggerMetadata["host"]; ok { diff --git a/pkg/scalers/ibmmq_scaler_test.go b/pkg/scalers/ibmmq_scaler_test.go index 7a766d4ef6b..72ac9a71534 100644 --- a/pkg/scalers/ibmmq_scaler_test.go +++ b/pkg/scalers/ibmmq_scaler_test.go @@ -5,6 +5,8 @@ import ( "fmt" "testing" "time" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) // Test host URLs for validation @@ -69,7 +71,7 @@ var testIBMMQMetadata = []parseIBMMQMetadataTestData{ // and verify that the password field is handled correctly. func TestIBMMQParseMetadata(t *testing.T) { for _, testData := range testIBMMQMetadata { - metadata, err := parseIBMMQMetadata(&ScalerConfig{ResolvedEnv: sampleIBMMQResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + metadata, err := parseIBMMQMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleIBMMQResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) fmt.Println(testData) @@ -93,7 +95,7 @@ var testDefaultQueueDepth = []parseIBMMQMetadataTestData{ // Test that DefaultQueueDepth is set when queueDepth is not provided func TestParseDefaultQueueDepth(t *testing.T) { for _, testData := range testDefaultQueueDepth { - metadata, err := parseIBMMQMetadata(&ScalerConfig{ResolvedEnv: sampleIBMMQResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + metadata, err := parseIBMMQMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleIBMMQResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) switch { case err != nil && !testData.isError: t.Error("Expected success but got error", err) @@ -108,7 +110,7 @@ func TestParseDefaultQueueDepth(t *testing.T) { // Create a scaler and check if metrics method is available func TestIBMMQGetMetricSpecForScaling(t *testing.T) { for _, testData := range IBMMQMetricIdentifiers { - metadata, err := parseIBMMQMetadata(&ScalerConfig{ResolvedEnv: sampleIBMMQResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}) + metadata, err := parseIBMMQMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleIBMMQResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}) httpTimeout := 100 * time.Millisecond if err != nil { diff --git a/pkg/scalers/influxdb_scaler.go b/pkg/scalers/influxdb_scaler.go index 04ad173e9f8..4f552999ed8 100644 --- a/pkg/scalers/influxdb_scaler.go +++ b/pkg/scalers/influxdb_scaler.go @@ -11,6 +11,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/util" ) @@ -33,7 +34,7 @@ type influxDBMetadata struct { } // NewInfluxDBScaler creates a new influx db scaler -func NewInfluxDBScaler(config *ScalerConfig) (Scaler, error) { +func NewInfluxDBScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -61,7 +62,7 @@ func NewInfluxDBScaler(config *ScalerConfig) (Scaler, error) { } // parseInfluxDBMetadata parses the metadata passed in from the ScaledObject config -func parseInfluxDBMetadata(config *ScalerConfig) (*influxDBMetadata, error) { +func parseInfluxDBMetadata(config *scalersconfig.ScalerConfig) (*influxDBMetadata, error) { var authToken string var organizationName string var query string diff --git a/pkg/scalers/influxdb_scaler_test.go b/pkg/scalers/influxdb_scaler_test.go index 73c88b66d03..d238a222a54 100644 --- a/pkg/scalers/influxdb_scaler_test.go +++ b/pkg/scalers/influxdb_scaler_test.go @@ -6,6 +6,8 @@ import ( "github.com/go-logr/logr" influxdb2 "github.com/influxdata/influxdb-client-go/v2" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testInfluxDBResolvedEnv = map[string]string{ @@ -58,7 +60,7 @@ var influxDBMetricIdentifiers = []influxDBMetricIdentifier{ func TestInfluxDBParseMetadata(t *testing.T) { testCaseNum := 1 for _, testData := range testInfluxDBMetadata { - _, err := parseInfluxDBMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testInfluxDBResolvedEnv, AuthParams: testData.authParams}) + _, err := parseInfluxDBMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testInfluxDBResolvedEnv, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Errorf("Expected success but got error for unit test # %v", testCaseNum) } @@ -71,7 +73,7 @@ func TestInfluxDBParseMetadata(t *testing.T) { func TestInfluxDBGetMetricSpecForScaling(t *testing.T) { for _, testData := range influxDBMetricIdentifiers { - meta, err := parseInfluxDBMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testInfluxDBResolvedEnv, TriggerIndex: testData.triggerIndex}) + meta, err := parseInfluxDBMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testInfluxDBResolvedEnv, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/kafka_scaler_oauth_token_provider.go b/pkg/scalers/kafka/kafka_scaler_oauth_token_provider.go similarity index 59% rename from pkg/scalers/kafka_scaler_oauth_token_provider.go rename to pkg/scalers/kafka/kafka_scaler_oauth_token_provider.go index c7ea00c50fd..084d8c9d15b 100644 --- a/pkg/scalers/kafka_scaler_oauth_token_provider.go +++ b/pkg/scalers/kafka/kafka_scaler_oauth_token_provider.go @@ -1,4 +1,20 @@ -package scalers +/* +Copyright 2024 The KEDA Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package kafka import ( "context" diff --git a/pkg/scalers/kafka_scram_client.go b/pkg/scalers/kafka/kafka_scram_client.go similarity index 64% rename from pkg/scalers/kafka_scram_client.go rename to pkg/scalers/kafka/kafka_scram_client.go index 36cd998738d..d2094c38beb 100644 --- a/pkg/scalers/kafka_scram_client.go +++ b/pkg/scalers/kafka/kafka_scram_client.go @@ -1,4 +1,20 @@ -package scalers +/* +Copyright 2024 The KEDA Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package kafka import ( "crypto/sha256" diff --git a/pkg/scalers/kafka_scaler.go b/pkg/scalers/kafka_scaler.go index 6d593b513fd..cae219bc533 100644 --- a/pkg/scalers/kafka_scaler.go +++ b/pkg/scalers/kafka_scaler.go @@ -33,6 +33,8 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/kafka" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -123,7 +125,7 @@ const ( ) // NewKafkaScaler creates a new kafkaScaler -func NewKafkaScaler(config *ScalerConfig) (Scaler, error) { +func NewKafkaScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -153,7 +155,7 @@ func NewKafkaScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseKafkaAuthParams(config *ScalerConfig, meta *kafkaMetadata) error { +func parseKafkaAuthParams(config *scalersconfig.ScalerConfig, meta *kafkaMetadata) error { meta.saslType = KafkaSASLTypeNone var saslAuthType string switch { @@ -224,7 +226,7 @@ func parseKafkaAuthParams(config *ScalerConfig, meta *kafkaMetadata) error { return nil } -func parseTLS(config *ScalerConfig, meta *kafkaMetadata) error { +func parseTLS(config *scalersconfig.ScalerConfig, meta *kafkaMetadata) error { certGiven := config.AuthParams["cert"] != "" keyGiven := config.AuthParams["key"] != "" if certGiven && !keyGiven { @@ -255,7 +257,7 @@ func parseTLS(config *ScalerConfig, meta *kafkaMetadata) error { return nil } -func parseKerberosParams(config *ScalerConfig, meta *kafkaMetadata, mode kafkaSaslType) error { +func parseKerberosParams(config *scalersconfig.ScalerConfig, meta *kafkaMetadata, mode kafkaSaslType) error { if config.AuthParams["username"] == "" { return errors.New("no username given") } @@ -293,7 +295,7 @@ func parseKerberosParams(config *ScalerConfig, meta *kafkaMetadata, mode kafkaSa return nil } -func parseSaslParams(config *ScalerConfig, meta *kafkaMetadata, mode kafkaSaslType) error { +func parseSaslParams(config *scalersconfig.ScalerConfig, meta *kafkaMetadata, mode kafkaSaslType) error { if config.AuthParams["username"] == "" { return errors.New("no username given") } @@ -355,7 +357,7 @@ func saveToFile(content string) (string, error) { return tempFilename, nil } -func parseKafkaMetadata(config *ScalerConfig, logger logr.Logger) (kafkaMetadata, error) { +func parseKafkaMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (kafkaMetadata, error) { meta := kafkaMetadata{} switch { case config.TriggerMetadata["bootstrapServersFromEnv"] != "": @@ -522,18 +524,18 @@ func getKafkaClients(metadata kafkaMetadata) (sarama.Client, sarama.ClusterAdmin } if metadata.saslType == KafkaSASLTypeSCRAMSHA256 { - config.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA256} } + config.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &kafka.XDGSCRAMClient{HashGeneratorFcn: kafka.SHA256} } config.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA256 } if metadata.saslType == KafkaSASLTypeSCRAMSHA512 { - config.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA512} } + config.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &kafka.XDGSCRAMClient{HashGeneratorFcn: kafka.SHA512} } config.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA512 } if metadata.saslType == KafkaSASLTypeOAuthbearer { config.Net.SASL.Mechanism = sarama.SASLTypeOAuth - config.Net.SASL.TokenProvider = OAuthBearerTokenProvider(metadata.username, metadata.password, metadata.oauthTokenEndpointURI, metadata.scopes, metadata.oauthExtensions) + config.Net.SASL.TokenProvider = kafka.OAuthBearerTokenProvider(metadata.username, metadata.password, metadata.oauthTokenEndpointURI, metadata.scopes, metadata.oauthExtensions) } if metadata.saslType == KafkaSASLTypeGSSAPI { diff --git a/pkg/scalers/kafka_scaler_test.go b/pkg/scalers/kafka_scaler_test.go index 82e949a9478..eb679212b7a 100644 --- a/pkg/scalers/kafka_scaler_test.go +++ b/pkg/scalers/kafka_scaler_test.go @@ -11,6 +11,8 @@ import ( "github.com/IBM/sarama" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseKafkaMetadataTestData struct { @@ -318,10 +320,10 @@ var kafkaMetricIdentifiers = []kafkaMetricIdentifier{ func TestGetBrokers(t *testing.T) { for _, testData := range parseKafkaMetadataTestDataset { - meta, err := parseKafkaMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validWithAuthParams}, logr.Discard()) + meta, err := parseKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validWithAuthParams}, logr.Discard()) getBrokerTestBase(t, meta, testData, err) - meta, err = parseKafkaMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validWithoutAuthParams}, logr.Discard()) + meta, err = parseKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validWithoutAuthParams}, logr.Discard()) getBrokerTestBase(t, meta, testData, err) } } @@ -372,7 +374,7 @@ func getBrokerTestBase(t *testing.T, meta kafkaMetadata, testData parseKafkaMeta func TestKafkaAuthParamsInTriggerAuthentication(t *testing.T) { for _, testData := range parseKafkaAuthParamsTestDataset { - meta, err := parseKafkaMetadata(&ScalerConfig{TriggerMetadata: validKafkaMetadata, AuthParams: testData.authParams}, logr.Discard()) + meta, err := parseKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: validKafkaMetadata, AuthParams: testData.authParams}, logr.Discard()) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -416,7 +418,7 @@ func TestKafkaAuthParamsInTriggerAuthentication(t *testing.T) { func TestKafkaAuthParamsInScaledObject(t *testing.T) { for id, testData := range parseAuthParamsTestDataset { - meta, err := parseKafkaMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}, logr.Discard()) + meta, err := parseKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}, logr.Discard()) if err != nil && !testData.isError { t.Errorf("Test case: %v. Expected success but got error %v", id, err) @@ -478,7 +480,7 @@ func testFileContents(testData parseKafkaAuthParamsTestData, meta kafkaMetadata, func TestKafkaOAuthbrearerAuthParams(t *testing.T) { for _, testData := range parseKafkaOAuthbrearerAuthParamsTestDataset { - meta, err := parseKafkaMetadata(&ScalerConfig{TriggerMetadata: validKafkaMetadata, AuthParams: testData.authParams}, logr.Discard()) + meta, err := parseKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: validKafkaMetadata, AuthParams: testData.authParams}, logr.Discard()) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -501,7 +503,7 @@ func TestKafkaOAuthbrearerAuthParams(t *testing.T) { func TestKafkaGetMetricSpecForScaling(t *testing.T) { for _, testData := range kafkaMetricIdentifiers { - meta, err := parseKafkaMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validWithAuthParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validWithAuthParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -529,7 +531,7 @@ func TestGetTopicPartitions(t *testing.T) { for _, tt := range testData { t.Run(tt.name, func(t *testing.T) { - meta, err := parseKafkaMetadata(&ScalerConfig{TriggerMetadata: tt.metadata, AuthParams: validWithAuthParams}, logr.Discard()) + meta, err := parseKafkaMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: tt.metadata, AuthParams: validWithAuthParams}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/kubernetes_workload_scaler.go b/pkg/scalers/kubernetes_workload_scaler.go index bb35b17ba56..2994e8daff2 100644 --- a/pkg/scalers/kubernetes_workload_scaler.go +++ b/pkg/scalers/kubernetes_workload_scaler.go @@ -12,6 +12,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -43,7 +44,7 @@ type kubernetesWorkloadMetadata struct { } // NewKubernetesWorkloadScaler creates a new kubernetesWorkloadScaler -func NewKubernetesWorkloadScaler(kubeClient client.Client, config *ScalerConfig) (Scaler, error) { +func NewKubernetesWorkloadScaler(kubeClient client.Client, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -62,7 +63,7 @@ func NewKubernetesWorkloadScaler(kubeClient client.Client, config *ScalerConfig) }, nil } -func parseWorkloadMetadata(config *ScalerConfig) (*kubernetesWorkloadMetadata, error) { +func parseWorkloadMetadata(config *scalersconfig.ScalerConfig) (*kubernetesWorkloadMetadata, error) { meta := &kubernetesWorkloadMetadata{} var err error meta.namespace = config.ScalableObjectNamespace diff --git a/pkg/scalers/kubernetes_workload_scaler_test.go b/pkg/scalers/kubernetes_workload_scaler_test.go index dc83fae3d09..ab7a7f360d6 100644 --- a/pkg/scalers/kubernetes_workload_scaler_test.go +++ b/pkg/scalers/kubernetes_workload_scaler_test.go @@ -10,6 +10,8 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client/fake" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type workloadMetadataTestData struct { @@ -36,7 +38,7 @@ var parseWorkloadMetadataTestDataset = []workloadMetadataTestData{ func TestParseWorkloadMetadata(t *testing.T) { for _, testData := range parseWorkloadMetadataTestDataset { - _, err := parseWorkloadMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ScalableObjectNamespace: testData.namespace}) + _, err := parseWorkloadMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ScalableObjectNamespace: testData.namespace}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -68,7 +70,7 @@ func TestWorkloadIsActive(t *testing.T) { for _, testData := range isActiveWorkloadTestDataset { s, _ := NewKubernetesWorkloadScaler( fake.NewClientBuilder().WithRuntimeObjects(createPodlist(testData.podCount)).Build(), - &ScalerConfig{ + &scalersconfig.ScalerConfig{ TriggerMetadata: testData.metadata, AuthParams: map[string]string{}, GlobalHTTPTimeout: 1000 * time.Millisecond, @@ -107,7 +109,7 @@ func TestWorkloadGetMetricSpecForScaling(t *testing.T) { for _, testData := range getMetricSpecForScalingTestDataset { s, _ := NewKubernetesWorkloadScaler( fake.NewClientBuilder().Build(), - &ScalerConfig{ + &scalersconfig.ScalerConfig{ TriggerMetadata: testData.metadata, AuthParams: map[string]string{}, GlobalHTTPTimeout: 1000 * time.Millisecond, @@ -170,7 +172,7 @@ func TestWorkloadPhase(t *testing.T) { list.Items = append(list.Items, *pod) s, err := NewKubernetesWorkloadScaler( fake.NewClientBuilder().WithRuntimeObjects(list).Build(), - &ScalerConfig{ + &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "podSelector": "app=testphases", "value": "1", diff --git a/pkg/scalers/liiklus/LiiklusService.pb.go b/pkg/scalers/liiklus/LiiklusService.pb.go index 71e3e8476d6..c5fac74bc95 100644 --- a/pkg/scalers/liiklus/LiiklusService.pb.go +++ b/pkg/scalers/liiklus/LiiklusService.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.24.4 +// protoc v4.23.2 // source: LiiklusService.proto package liiklus diff --git a/pkg/scalers/liiklus/LiiklusService_grpc.pb.go b/pkg/scalers/liiklus/LiiklusService_grpc.pb.go index 1910dd6b90a..51480c39dae 100644 --- a/pkg/scalers/liiklus/LiiklusService_grpc.pb.go +++ b/pkg/scalers/liiklus/LiiklusService_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.24.4 +// - protoc v4.23.2 // source: LiiklusService.proto package liiklus diff --git a/pkg/scalers/liiklus_scaler.go b/pkg/scalers/liiklus_scaler.go index 465c019a630..2587911209e 100644 --- a/pkg/scalers/liiklus_scaler.go +++ b/pkg/scalers/liiklus_scaler.go @@ -14,6 +14,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" liiklus_service "github.com/kedacore/keda/v2/pkg/scalers/liiklus" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -58,7 +59,7 @@ var ( ) // NewLiiklusScaler creates a new liiklusScaler scaler -func NewLiiklusScaler(config *ScalerConfig) (Scaler, error) { +func NewLiiklusScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -157,7 +158,7 @@ func (s *liiklusScaler) getLag(ctx context.Context) (uint64, map[uint32]uint64, return totalLag, lags, nil } -func parseLiiklusMetadata(config *ScalerConfig) (*liiklusMetadata, error) { +func parseLiiklusMetadata(config *scalersconfig.ScalerConfig) (*liiklusMetadata, error) { lagThreshold := defaultLiiklusLagThreshold activationLagThreshold := defaultLiiklusActivationLagThreshold diff --git a/pkg/scalers/liiklus_scaler_test.go b/pkg/scalers/liiklus_scaler_test.go index 38737ce9a81..2a31e6bc88e 100644 --- a/pkg/scalers/liiklus_scaler_test.go +++ b/pkg/scalers/liiklus_scaler_test.go @@ -11,6 +11,7 @@ import ( "github.com/kedacore/keda/v2/pkg/scalers/liiklus" mock_liiklus "github.com/kedacore/keda/v2/pkg/scalers/liiklus/mocks" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseLiiklusMetadataTestData struct { @@ -44,7 +45,7 @@ var liiklusMetricIdentifiers = []liiklusMetricIdentifier{ func TestLiiklusParseMetadata(t *testing.T) { for _, testData := range parseLiiklusMetadataTestDataset { - meta, err := parseLiiklusMetadata(&ScalerConfig{TriggerMetadata: testData.metadata}) + meta, err := parseLiiklusMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata}) if err != nil && testData.err == nil { t.Error("Expected success but got error", err) continue @@ -83,7 +84,7 @@ func TestLiiklusScalerActiveBehavior(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - lm, _ := parseLiiklusMetadata(&ScalerConfig{TriggerMetadata: map[string]string{"topic": "foo", "address": "using-mock", "group": "mygroup"}}) + lm, _ := parseLiiklusMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: map[string]string{"topic": "foo", "address": "using-mock", "group": "mygroup"}}) mockClient := mock_liiklus.NewMockLiiklusServiceClient(ctrl) scaler := &liiklusScaler{ metadata: lm, @@ -127,7 +128,7 @@ func TestLiiklusScalerGetMetricsBehavior(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - lm, _ := parseLiiklusMetadata(&ScalerConfig{TriggerMetadata: map[string]string{"topic": "foo", "address": "using-mock", "group": "mygroup"}}) + lm, _ := parseLiiklusMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: map[string]string{"topic": "foo", "address": "using-mock", "group": "mygroup"}}) mockClient := mock_liiklus.NewMockLiiklusServiceClient(ctrl) scaler := &liiklusScaler{ metadata: lm, @@ -171,7 +172,7 @@ func TestLiiklusScalerGetMetricsBehavior(t *testing.T) { func TestLiiklusGetMetricSpecForScaling(t *testing.T) { for _, testData := range liiklusMetricIdentifiers { - meta, err := parseLiiklusMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) + meta, err := parseLiiklusMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/loki_scaler.go b/pkg/scalers/loki_scaler.go index 6b3b9f64cc7..11a43e5384c 100644 --- a/pkg/scalers/loki_scaler.go +++ b/pkg/scalers/loki_scaler.go @@ -14,6 +14,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" "github.com/kedacore/keda/v2/pkg/scalers/authentication" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -64,7 +65,7 @@ type lokiQueryResult struct { } // NewLokiScaler returns a new lokiScaler -func NewLokiScaler(config *ScalerConfig) (Scaler, error) { +func NewLokiScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -87,7 +88,7 @@ func NewLokiScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseLokiMetadata(config *ScalerConfig) (meta *lokiMetadata, err error) { +func parseLokiMetadata(config *scalersconfig.ScalerConfig) (meta *lokiMetadata, err error) { meta = &lokiMetadata{} if val, ok := config.TriggerMetadata[lokiServerAddress]; ok && val != "" { @@ -135,8 +136,7 @@ func parseLokiMetadata(config *ScalerConfig) (meta *lokiMetadata, err error) { if val, ok := config.TriggerMetadata[lokiIgnoreNullValues]; ok && val != "" { ignoreNullValues, err := strconv.ParseBool(val) if err != nil { - return nil, fmt.Errorf("err incorrect value for ignoreNullValues given: %s, "+ - "please use true or false", val) + return nil, fmt.Errorf("err incorrect value for ignoreNullValues given: %s please use true or false", val) } meta.ignoreNullValues = ignoreNullValues } diff --git a/pkg/scalers/loki_scaler_test.go b/pkg/scalers/loki_scaler_test.go index 2c70bf532c8..06f95f46419 100644 --- a/pkg/scalers/loki_scaler_test.go +++ b/pkg/scalers/loki_scaler_test.go @@ -9,6 +9,8 @@ import ( "github.com/go-logr/logr" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseLokiMetadataTestData struct { @@ -59,7 +61,7 @@ var testLokiAuthMetadata = []lokiAuthMetadataTestData{ func TestLokiParseMetadata(t *testing.T) { for _, testData := range testLokiMetadata { - _, err := parseLokiMetadata(&ScalerConfig{TriggerMetadata: testData.metadata}) + _, err := parseLokiMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -71,7 +73,7 @@ func TestLokiParseMetadata(t *testing.T) { func TestLokiScalerAuthParams(t *testing.T) { for _, testData := range testLokiAuthMetadata { - meta, err := parseLokiMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + meta, err := parseLokiMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) diff --git a/pkg/scalers/metrics_api_scaler.go b/pkg/scalers/metrics_api_scaler.go index b8f5e3ab42b..d5e0820e3bc 100644 --- a/pkg/scalers/metrics_api_scaler.go +++ b/pkg/scalers/metrics_api_scaler.go @@ -17,6 +17,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" "github.com/kedacore/keda/v2/pkg/scalers/authentication" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -65,7 +66,7 @@ const ( ) // NewMetricsAPIScaler creates a new HTTP scaler -func NewMetricsAPIScaler(config *ScalerConfig) (Scaler, error) { +func NewMetricsAPIScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -94,7 +95,7 @@ func NewMetricsAPIScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseMetricsAPIMetadata(config *ScalerConfig) (*metricsAPIScalerMetadata, error) { +func parseMetricsAPIMetadata(config *scalersconfig.ScalerConfig) (*metricsAPIScalerMetadata, error) { meta := metricsAPIScalerMetadata{} meta.triggerIndex = config.TriggerIndex diff --git a/pkg/scalers/metrics_api_scaler_test.go b/pkg/scalers/metrics_api_scaler_test.go index 6bbbe7411ef..7728d7d2fe0 100644 --- a/pkg/scalers/metrics_api_scaler_test.go +++ b/pkg/scalers/metrics_api_scaler_test.go @@ -10,6 +10,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type metricsAPIMetadataTestData struct { @@ -77,7 +79,7 @@ var testMetricsAPIAuthMetadata = []metricAPIAuthMetadataTestData{ func TestParseMetricsAPIMetadata(t *testing.T) { for _, testData := range testMetricsAPIMetadata { - _, err := parseMetricsAPIMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: map[string]string{}}) + _, err := parseMetricsAPIMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: map[string]string{}}) if err != nil && !testData.raisesError { t.Error("Expected success but got error", err) } @@ -100,7 +102,7 @@ var metricsAPIMetricIdentifiers = []metricsAPIMetricIdentifier{ func TestMetricsAPIGetMetricSpecForScaling(t *testing.T) { for _, testData := range metricsAPIMetricIdentifiers { s, err := NewMetricsAPIScaler( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: map[string]string{}, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: map[string]string{}, @@ -162,7 +164,7 @@ func TestGetValueFromResponse(t *testing.T) { func TestMetricAPIScalerAuthParams(t *testing.T) { for _, testData := range testMetricsAPIAuthMetadata { - meta, err := parseMetricsAPIMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + meta, err := parseMetricsAPIMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -208,7 +210,7 @@ func TestBearerAuth(t *testing.T) { } s, err := NewMetricsAPIScaler( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: map[string]string{}, TriggerMetadata: metadata, AuthParams: authentication, diff --git a/pkg/scalers/mongo_scaler.go b/pkg/scalers/mongo_scaler.go index f79e6508815..8e80b723baf 100644 --- a/pkg/scalers/mongo_scaler.go +++ b/pkg/scalers/mongo_scaler.go @@ -17,6 +17,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -73,7 +74,7 @@ const ( ) // NewMongoDBScaler creates a new mongoDB scaler -func NewMongoDBScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewMongoDBScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -105,7 +106,7 @@ func NewMongoDBScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) }, nil } -func parseMongoDBMetadata(config *ScalerConfig) (*mongoDBMetadata, string, error) { +func parseMongoDBMetadata(config *scalersconfig.ScalerConfig) (*mongoDBMetadata, string, error) { var connStr string var err error // setting default metadata diff --git a/pkg/scalers/mongo_scaler_test.go b/pkg/scalers/mongo_scaler_test.go index 26509d673f8..4ccb02b30f8 100644 --- a/pkg/scalers/mongo_scaler_test.go +++ b/pkg/scalers/mongo_scaler_test.go @@ -7,6 +7,8 @@ import ( "github.com/go-logr/logr" "github.com/stretchr/testify/assert" "go.mongodb.org/mongo-driver/mongo" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testMongoDBResolvedEnv = map[string]string{ @@ -90,7 +92,7 @@ var mongoDBMetricIdentifiers = []mongoDBMetricIdentifier{ func TestParseMongoDBMetadata(t *testing.T) { for _, testData := range testMONGODBMetadata { - _, _, err := parseMongoDBMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, _, err := parseMongoDBMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.raisesError { t.Error("Expected success but got error:", err) } @@ -102,7 +104,7 @@ func TestParseMongoDBMetadata(t *testing.T) { func TestParseMongoDBConnectionString(t *testing.T) { for _, testData := range mongoDBConnectionStringTestDatas { - _, connStr, err := parseMongoDBMetadata(&ScalerConfig{ResolvedEnv: testData.metadataTestData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams}) + _, connStr, err := parseMongoDBMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.metadataTestData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams}) if err != nil { t.Error("Expected success but got error:", err) } @@ -112,7 +114,7 @@ func TestParseMongoDBConnectionString(t *testing.T) { func TestMongoDBGetMetricSpecForScaling(t *testing.T) { for _, testData := range mongoDBMetricIdentifiers { - meta, _, err := parseMongoDBMetadata(&ScalerConfig{ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) + meta, _, err := parseMongoDBMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.metadataTestData.resolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/mssql_scaler.go b/pkg/scalers/mssql_scaler.go index 53880043437..e0463c6a98c 100644 --- a/pkg/scalers/mssql_scaler.go +++ b/pkg/scalers/mssql_scaler.go @@ -14,6 +14,8 @@ import ( "github.com/go-logr/logr" v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var ( @@ -68,7 +70,7 @@ type mssqlMetadata struct { } // NewMSSQLScaler creates a new mssql scaler -func NewMSSQLScaler(config *ScalerConfig) (Scaler, error) { +func NewMSSQLScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -95,7 +97,7 @@ func NewMSSQLScaler(config *ScalerConfig) (Scaler, error) { } // parseMSSQLMetadata takes a ScalerConfig and returns a mssqlMetadata or an error if the config is invalid -func parseMSSQLMetadata(config *ScalerConfig) (*mssqlMetadata, error) { +func parseMSSQLMetadata(config *scalersconfig.ScalerConfig) (*mssqlMetadata, error) { meta := mssqlMetadata{} // Query diff --git a/pkg/scalers/mssql_scaler_test.go b/pkg/scalers/mssql_scaler_test.go index 67877259b7a..a48c9842cea 100644 --- a/pkg/scalers/mssql_scaler_test.go +++ b/pkg/scalers/mssql_scaler_test.go @@ -4,6 +4,8 @@ import ( "context" "errors" "testing" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type mssqlTestData struct { @@ -122,7 +124,7 @@ var mssqlMetricIdentifiers = []mssqlMetricIdentifier{ func TestMSSQLMetadataParsing(t *testing.T) { for _, testData := range testMssqlMetadata { - var config = ScalerConfig{ + var config = scalersconfig.ScalerConfig{ ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams, @@ -159,7 +161,7 @@ func TestMSSQLMetadataParsing(t *testing.T) { func TestMSSQLGetMetricSpecForScaling(t *testing.T) { for _, testData := range mssqlMetricIdentifiers { ctx := context.Background() - var config = ScalerConfig{ + var config = scalersconfig.ScalerConfig{ ResolvedEnv: testData.metadataTestData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, diff --git a/pkg/scalers/mysql_scaler.go b/pkg/scalers/mysql_scaler.go index 59a854164f4..976295d0268 100644 --- a/pkg/scalers/mysql_scaler.go +++ b/pkg/scalers/mysql_scaler.go @@ -13,6 +13,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -37,7 +38,7 @@ type mySQLMetadata struct { } // NewMySQLScaler creates a new MySQL scaler -func NewMySQLScaler(config *ScalerConfig) (Scaler, error) { +func NewMySQLScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -62,7 +63,7 @@ func NewMySQLScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseMySQLMetadata(config *ScalerConfig) (*mySQLMetadata, error) { +func parseMySQLMetadata(config *scalersconfig.ScalerConfig) (*mySQLMetadata, error) { meta := mySQLMetadata{} if val, ok := config.TriggerMetadata["query"]; ok { diff --git a/pkg/scalers/mysql_scaler_test.go b/pkg/scalers/mysql_scaler_test.go index 141e5124a1b..e2b514a4b2a 100644 --- a/pkg/scalers/mysql_scaler_test.go +++ b/pkg/scalers/mysql_scaler_test.go @@ -2,6 +2,8 @@ package scalers import ( "testing" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testMySQLResolvedEnv = map[string]string{ @@ -67,7 +69,7 @@ var mySQLMetricIdentifiers = []mySQLMetricIdentifier{ func TestParseMySQLMetadata(t *testing.T) { for _, testData := range testMySQLMetadata { - _, err := parseMySQLMetadata(&ScalerConfig{ResolvedEnv: testMySQLResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, err := parseMySQLMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testMySQLResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.raisesError { t.Error("Expected success but got error", err) } @@ -80,7 +82,7 @@ func TestParseMySQLMetadata(t *testing.T) { func TestMetadataToConnectionStrUseConnStr(t *testing.T) { // Use existing ConnStr testMeta := map[string]string{"query": "query", "queryValue": "12", "connectionStringFromEnv": "MYSQL_CONN_STR"} - meta, _ := parseMySQLMetadata(&ScalerConfig{ResolvedEnv: testMySQLResolvedEnv, TriggerMetadata: testMeta, AuthParams: map[string]string{}}) + meta, _ := parseMySQLMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testMySQLResolvedEnv, TriggerMetadata: testMeta, AuthParams: map[string]string{}}) connStr := metadataToConnectionStr(meta) if connStr != testMySQLResolvedEnv["MYSQL_CONN_STR"] { t.Error("Expected success") @@ -91,7 +93,7 @@ func TestMetadataToConnectionStrBuildNew(t *testing.T) { // Build new ConnStr expected := "test_username:pass@tcp(test_host:test_port)/test_dbname" testMeta := map[string]string{"query": "query", "queryValue": "12", "host": "test_host", "port": "test_port", "username": "test_username", "passwordFromEnv": "MYSQL_PASSWORD", "dbName": "test_dbname"} - meta, _ := parseMySQLMetadata(&ScalerConfig{ResolvedEnv: testMySQLResolvedEnv, TriggerMetadata: testMeta, AuthParams: map[string]string{}}) + meta, _ := parseMySQLMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testMySQLResolvedEnv, TriggerMetadata: testMeta, AuthParams: map[string]string{}}) connStr := metadataToConnectionStr(meta) if connStr != expected { t.Errorf("%s != %s", expected, connStr) @@ -100,7 +102,7 @@ func TestMetadataToConnectionStrBuildNew(t *testing.T) { func TestMySQLGetMetricSpecForScaling(t *testing.T) { for _, testData := range mySQLMetricIdentifiers { - meta, err := parseMySQLMetadata(&ScalerConfig{ResolvedEnv: testData.metadataTestData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: nil, TriggerIndex: testData.triggerIndex}) + meta, err := parseMySQLMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.metadataTestData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: nil, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/nats_jetstream_scaler.go b/pkg/scalers/nats_jetstream_scaler.go index 2c4d59d0e9e..52f8043b2bd 100644 --- a/pkg/scalers/nats_jetstream_scaler.go +++ b/pkg/scalers/nats_jetstream_scaler.go @@ -15,6 +15,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -112,7 +113,7 @@ type consumerDeliveryStatus struct { StreamSequence int64 `json:"stream_seq"` } -func NewNATSJetStreamScaler(config *ScalerConfig) (Scaler, error) { +func NewNATSJetStreamScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -132,7 +133,7 @@ func NewNATSJetStreamScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseNATSJetStreamMetadata(config *ScalerConfig) (natsJetStreamMetadata, error) { +func parseNATSJetStreamMetadata(config *scalersconfig.ScalerConfig) (natsJetStreamMetadata, error) { meta := natsJetStreamMetadata{} account, err := GetFromAuthOrMeta(config, "account") diff --git a/pkg/scalers/nats_jetstream_scaler_test.go b/pkg/scalers/nats_jetstream_scaler_test.go index c73029f106f..10312d3873c 100644 --- a/pkg/scalers/nats_jetstream_scaler_test.go +++ b/pkg/scalers/nats_jetstream_scaler_test.go @@ -12,6 +12,8 @@ import ( "time" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseNATSJetStreamMetadataTestData struct { @@ -76,7 +78,7 @@ var natsJetStreamMetricIdentifiers = []natsJetStreamMetricIdentifier{ func TestNATSJetStreamParseMetadata(t *testing.T) { for _, testData := range testNATSJetStreamMetadata { - _, err := parseNATSJetStreamMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, err := parseNATSJetStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } else if testData.isError && err == nil { @@ -88,7 +90,7 @@ func TestNATSJetStreamParseMetadata(t *testing.T) { func TestNATSJetStreamGetMetricSpecForScaling(t *testing.T) { for _, testData := range natsJetStreamMetricIdentifiers { ctx := context.Background() - meta, err := parseNATSJetStreamMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) + meta, err := parseNATSJetStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -235,7 +237,7 @@ func TestNATSJetStreamIsActive(t *testing.T) { client, srv := natsMockHTTPJetStreamServer(t, mockResponseJSON) ctx := context.Background() - meta, err := parseNATSJetStreamMetadata(&ScalerConfig{TriggerMetadata: mockResponse.metadata.metadataTestData.metadata, TriggerIndex: mockResponse.metadata.triggerIndex}) + meta, err := parseNATSJetStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: mockResponse.metadata.metadataTestData.metadata, TriggerIndex: mockResponse.metadata.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -244,7 +246,7 @@ func TestNATSJetStreamIsActive(t *testing.T) { stream: nil, metadata: meta, httpClient: client, - logger: InitializeLogger(&ScalerConfig{TriggerMetadata: mockResponse.metadata.metadataTestData.metadata, TriggerIndex: mockResponse.metadata.triggerIndex}, "nats_jetstream_scaler"), + logger: InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: mockResponse.metadata.metadataTestData.metadata, TriggerIndex: mockResponse.metadata.triggerIndex}, "nats_jetstream_scaler"), } _, isActive, err := mockJetStreamScaler.GetMetricsAndActivity(ctx, "metric_name") @@ -263,13 +265,13 @@ func TestNATSJetStreamIsActive(t *testing.T) { func TestNewNATSJetStreamScaler(t *testing.T) { // All Good - _, err := NewNATSJetStreamScaler(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) + _, err := NewNATSJetStreamScaler(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) if err != nil { t.Error("Expected success for New NATS JetStream Scaler but got error", err) } // Fail - Empty account - _, err = NewNATSJetStreamScaler(&ScalerConfig{TriggerMetadata: map[string]string{"natsServerMonitoringEndpoint": "localhost:8222", "account": ""}}) + _, err = NewNATSJetStreamScaler(&scalersconfig.ScalerConfig{TriggerMetadata: map[string]string{"natsServerMonitoringEndpoint": "localhost:8222", "account": ""}}) if err == nil { t.Error("Expected error for parsing monitoring leader URL but got success") } @@ -285,7 +287,7 @@ func TestNATSJetStreamGetMetrics(t *testing.T) { client, srv := natsMockHTTPJetStreamServer(t, mockResponseJSON) ctx := context.Background() - meta, err := parseNATSJetStreamMetadata(&ScalerConfig{TriggerMetadata: mockResponse.metadata.metadataTestData.metadata, TriggerIndex: mockResponse.metadata.triggerIndex}) + meta, err := parseNATSJetStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: mockResponse.metadata.metadataTestData.metadata, TriggerIndex: mockResponse.metadata.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -294,7 +296,7 @@ func TestNATSJetStreamGetMetrics(t *testing.T) { stream: nil, metadata: meta, httpClient: client, - logger: InitializeLogger(&ScalerConfig{TriggerMetadata: mockResponse.metadata.metadataTestData.metadata, TriggerIndex: mockResponse.metadata.triggerIndex}, "nats_jetstream_scaler"), + logger: InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: mockResponse.metadata.metadataTestData.metadata, TriggerIndex: mockResponse.metadata.triggerIndex}, "nats_jetstream_scaler"), } _, _, err = mockJetStreamScaler.GetMetricsAndActivity(ctx, "metric_name") @@ -372,7 +374,7 @@ func TestNATSJetStreamgetNATSJetstreamMonitoringData(t *testing.T) { }() ctx := context.Background() - meta, err := parseNATSJetStreamMetadata(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) + meta, err := parseNATSJetStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -381,7 +383,7 @@ func TestNATSJetStreamgetNATSJetstreamMonitoringData(t *testing.T) { stream: nil, metadata: meta, httpClient: client, - logger: InitializeLogger(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}, "nats_jetstream_scaler"), + logger: InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}, "nats_jetstream_scaler"), } err = mockJetStreamScaler.getNATSJetstreamMonitoringData(ctx, mockJetStreamScaler.metadata.monitoringURL) @@ -394,7 +396,7 @@ func TestNATSJetStreamGetNATSJetstreamNodeURL(t *testing.T) { client, invalidJSONServer := natsMockHTTPJetStreamServer(t, []byte(`{invalidJSON}`)) defer invalidJSONServer.Close() - meta, err := parseNATSJetStreamMetadata(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) + meta, err := parseNATSJetStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -403,7 +405,7 @@ func TestNATSJetStreamGetNATSJetstreamNodeURL(t *testing.T) { stream: nil, metadata: meta, httpClient: client, - logger: InitializeLogger(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}, "nats_jetstream_scaler"), + logger: InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}, "nats_jetstream_scaler"), } mockJetStreamScaler.metadata.monitoringURL = "234234:::::34234234;;;;really_bad_URL;;/" @@ -418,7 +420,7 @@ func TestNATSJetStreamGetNATSJetstreamServerURL(t *testing.T) { client, invalidJSONServer := natsMockHTTPJetStreamServer(t, []byte(`{invalidJSON}`)) defer invalidJSONServer.Close() - meta, err := parseNATSJetStreamMetadata(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) + meta, err := parseNATSJetStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -427,7 +429,7 @@ func TestNATSJetStreamGetNATSJetstreamServerURL(t *testing.T) { stream: nil, metadata: meta, httpClient: client, - logger: InitializeLogger(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}, "nats_jetstream_scaler"), + logger: InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}, "nats_jetstream_scaler"), } mockJetStreamScaler.metadata.monitoringURL = "234234:::::34234234;;;;really_bad_URL;;/" @@ -439,7 +441,7 @@ func TestNATSJetStreamGetNATSJetstreamServerURL(t *testing.T) { } func TestInvalidateNATSJetStreamCachedMonitoringData(t *testing.T) { - meta, err := parseNATSJetStreamMetadata(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) + meta, err := parseNATSJetStreamMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -448,14 +450,14 @@ func TestInvalidateNATSJetStreamCachedMonitoringData(t *testing.T) { stream: nil, metadata: meta, httpClient: http.DefaultClient, - logger: InitializeLogger(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}, "nats_jetstream_scaler"), + logger: InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}, "nats_jetstream_scaler"), } mockJetStreamScaler.invalidateNATSJetStreamCachedMonitoringData() } func TestNATSJetStreamClose(t *testing.T) { - mockJetStreamScaler, err := NewNATSJetStreamScaler(&ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) + mockJetStreamScaler, err := NewNATSJetStreamScaler(&scalersconfig.ScalerConfig{TriggerMetadata: testNATSJetStreamGoodMetadata, TriggerIndex: 0}) if err != nil { t.Error("Expected success for New NATS JetStream Scaler but got error", err) } diff --git a/pkg/scalers/newrelic_scaler.go b/pkg/scalers/newrelic_scaler.go index 7c820fd0f77..1d62ea911e6 100644 --- a/pkg/scalers/newrelic_scaler.go +++ b/pkg/scalers/newrelic_scaler.go @@ -12,6 +12,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -43,7 +44,7 @@ type newrelicMetadata struct { triggerIndex int } -func NewNewRelicScaler(config *ScalerConfig) (Scaler, error) { +func NewNewRelicScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -75,7 +76,7 @@ func NewNewRelicScaler(config *ScalerConfig) (Scaler, error) { logger: logger}, nil } -func parseNewRelicMetadata(config *ScalerConfig, logger logr.Logger) (*newrelicMetadata, error) { +func parseNewRelicMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*newrelicMetadata, error) { meta := newrelicMetadata{} var err error diff --git a/pkg/scalers/newrelic_scaler_test.go b/pkg/scalers/newrelic_scaler_test.go index 346c0101b4a..632449cbf95 100644 --- a/pkg/scalers/newrelic_scaler_test.go +++ b/pkg/scalers/newrelic_scaler_test.go @@ -6,6 +6,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseNewRelicMetadataTestData struct { @@ -60,7 +62,7 @@ var newrelicMetricIdentifiers = []newrelicMetricIdentifier{ func TestNewRelicParseMetadata(t *testing.T) { for _, testData := range testNewRelicMetadata { - _, err := parseNewRelicMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}, logr.Discard()) + _, err := parseNewRelicMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}, logr.Discard()) if err != nil && !testData.isError { fmt.Printf("X: %s", testData.metadata) t.Error("Expected success but got error", err) @@ -73,7 +75,7 @@ func TestNewRelicParseMetadata(t *testing.T) { } func TestNewRelicGetMetricSpecForScaling(t *testing.T) { for _, testData := range newrelicMetricIdentifiers { - meta, err := parseNewRelicMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseNewRelicMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/openstack_metrics_scaler.go b/pkg/scalers/openstack_metrics_scaler.go index 9dbe92e5fbc..da98d2fdabc 100644 --- a/pkg/scalers/openstack_metrics_scaler.go +++ b/pkg/scalers/openstack_metrics_scaler.go @@ -16,6 +16,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" "github.com/kedacore/keda/v2/pkg/scalers/openstack" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -59,7 +60,7 @@ type measureResult struct { /* end of declarations */ // NewOpenstackMetricScaler creates new openstack metrics scaler instance -func NewOpenstackMetricScaler(ctx context.Context, config *ScalerConfig) (Scaler, error) { +func NewOpenstackMetricScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (Scaler, error) { var keystoneAuth *openstack.KeystoneAuthRequest var metricsClient openstack.Client @@ -116,7 +117,7 @@ func NewOpenstackMetricScaler(ctx context.Context, config *ScalerConfig) (Scaler }, nil } -func parseOpenstackMetricMetadata(config *ScalerConfig, logger logr.Logger) (*openstackMetricMetadata, error) { +func parseOpenstackMetricMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (*openstackMetricMetadata, error) { meta := openstackMetricMetadata{} triggerMetadata := config.TriggerMetadata @@ -187,7 +188,7 @@ func parseOpenstackMetricMetadata(config *ScalerConfig, logger logr.Logger) (*op return &meta, nil } -func parseOpenstackMetricAuthenticationMetadata(config *ScalerConfig) (openstackMetricAuthenticationMetadata, error) { +func parseOpenstackMetricAuthenticationMetadata(config *scalersconfig.ScalerConfig) (openstackMetricAuthenticationMetadata, error) { authMeta := openstackMetricAuthenticationMetadata{} authParams := config.AuthParams diff --git a/pkg/scalers/openstack_metrics_scaler_test.go b/pkg/scalers/openstack_metrics_scaler_test.go index ddfd96feed0..e5695c5a377 100644 --- a/pkg/scalers/openstack_metrics_scaler_test.go +++ b/pkg/scalers/openstack_metrics_scaler_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/kedacore/keda/v2/pkg/scalers/openstack" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseOpenstackMetricMetadataTestData struct { @@ -107,13 +108,13 @@ func TestOpenstackMetricsGetMetricsForSpecScaling(t *testing.T) { for _, testData := range testCases { testData := testData - meta, err := parseOpenstackMetricMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}, logr.Discard()) + meta, err := parseOpenstackMetricMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}, logr.Discard()) if err != nil { t.Fatal("Could not parse metadata from openstack metrics scaler") } - _, err = parseOpenstackMetricAuthenticationMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}) + _, err = parseOpenstackMetricAuthenticationMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("could not parse openstack metric authentication metadata") @@ -145,7 +146,7 @@ func TestOpenstackMetricsGetMetricsForSpecScalingInvalidMetaData(t *testing.T) { for _, testData := range testCases { testData := testData t.Run(testData.name, func(pt *testing.T) { - _, err := parseOpenstackMetricMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}, logr.Discard()) + _, err := parseOpenstackMetricMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}, logr.Discard()) assert.NotNil(t, err) }) } @@ -164,7 +165,7 @@ func TestOpenstackMetricAuthenticationInvalidAuthMetadata(t *testing.T) { for _, testData := range testCases { testData := testData t.Run(testData.name, func(ptr *testing.T) { - _, err := parseOpenstackMetricAuthenticationMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}) + _, err := parseOpenstackMetricAuthenticationMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.triggerIndex}) assert.NotNil(t, err) }) } diff --git a/pkg/scalers/openstack_swift_scaler.go b/pkg/scalers/openstack_swift_scaler.go index 1e33d9d2d0f..66a02af2370 100644 --- a/pkg/scalers/openstack_swift_scaler.go +++ b/pkg/scalers/openstack_swift_scaler.go @@ -12,6 +12,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -56,7 +57,7 @@ type openstackSwiftScaler struct { } // NewOpenstackSwiftScaler creates a new OpenStack Swift scaler -func NewOpenstackSwiftScaler(config *ScalerConfig) (Scaler, error) { +func NewOpenstackSwiftScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { var swiftClient *gophercloud.ServiceClient metricType, err := GetMetricTargetType(config) @@ -124,7 +125,7 @@ func NewOpenstackSwiftScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseOpenstackSwiftMetadata(config *ScalerConfig) (*openstackSwiftMetadata, error) { +func parseOpenstackSwiftMetadata(config *scalersconfig.ScalerConfig) (*openstackSwiftMetadata, error) { meta := openstackSwiftMetadata{} if val, ok := config.TriggerMetadata["swiftURL"]; ok { @@ -200,7 +201,7 @@ func parseOpenstackSwiftMetadata(config *ScalerConfig) (*openstackSwiftMetadata, return &meta, nil } -func parseOpenstackSwiftAuthenticationMetadata(config *ScalerConfig) (*openstackSwiftAuthenticationMetadata, error) { +func parseOpenstackSwiftAuthenticationMetadata(config *scalersconfig.ScalerConfig) (*openstackSwiftAuthenticationMetadata, error) { authMeta := openstackSwiftAuthenticationMetadata{} if config.AuthParams["authURL"] != "" { diff --git a/pkg/scalers/openstack_swift_scaler_test.go b/pkg/scalers/openstack_swift_scaler_test.go index 9e230b3fec6..7bd4faf663f 100644 --- a/pkg/scalers/openstack_swift_scaler_test.go +++ b/pkg/scalers/openstack_swift_scaler_test.go @@ -7,6 +7,8 @@ import ( "github.com/go-logr/logr" "github.com/gophercloud/gophercloud" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseOpenstackSwiftMetadataTestData struct { @@ -103,11 +105,11 @@ func TestOpenstackSwiftGetMetricSpecForScaling(t *testing.T) { for _, testData := range testCases { testData := testData - meta, err := parseOpenstackSwiftMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex}) + meta, err := parseOpenstackSwiftMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } - _, err = parseOpenstackSwiftAuthenticationMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex}) + _, err = parseOpenstackSwiftAuthenticationMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex}) if err != nil { t.Fatal("Could not parse auth metadata:", err) } @@ -135,7 +137,7 @@ func TestParseOpenstackSwiftMetadataForInvalidCases(t *testing.T) { for _, testData := range testCases { testData := testData t.Run(testData.name, func(pt *testing.T) { - _, err := parseOpenstackSwiftMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex}) + _, err := parseOpenstackSwiftMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex}) assert.NotNil(t, err) }) } @@ -155,7 +157,7 @@ func TestParseOpenstackSwiftAuthenticationMetadataForInvalidCases(t *testing.T) for _, testData := range testCases { testData := testData t.Run(testData.name, func(pt *testing.T) { - _, err := parseOpenstackSwiftAuthenticationMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex}) + _, err := parseOpenstackSwiftAuthenticationMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authMetadataTestData.authMetadata, TriggerIndex: testData.scaledIndex}) assert.NotNil(t, err) }) } diff --git a/pkg/scalers/postgresql_scaler.go b/pkg/scalers/postgresql_scaler.go index 6f93aa77081..00f1edada2f 100644 --- a/pkg/scalers/postgresql_scaler.go +++ b/pkg/scalers/postgresql_scaler.go @@ -13,6 +13,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -32,7 +33,7 @@ type postgreSQLMetadata struct { } // NewPostgreSQLScaler creates a new postgreSQL scaler -func NewPostgreSQLScaler(config *ScalerConfig) (Scaler, error) { +func NewPostgreSQLScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -57,7 +58,7 @@ func NewPostgreSQLScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parsePostgreSQLMetadata(config *ScalerConfig) (*postgreSQLMetadata, error) { +func parsePostgreSQLMetadata(config *scalersconfig.ScalerConfig) (*postgreSQLMetadata, error) { meta := postgreSQLMetadata{} if val, ok := config.TriggerMetadata["query"]; ok { diff --git a/pkg/scalers/postgresql_scaler_test.go b/pkg/scalers/postgresql_scaler_test.go index c3ad071368a..02e9fe9d157 100644 --- a/pkg/scalers/postgresql_scaler_test.go +++ b/pkg/scalers/postgresql_scaler_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parsePostgreSQLMetadataTestData struct { @@ -43,7 +45,7 @@ var postgreSQLMetricIdentifiers = []postgreSQLMetricIdentifier{ func TestPosgresSQLGetMetricSpecForScaling(t *testing.T) { for _, testData := range postgreSQLMetricIdentifiers { - meta, err := parsePostgreSQLMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authParam, TriggerIndex: testData.scaleIndex}) + meta, err := parsePostgreSQLMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.authParam, TriggerIndex: testData.scaleIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -77,7 +79,7 @@ var testPostgreSQLConnectionstring = []postgreSQLConnectionStringTestData{ func TestPosgresSQLConnectionStringGeneration(t *testing.T) { for _, testData := range testPostgreSQLConnectionstring { - meta, err := parsePostgreSQLMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParam, TriggerIndex: 0}) + meta, err := parsePostgreSQLMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParam, TriggerIndex: 0}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -133,7 +135,7 @@ var testPostgresMetadata = []parsePostgresMetadataTestData{ func TestParsePosgresSQLMetadata(t *testing.T) { for _, testData := range testPostgresMetadata { - _, err := parsePostgreSQLMetadata(&ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, err := parsePostgreSQLMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testData.resolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.raisesError { t.Error("Expected success but got error", err) } diff --git a/pkg/scalers/predictkube_scaler.go b/pkg/scalers/predictkube_scaler.go index fdff81413cb..a8695e37a79 100644 --- a/pkg/scalers/predictkube_scaler.go +++ b/pkg/scalers/predictkube_scaler.go @@ -28,6 +28,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" "github.com/kedacore/keda/v2/pkg/scalers/authentication" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -136,7 +137,7 @@ func (s *PredictKubeScaler) setupClientConn() error { } // NewPredictKubeScaler creates a new PredictKube scaler -func NewPredictKubeScaler(ctx context.Context, config *ScalerConfig) (*PredictKubeScaler, error) { +func NewPredictKubeScaler(ctx context.Context, config *scalersconfig.ScalerConfig) (*PredictKubeScaler, error) { s := &PredictKubeScaler{} logger := InitializeLogger(config, "predictkube_scaler") @@ -343,7 +344,7 @@ func (s *PredictKubeScaler) parsePrometheusResult(result model.Value) (out []*co return out, nil } -func parsePredictKubeMetadata(config *ScalerConfig) (result *predictKubeMetadata, err error) { +func parsePredictKubeMetadata(config *scalersconfig.ScalerConfig) (result *predictKubeMetadata, err error) { validate := validator.New() meta := predictKubeMetadata{} diff --git a/pkg/scalers/predictkube_scaler_test.go b/pkg/scalers/predictkube_scaler_test.go index bf7c625d832..4872eb32522 100644 --- a/pkg/scalers/predictkube_scaler_test.go +++ b/pkg/scalers/predictkube_scaler_test.go @@ -15,6 +15,8 @@ import ( "github.com/stretchr/testify/assert" "google.golang.org/grpc" "k8s.io/apimachinery/pkg/api/resource" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type server struct { @@ -142,7 +144,7 @@ var testPredictKubeMetadata = []predictKubeMetadataTestData{ func TestPredictKubeParseMetadata(t *testing.T) { for _, testData := range testPredictKubeMetadata { - _, err := parsePredictKubeMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, err := parsePredictKubeMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -175,7 +177,7 @@ func TestPredictKubeGetMetricSpecForScaling(t *testing.T) { for _, testData := range predictKubeMetricIdentifiers { mockPredictKubeScaler, err := NewPredictKubeScaler( - context.Background(), &ScalerConfig{ + context.Background(), &scalersconfig.ScalerConfig{ TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex, @@ -209,7 +211,7 @@ func TestPredictKubeGetMetrics(t *testing.T) { for _, testData := range predictKubeMetricIdentifiers { mockPredictKubeScaler, err := NewPredictKubeScaler( - context.Background(), &ScalerConfig{ + context.Background(), &scalersconfig.ScalerConfig{ TriggerMetadata: testData.metadataTestData.metadata, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex, diff --git a/pkg/scalers/prometheus_scaler.go b/pkg/scalers/prometheus_scaler.go index f204167b3ff..3abd77c7d3d 100644 --- a/pkg/scalers/prometheus_scaler.go +++ b/pkg/scalers/prometheus_scaler.go @@ -19,6 +19,8 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/authentication" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/gcp" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -77,7 +79,7 @@ type promQueryResult struct { } // NewPrometheusScaler creates a new prometheusScaler -func NewPrometheusScaler(config *ScalerConfig) (Scaler, error) { +func NewPrometheusScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -119,8 +121,8 @@ func NewPrometheusScaler(config *ScalerConfig) (Scaler, error) { httpClient.Transport = azureTransport } - gcpTransport, err := getGCPOAuth2HTTPTransport(config, httpClient.Transport, gcpScopeMonitoringRead) - if err != nil && !errors.Is(err, errGoogleApplicationCrendentialsNotFound) { + gcpTransport, err := gcp.GetGCPOAuth2HTTPTransport(config, httpClient.Transport, gcp.GcpScopeMonitoringRead) + if err != nil && !errors.Is(err, gcp.ErrGoogleApplicationCrendentialsNotFound) { logger.V(1).Error(err, "failed to get GCP client HTTP transport (either using Google application credentials or workload identity)") return nil, err } @@ -138,7 +140,7 @@ func NewPrometheusScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parsePrometheusMetadata(config *ScalerConfig) (meta *prometheusMetadata, err error) { +func parsePrometheusMetadata(config *scalersconfig.ScalerConfig) (meta *prometheusMetadata, err error) { meta = &prometheusMetadata{} if val, ok := config.TriggerMetadata[promServerAddress]; ok && val != "" { @@ -208,8 +210,7 @@ func parsePrometheusMetadata(config *ScalerConfig) (meta *prometheusMetadata, er if val, ok := config.TriggerMetadata[ignoreNullValues]; ok && val != "" { ignoreNullValues, err := strconv.ParseBool(val) if err != nil { - return nil, fmt.Errorf("err incorrect value for ignoreNullValues given: %s, "+ - "please use true or false", val) + return nil, fmt.Errorf("err incorrect value for ignoreNullValues given: %s, please use true or false", val) } meta.ignoreNullValues = ignoreNullValues } @@ -234,7 +235,7 @@ func parsePrometheusMetadata(config *ScalerConfig) (meta *prometheusMetadata, er return meta, nil } -func parseAuthConfig(config *ScalerConfig, meta *prometheusMetadata) error { +func parseAuthConfig(config *scalersconfig.ScalerConfig, meta *prometheusMetadata) error { // parse auth configs from ScalerConfig auth, err := authentication.GetAuthConfigs(config.TriggerMetadata, config.AuthParams) if err != nil { diff --git a/pkg/scalers/prometheus_scaler_test.go b/pkg/scalers/prometheus_scaler_test.go index 57e8d448904..844920f6d12 100644 --- a/pkg/scalers/prometheus_scaler_test.go +++ b/pkg/scalers/prometheus_scaler_test.go @@ -18,6 +18,7 @@ import ( "golang.org/x/oauth2" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parsePrometheusMetadataTestData struct { @@ -120,7 +121,7 @@ var testPrometheusAuthMetadata = []prometheusAuthMetadataTestData{ func TestPrometheusParseMetadata(t *testing.T) { for _, testData := range testPromMetadata { - _, err := parsePrometheusMetadata(&ScalerConfig{TriggerMetadata: testData.metadata}) + _, err := parsePrometheusMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -132,7 +133,7 @@ func TestPrometheusParseMetadata(t *testing.T) { func TestPrometheusGetMetricSpecForScaling(t *testing.T) { for _, testData := range prometheusMetricIdentifiers { - meta, err := parsePrometheusMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) + meta, err := parsePrometheusMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -151,7 +152,7 @@ func TestPrometheusGetMetricSpecForScaling(t *testing.T) { func TestPrometheusScalerAuthParams(t *testing.T) { for _, testData := range testPrometheusAuthMetadata { - meta, err := parsePrometheusMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.podIdentityProvider}}) + meta, err := parsePrometheusMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams, PodIdentity: kedav1alpha1.AuthPodIdentity{Provider: testData.podIdentityProvider}}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -473,10 +474,10 @@ IisErx3ap2o99Zn+Yotv/TGZkS+lfMLdbcOBr8a57Q== } tests := map[string]struct { - config func(*testing.T, *ScalerConfig) *ScalerConfig + config func(*testing.T, *scalersconfig.ScalerConfig) *scalersconfig.ScalerConfig }{ "using GCP workload identity": { - config: func(t *testing.T, config *ScalerConfig) *ScalerConfig { + config: func(t *testing.T, config *scalersconfig.ScalerConfig) *scalersconfig.ScalerConfig { t.Setenv("GOOGLE_APPLICATION_CREDENTIALS", fakeGCPCredsPath) config.PodIdentity = kedav1alpha1.AuthPodIdentity{ Provider: kedav1alpha1.PodIdentityProviderGCP, @@ -486,7 +487,7 @@ IisErx3ap2o99Zn+Yotv/TGZkS+lfMLdbcOBr8a57Q== }, "with Google app credentials on auth params": { - config: func(t *testing.T, config *ScalerConfig) *ScalerConfig { + config: func(t *testing.T, config *scalersconfig.ScalerConfig) *scalersconfig.ScalerConfig { config.AuthParams = map[string]string{ "GoogleApplicationCredentials": string(fakeGCPCredsJSON), } @@ -495,7 +496,7 @@ IisErx3ap2o99Zn+Yotv/TGZkS+lfMLdbcOBr8a57Q== }, "with Google app credentials on envs": { - config: func(t *testing.T, config *ScalerConfig) *ScalerConfig { + config: func(t *testing.T, config *scalersconfig.ScalerConfig) *scalersconfig.ScalerConfig { config.TriggerMetadata["credentialsFromEnv"] = "GCP_APP_CREDENTIALS" config.ResolvedEnv = map[string]string{ "GCP_APP_CREDENTIALS": string(fakeGCPCredsJSON), @@ -505,7 +506,7 @@ IisErx3ap2o99Zn+Yotv/TGZkS+lfMLdbcOBr8a57Q== }, "with Google app credentials file on auth params": { - config: func(t *testing.T, config *ScalerConfig) *ScalerConfig { + config: func(t *testing.T, config *scalersconfig.ScalerConfig) *scalersconfig.ScalerConfig { config.TriggerMetadata["credentialsFromEnvFile"] = "GCP_APP_CREDENTIALS" config.ResolvedEnv = map[string]string{ "GCP_APP_CREDENTIALS": fakeGCPCredsPath, @@ -520,7 +521,7 @@ IisErx3ap2o99Zn+Yotv/TGZkS+lfMLdbcOBr8a57Q== server := newFakeServer(t) defer server.Close() - baseConfig := &ScalerConfig{ + baseConfig := &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "serverAddress": server.URL + "/v1/projects/my-fake-project/location/global/prometheus", "query": "sum(rate(http_requests_total{instance=\"my-instance\"}[5m]))", diff --git a/pkg/scalers/pulsar_scaler.go b/pkg/scalers/pulsar_scaler.go index 75cf1b96d4d..c9732083113 100644 --- a/pkg/scalers/pulsar_scaler.go +++ b/pkg/scalers/pulsar_scaler.go @@ -18,6 +18,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" "github.com/kedacore/keda/v2/pkg/scalers/authentication" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -96,7 +97,7 @@ type pulsarStats struct { } // NewPulsarScaler creates a new PulsarScaler -func NewPulsarScaler(config *ScalerConfig) (Scaler, error) { +func NewPulsarScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { logger := InitializeLogger(config, "pulsar_scaler") pulsarMetadata, err := parsePulsarMetadata(config, logger) if err != nil { @@ -132,7 +133,7 @@ func NewPulsarScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parsePulsarMetadata(config *ScalerConfig, logger logr.Logger) (pulsarMetadata, error) { +func parsePulsarMetadata(config *scalersconfig.ScalerConfig, logger logr.Logger) (pulsarMetadata, error) { meta := pulsarMetadata{} switch { case config.TriggerMetadata["adminURLFromEnv"] != "": diff --git a/pkg/scalers/pulsar_scaler_test.go b/pkg/scalers/pulsar_scaler_test.go index aa7e55190f9..5c7148cf5b6 100644 --- a/pkg/scalers/pulsar_scaler_test.go +++ b/pkg/scalers/pulsar_scaler_test.go @@ -9,6 +9,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parsePulsarMetadataTestData struct { @@ -119,8 +121,8 @@ var pulsarMetricIdentifiers = []pulsarMetricIdentifier{ func TestParsePulsarMetadata(t *testing.T) { for _, testData := range parsePulsarMetadataTestDataset { - logger := InitializeLogger(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validPulsarWithAuthParams}, "test_pulsar_scaler") - meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validPulsarWithAuthParams}, logger) + logger := InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validPulsarWithAuthParams}, "test_pulsar_scaler") + meta, err := parsePulsarMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: validPulsarWithAuthParams}, logger) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -178,7 +180,7 @@ func TestParsePulsarMetadata(t *testing.T) { authParams = validPulsarWithAuthParams } - meta, err = parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: authParams}, logger) + meta, err = parsePulsarMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: authParams}, logger) if err != nil && !testData.isError { t.Error("Expected success but got error", err) @@ -217,8 +219,8 @@ func compareScope(scopes []string, scopeStr string) bool { func TestPulsarAuthParams(t *testing.T) { for _, testData := range parsePulsarMetadataTestAuthTLSDataset { - logger := InitializeLogger(&ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, "test_pulsar_scaler") - meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, logger) + logger := InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, "test_pulsar_scaler") + meta, err := parsePulsarMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, logger) if err != nil && !testData.isError { t.Error("Expected success but got error", testData.authParams, err) @@ -277,8 +279,8 @@ func TestPulsarAuthParams(t *testing.T) { func TestPulsarOAuthParams(t *testing.T) { for _, testData := range parsePulsarMetadataTestAuthTLSDataset { - logger := InitializeLogger(&ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, "test_pulsar_scaler") - meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, logger) + logger := InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, "test_pulsar_scaler") + meta, err := parsePulsarMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.triggerMetadata, AuthParams: testData.authParams}, logger) if err != nil && !testData.isError { t.Error("Expected success but got error", testData.authParams, err) @@ -332,8 +334,8 @@ func TestPulsarOAuthParams(t *testing.T) { func TestPulsarGetMetricSpecForScaling(t *testing.T) { for _, testData := range pulsarMetricIdentifiers { - logger := InitializeLogger(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validWithAuthParams}, "test_pulsar_scaler") - meta, err := parsePulsarMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validWithAuthParams}, logger) + logger := InitializeLogger(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validWithAuthParams}, "test_pulsar_scaler") + meta, err := parsePulsarMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validWithAuthParams}, logger) if err != nil { if testData.metadataTestData.isError { continue @@ -352,7 +354,7 @@ func TestPulsarGetMetricSpecForScaling(t *testing.T) { func TestPulsarIsActive(t *testing.T) { for _, testData := range pulsarMetricIdentifiers { - mockPulsarScaler, err := NewPulsarScaler(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validPulsarWithoutAuthParams}) + mockPulsarScaler, err := NewPulsarScaler(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validPulsarWithoutAuthParams}) if err != nil { if testData.metadataTestData.isError { continue @@ -376,7 +378,7 @@ func TestPulsarIsActive(t *testing.T) { func TestPulsarIsActiveWithAuthParams(t *testing.T) { for _, testData := range pulsarMetricIdentifiers { - mockPulsarScaler, err := NewPulsarScaler(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validPulsarWithAuthParams}) + mockPulsarScaler, err := NewPulsarScaler(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validPulsarWithAuthParams}) if err != nil { if testData.metadataTestData.isError { continue @@ -400,7 +402,7 @@ func TestPulsarIsActiveWithAuthParams(t *testing.T) { func TestPulsarGetMetric(t *testing.T) { for _, testData := range pulsarMetricIdentifiers { - mockPulsarScaler, err := NewPulsarScaler(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validPulsarWithoutAuthParams}) + mockPulsarScaler, err := NewPulsarScaler(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, AuthParams: validPulsarWithoutAuthParams}) if err != nil { if testData.metadataTestData.isError { continue diff --git a/pkg/scalers/rabbitmq_scaler.go b/pkg/scalers/rabbitmq_scaler.go index 37854d2dce6..9681ff8f932 100644 --- a/pkg/scalers/rabbitmq_scaler.go +++ b/pkg/scalers/rabbitmq_scaler.go @@ -20,6 +20,7 @@ import ( "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers/azure" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -116,7 +117,7 @@ type publishDetail struct { } // NewRabbitMQScaler creates a new rabbitMQ scaler -func NewRabbitMQScaler(config *ScalerConfig) (Scaler, error) { +func NewRabbitMQScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { s := &rabbitMQScaler{} metricType, err := GetMetricTargetType(config) @@ -157,7 +158,7 @@ func NewRabbitMQScaler(config *ScalerConfig) (Scaler, error) { return s, nil } -func resolveProtocol(config *ScalerConfig, meta *rabbitMQMetadata) error { +func resolveProtocol(config *scalersconfig.ScalerConfig, meta *rabbitMQMetadata) error { meta.protocol = defaultProtocol if val, ok := config.AuthParams["protocol"]; ok { meta.protocol = val @@ -171,7 +172,7 @@ func resolveProtocol(config *ScalerConfig, meta *rabbitMQMetadata) error { return nil } -func resolveHostValue(config *ScalerConfig, meta *rabbitMQMetadata) error { +func resolveHostValue(config *scalersconfig.ScalerConfig, meta *rabbitMQMetadata) error { switch { case config.AuthParams["host"] != "": meta.host = config.AuthParams["host"] @@ -185,7 +186,7 @@ func resolveHostValue(config *ScalerConfig, meta *rabbitMQMetadata) error { return nil } -func resolveTimeout(config *ScalerConfig, meta *rabbitMQMetadata) error { +func resolveTimeout(config *scalersconfig.ScalerConfig, meta *rabbitMQMetadata) error { if val, ok := config.TriggerMetadata["timeout"]; ok { timeoutMS, err := strconv.Atoi(val) if err != nil { @@ -204,7 +205,7 @@ func resolveTimeout(config *ScalerConfig, meta *rabbitMQMetadata) error { return nil } -func resolveTLSAuthParams(config *ScalerConfig, meta *rabbitMQMetadata) error { +func resolveTLSAuthParams(config *scalersconfig.ScalerConfig, meta *rabbitMQMetadata) error { meta.enableTLS = false if val, ok := config.AuthParams["tls"]; ok { val = strings.TrimSpace(val) @@ -220,7 +221,7 @@ func resolveTLSAuthParams(config *ScalerConfig, meta *rabbitMQMetadata) error { return nil } -func parseRabbitMQMetadata(config *ScalerConfig) (*rabbitMQMetadata, error) { +func parseRabbitMQMetadata(config *scalersconfig.ScalerConfig) (*rabbitMQMetadata, error) { meta := rabbitMQMetadata{} // Resolve protocol type @@ -320,7 +321,7 @@ func parseRabbitMQMetadata(config *ScalerConfig) (*rabbitMQMetadata, error) { return &meta, nil } -func parseRabbitMQHttpProtocolMetadata(config *ScalerConfig, meta *rabbitMQMetadata) error { +func parseRabbitMQHttpProtocolMetadata(config *scalersconfig.ScalerConfig, meta *rabbitMQMetadata) error { // Resolve useRegex if val, ok := config.TriggerMetadata["useRegex"]; ok { useRegex, err := strconv.ParseBool(val) @@ -362,7 +363,7 @@ func parseRabbitMQHttpProtocolMetadata(config *ScalerConfig, meta *rabbitMQMetad return nil } -func parseTrigger(meta *rabbitMQMetadata, config *ScalerConfig) (*rabbitMQMetadata, error) { +func parseTrigger(meta *rabbitMQMetadata, config *scalersconfig.ScalerConfig) (*rabbitMQMetadata, error) { deprecatedQueueLengthValue, deprecatedQueueLengthPresent := config.TriggerMetadata[rabbitQueueLengthMetricName] mode, modePresent := config.TriggerMetadata[rabbitModeTriggerConfigName] value, valuePresent := config.TriggerMetadata[rabbitValueTriggerConfigName] diff --git a/pkg/scalers/rabbitmq_scaler_test.go b/pkg/scalers/rabbitmq_scaler_test.go index 1ba918dd47c..1d2ba1eacd2 100644 --- a/pkg/scalers/rabbitmq_scaler_test.go +++ b/pkg/scalers/rabbitmq_scaler_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -162,7 +163,7 @@ var rabbitMQMetricIdentifiers = []rabbitMQMetricIdentifier{ func TestRabbitMQParseMetadata(t *testing.T) { for idx, testData := range testRabbitMQMetadata { - meta, err := parseRabbitMQMetadata(&ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + meta, err := parseRabbitMQMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -183,7 +184,7 @@ func TestRabbitMQParseMetadata(t *testing.T) { func TestRabbitMQParseAuthParamData(t *testing.T) { for _, testData := range testRabbitMQAuthParamData { - metadata, err := parseRabbitMQMetadata(&ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams, PodIdentity: testData.podIdentity}) + metadata, err := parseRabbitMQMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams, PodIdentity: testData.podIdentity}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } @@ -225,7 +226,7 @@ var testDefaultQueueLength = []parseRabbitMQMetadataTestData{ func TestParseDefaultQueueLength(t *testing.T) { for _, testData := range testDefaultQueueLength { - metadata, err := parseRabbitMQMetadata(&ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + metadata, err := parseRabbitMQMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) switch { case err != nil && !testData.isError: t.Error("Expected success but got error", err) @@ -377,7 +378,7 @@ func TestGetQueueInfo(t *testing.T) { } s, err := NewRabbitMQScaler( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: resolvedEnv, TriggerMetadata: metadata, AuthParams: map[string]string{}, @@ -518,7 +519,7 @@ func TestGetQueueInfoWithRegex(t *testing.T) { } s, err := NewRabbitMQScaler( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: resolvedEnv, TriggerMetadata: metadata, AuthParams: map[string]string{}, @@ -602,7 +603,7 @@ func TestGetPageSizeWithRegex(t *testing.T) { } s, err := NewRabbitMQScaler( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: resolvedEnv, TriggerMetadata: metadata, AuthParams: map[string]string{}, @@ -629,7 +630,7 @@ func TestGetPageSizeWithRegex(t *testing.T) { func TestRabbitMQGetMetricSpecForScaling(t *testing.T) { for _, testData := range rabbitMQMetricIdentifiers { - meta, err := parseRabbitMQMetadata(&ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: nil, TriggerIndex: testData.index}) + meta, err := parseRabbitMQMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: testData.metadataTestData.metadata, AuthParams: nil, TriggerIndex: testData.index}) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -671,7 +672,7 @@ func TestRabbitMQAnonymizeRabbitMQError(t *testing.T) { "hostFromEnv": host, "protocol": "http", } - meta, err := parseRabbitMQMetadata(&ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: metadata, AuthParams: nil}) + meta, err := parseRabbitMQMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: sampleRabbitMqResolvedEnv, TriggerMetadata: metadata, AuthParams: nil}) if err != nil { t.Fatalf("Error parsing metadata (%s)", err) @@ -723,7 +724,7 @@ func TestRegexQueueMissingError(t *testing.T) { } s, err := NewRabbitMQScaler( - &ScalerConfig{ + &scalersconfig.ScalerConfig{ ResolvedEnv: resolvedEnv, TriggerMetadata: metadata, AuthParams: map[string]string{}, diff --git a/pkg/scalers/redis_scaler.go b/pkg/scalers/redis_scaler.go index 2420d21bccb..81c318facaa 100644 --- a/pkg/scalers/redis_scaler.go +++ b/pkg/scalers/redis_scaler.go @@ -13,6 +13,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/util" ) @@ -71,7 +72,7 @@ type redisMetadata struct { } // NewRedisScaler creates a new redisScaler -func NewRedisScaler(ctx context.Context, isClustered, isSentinel bool, config *ScalerConfig) (Scaler, error) { +func NewRedisScaler(ctx context.Context, isClustered, isSentinel bool, config *scalersconfig.ScalerConfig) (Scaler, error) { luaScript := ` local listName = KEYS[1] local listType = redis.call('type', listName).ok @@ -192,7 +193,7 @@ func createRedisScalerWithClient(client *redis.Client, meta *redisMetadata, scri } } -func parseTLSConfigIntoConnectionInfo(config *ScalerConfig, connInfo *redisConnectionInfo) error { +func parseTLSConfigIntoConnectionInfo(config *scalersconfig.ScalerConfig, connInfo *redisConnectionInfo) error { enableTLS := defaultEnableTLS if val, ok := config.TriggerMetadata["enableTLS"]; ok { tls, err := strconv.ParseBool(val) @@ -248,7 +249,7 @@ func parseTLSConfigIntoConnectionInfo(config *ScalerConfig, connInfo *redisConne return nil } -func parseRedisMetadata(config *ScalerConfig, parserFn redisAddressParser) (*redisMetadata, error) { +func parseRedisMetadata(config *scalersconfig.ScalerConfig, parserFn redisAddressParser) (*redisMetadata, error) { connInfo, err := parserFn(config.TriggerMetadata, config.ResolvedEnv, config.AuthParams) if err != nil { return nil, err diff --git a/pkg/scalers/redis_scaler_test.go b/pkg/scalers/redis_scaler_test.go index 20903e8506e..9ce7a062e70 100644 --- a/pkg/scalers/redis_scaler_test.go +++ b/pkg/scalers/redis_scaler_test.go @@ -7,6 +7,8 @@ import ( "github.com/go-logr/logr" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var testRedisResolvedEnv = map[string]string{ @@ -81,7 +83,7 @@ func TestRedisParseMetadata(t *testing.T) { testCaseNum := 0 for _, testData := range testRedisMetadata { testCaseNum++ - meta, err := parseRedisMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testRedisResolvedEnv, AuthParams: testData.authParams}, parseRedisAddress) + meta, err := parseRedisMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testRedisResolvedEnv, AuthParams: testData.authParams}, parseRedisAddress) if err != nil && !testData.isError { t.Errorf("Expected success but got error for unit test # %v", testCaseNum) } @@ -113,7 +115,7 @@ func TestRedisParseMetadata(t *testing.T) { func TestRedisGetMetricSpecForScaling(t *testing.T) { for _, testData := range redisMetricIdentifiers { - meta, err := parseRedisMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testRedisResolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, parseRedisAddress) + meta, err := parseRedisMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: testRedisResolvedEnv, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, parseRedisAddress) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -371,7 +373,7 @@ func TestParseRedisClusterMetadata(t *testing.T) { for _, testCase := range cases { c := testCase t.Run(c.name, func(t *testing.T) { - config := &ScalerConfig{ + config := &scalersconfig.ScalerConfig{ TriggerMetadata: c.metadata, ResolvedEnv: c.resolvedEnv, AuthParams: c.authParams, @@ -817,7 +819,7 @@ func TestParseRedisSentinelMetadata(t *testing.T) { for _, testCase := range cases { c := testCase t.Run(c.name, func(t *testing.T) { - config := &ScalerConfig{ + config := &scalersconfig.ScalerConfig{ TriggerMetadata: c.metadata, ResolvedEnv: c.resolvedEnv, AuthParams: c.authParams, diff --git a/pkg/scalers/redis_streams_scaler.go b/pkg/scalers/redis_streams_scaler.go index b4a03e00bde..fdb3f7bc085 100644 --- a/pkg/scalers/redis_streams_scaler.go +++ b/pkg/scalers/redis_streams_scaler.go @@ -12,6 +12,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -65,7 +66,7 @@ type redisStreamsMetadata struct { } // NewRedisStreamsScaler creates a new redisStreamsScaler -func NewRedisStreamsScaler(ctx context.Context, isClustered, isSentinel bool, config *ScalerConfig) (Scaler, error) { +func NewRedisStreamsScaler(ctx context.Context, isClustered, isSentinel bool, config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -256,7 +257,7 @@ var ( ErrRedisMissingStreamName = errors.New("missing redis stream name") ) -func parseRedisStreamsMetadata(config *ScalerConfig, parseFn redisAddressParser) (*redisStreamsMetadata, error) { +func parseRedisStreamsMetadata(config *scalersconfig.ScalerConfig, parseFn redisAddressParser) (*redisStreamsMetadata, error) { connInfo, err := parseFn(config.TriggerMetadata, config.ResolvedEnv, config.AuthParams) if err != nil { return nil, err diff --git a/pkg/scalers/redis_streams_scaler_test.go b/pkg/scalers/redis_streams_scaler_test.go index 9345b30364c..0accba44f0b 100644 --- a/pkg/scalers/redis_streams_scaler_test.go +++ b/pkg/scalers/redis_streams_scaler_test.go @@ -7,6 +7,8 @@ import ( "github.com/go-logr/logr" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) func TestParseRedisStreamsMetadata(t *testing.T) { @@ -47,7 +49,7 @@ func TestParseRedisStreamsMetadata(t *testing.T) { for _, tc := range testCasesPending { tc := tc t.Run(tc.name, func(te *testing.T) { - m, err := parseRedisStreamsMetadata(&ScalerConfig{TriggerMetadata: tc.metadata, ResolvedEnv: tc.resolvedEnv, AuthParams: tc.authParams}, parseRedisAddress) + m, err := parseRedisStreamsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: tc.metadata, ResolvedEnv: tc.resolvedEnv, AuthParams: tc.authParams}, parseRedisAddress) assert.Nil(t, err) assert.Equal(t, tc.metadata[streamNameMetadata], m.streamName) assert.Equal(t, tc.metadata[consumerGroupNameMetadata], m.consumerGroupName) @@ -97,7 +99,7 @@ func TestParseRedisStreamsMetadata(t *testing.T) { for _, tc := range testCasesLag { tc := tc t.Run(tc.name, func(te *testing.T) { - m, err := parseRedisStreamsMetadata(&ScalerConfig{TriggerMetadata: tc.metadata, ResolvedEnv: tc.resolvedEnv, AuthParams: tc.authParams}, parseRedisAddress) + m, err := parseRedisStreamsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: tc.metadata, ResolvedEnv: tc.resolvedEnv, AuthParams: tc.authParams}, parseRedisAddress) assert.Nil(t, err) assert.Equal(t, m.streamName, tc.metadata[streamNameMetadata]) assert.Equal(t, m.consumerGroupName, tc.metadata[consumerGroupNameMetadata]) @@ -158,7 +160,7 @@ func TestParseRedisStreamsMetadataForInvalidCases(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.name, func(te *testing.T) { - _, err := parseRedisStreamsMetadata(&ScalerConfig{TriggerMetadata: tc.metadata, ResolvedEnv: tc.resolvedEnv, AuthParams: map[string]string{}}, parseRedisAddress) + _, err := parseRedisStreamsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: tc.metadata, ResolvedEnv: tc.resolvedEnv, AuthParams: map[string]string{}}, parseRedisAddress) assert.NotNil(t, err) }) } @@ -189,7 +191,7 @@ func TestRedisStreamsGetMetricSpecForScaling(t *testing.T) { } for _, testData := range redisStreamMetricIdentifiers { - meta, err := parseRedisStreamsMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: map[string]string{"REDIS_SERVICE": "my-address"}, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, parseRedisAddress) + meta, err := parseRedisStreamsMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, ResolvedEnv: map[string]string{"REDIS_SERVICE": "my-address"}, AuthParams: testData.metadataTestData.authParams, TriggerIndex: testData.triggerIndex}, parseRedisAddress) if err != nil { t.Fatal("Could not parse metadata:", err) } @@ -819,7 +821,7 @@ func TestParseRedisClusterStreamsMetadata(t *testing.T) { for _, testCase := range cases { c := testCase t.Run(c.name, func(t *testing.T) { - config := &ScalerConfig{ + config := &scalersconfig.ScalerConfig{ TriggerMetadata: c.metadata, ResolvedEnv: c.resolvedEnv, AuthParams: c.authParams, @@ -1939,7 +1941,7 @@ func TestParseRedisSentinelStreamsMetadata(t *testing.T) { for _, testCase := range cases { c := testCase t.Run(c.name, func(t *testing.T) { - config := &ScalerConfig{ + config := &scalersconfig.ScalerConfig{ TriggerMetadata: c.metadata, ResolvedEnv: c.resolvedEnv, AuthParams: c.authParams, @@ -1995,7 +1997,7 @@ func TestActivityCount(t *testing.T) { wantErr: nil, } t.Run(c.name, func(t *testing.T) { - config := &ScalerConfig{ + config := &scalersconfig.ScalerConfig{ TriggerMetadata: c.metadata, ResolvedEnv: c.resolvedEnv, AuthParams: c.authParams, diff --git a/pkg/scalers/scaler.go b/pkg/scalers/scaler.go index cce7eccc8d8..e7454681cc1 100644 --- a/pkg/scalers/scaler.go +++ b/pkg/scalers/scaler.go @@ -22,7 +22,6 @@ import ( "fmt" "reflect" "strings" - "time" "github.com/go-logr/logr" metrics "github.com/rcrowley/go-metrics" @@ -33,7 +32,7 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" logf "sigs.k8s.io/controller-runtime/pkg/log" - kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) func init() { @@ -63,52 +62,6 @@ type PushScaler interface { Run(ctx context.Context, active chan<- bool) } -// ScalerConfig contains config fields common for all scalers -type ScalerConfig struct { - // ScalableObjectName specifies name of the ScaledObject/ScaledJob that owns this scaler - ScalableObjectName string - - // ScalableObjectNamespace specifies name of the ScaledObject/ScaledJob that owns this scaler - ScalableObjectNamespace string - - // ScalableObjectType specifies whether this Scaler is owned by ScaledObject or ScaledJob - ScalableObjectType string - - // The timeout to be used on all HTTP requests from the controller - GlobalHTTPTimeout time.Duration - - // Name of the trigger - TriggerName string - - // Marks whether we should query metrics only during the polling interval - // Any requests for metrics in between are read from the cache - TriggerUseCachedMetrics bool - - // TriggerMetadata - TriggerMetadata map[string]string - - // ResolvedEnv - ResolvedEnv map[string]string - - // AuthParams - AuthParams map[string]string - - // PodIdentity - PodIdentity kedav1alpha1.AuthPodIdentity - - // TriggerIndex - TriggerIndex int - - // TriggerUniqueKey for the scaler across KEDA. Useful to identify uniquely the scaler, eg: AWS credentials cache - TriggerUniqueKey string - - // MetricType - MetricType v2.MetricTargetType - - // When we use the scaler for composite scaler, we shouldn't require the value because it'll be ignored - AsMetricSource bool -} - var ( // ErrScalerUnsupportedUtilizationMetricType is returned when v2.UtilizationMetricType // is provided as the metric target type for scaler. @@ -119,7 +72,7 @@ var ( ) // GetFromAuthOrMeta helps to get a field from Auth or Meta sections -func GetFromAuthOrMeta(config *ScalerConfig, field string) (string, error) { +func GetFromAuthOrMeta(config *scalersconfig.ScalerConfig, field string) (string, error) { var result string var err error if config.AuthParams[field] != "" { @@ -153,12 +106,12 @@ func RemoveIndexFromMetricName(triggerIndex int, metricName string) (string, err return metricNameWithoutIndex, nil } -func InitializeLogger(config *ScalerConfig, scalerName string) logr.Logger { +func InitializeLogger(config *scalersconfig.ScalerConfig, scalerName string) logr.Logger { return logf.Log.WithName(scalerName).WithValues("type", config.ScalableObjectType, "namespace", config.ScalableObjectNamespace, "name", config.ScalableObjectName) } // GetMetricTargetType helps get the metric target type of the scaler -func GetMetricTargetType(config *ScalerConfig) (v2.MetricTargetType, error) { +func GetMetricTargetType(config *scalersconfig.ScalerConfig) (v2.MetricTargetType, error) { switch config.MetricType { case v2.UtilizationMetricType: return "", ErrScalerUnsupportedUtilizationMetricType @@ -216,7 +169,7 @@ func GenerateMetricInMili(metricName string, value float64) external_metrics.Ext } // getParameterFromConfigV2 returns the value of the parameter from the config -func getParameterFromConfigV2(config *ScalerConfig, parameter string, useMetadata bool, useAuthentication bool, useResolvedEnv bool, isOptional bool, defaultVal string, targetType reflect.Type) (interface{}, error) { +func getParameterFromConfigV2(config *scalersconfig.ScalerConfig, parameter string, useMetadata bool, useAuthentication bool, useResolvedEnv bool, isOptional bool, defaultVal string, targetType reflect.Type) (interface{}, error) { foundCount := 0 var foundVal string var convertedVal interface{} diff --git a/pkg/scalers/scaler_test.go b/pkg/scalers/scaler_test.go index 4cd2f7ef00b..2db21abd35e 100644 --- a/pkg/scalers/scaler_test.go +++ b/pkg/scalers/scaler_test.go @@ -7,36 +7,38 @@ import ( "github.com/stretchr/testify/assert" v2 "k8s.io/api/autoscaling/v2" "k8s.io/apimachinery/pkg/api/resource" + + scalersconfig "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) func TestGetMetricTargetType(t *testing.T) { cases := []struct { name string - config *ScalerConfig + config *scalersconfig.ScalerConfig wantmetricType v2.MetricTargetType wantErr error }{ { name: "utilization metric type", - config: &ScalerConfig{MetricType: v2.UtilizationMetricType}, + config: &scalersconfig.ScalerConfig{MetricType: v2.UtilizationMetricType}, wantmetricType: "", wantErr: ErrScalerUnsupportedUtilizationMetricType, }, { name: "average value metric type", - config: &ScalerConfig{MetricType: v2.AverageValueMetricType}, + config: &scalersconfig.ScalerConfig{MetricType: v2.AverageValueMetricType}, wantmetricType: v2.AverageValueMetricType, wantErr: nil, }, { name: "value metric type", - config: &ScalerConfig{MetricType: v2.ValueMetricType}, + config: &scalersconfig.ScalerConfig{MetricType: v2.ValueMetricType}, wantmetricType: v2.ValueMetricType, wantErr: nil, }, { name: "no metric type", - config: &ScalerConfig{}, + config: &scalersconfig.ScalerConfig{}, wantmetricType: v2.AverageValueMetricType, wantErr: nil, }, @@ -253,7 +255,7 @@ var getParameterFromConfigTestDataset = []getParameterFromConfigTestData{ func TestGetParameterFromConfigV2(t *testing.T) { for _, testData := range getParameterFromConfigTestDataset { val, err := getParameterFromConfigV2( - &ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams, ResolvedEnv: testData.resolvedEnv}, + &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams, ResolvedEnv: testData.resolvedEnv}, testData.parameter, testData.useMetadata, testData.useAuthentication, diff --git a/pkg/scalers/scalersconfig/scalersconfig.go b/pkg/scalers/scalersconfig/scalersconfig.go new file mode 100644 index 00000000000..67ed86cd7a0 --- /dev/null +++ b/pkg/scalers/scalersconfig/scalersconfig.go @@ -0,0 +1,71 @@ +/* +Copyright 2024 The KEDA Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package scalersconfig + +import ( + "time" + + v2 "k8s.io/api/autoscaling/v2" + + kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" +) + +// ScalerConfig contains config fields common for all scalers +type ScalerConfig struct { + // ScalableObjectName specifies name of the ScaledObject/ScaledJob that owns this scaler + ScalableObjectName string + + // ScalableObjectNamespace specifies name of the ScaledObject/ScaledJob that owns this scaler + ScalableObjectNamespace string + + // ScalableObjectType specifies whether this Scaler is owned by ScaledObject or ScaledJob + ScalableObjectType string + + // The timeout to be used on all HTTP requests from the controller + GlobalHTTPTimeout time.Duration + + // Name of the trigger + TriggerName string + + // Marks whether we should query metrics only during the polling interval + // Any requests for metrics in between are read from the cache + TriggerUseCachedMetrics bool + + // TriggerMetadata + TriggerMetadata map[string]string + + // ResolvedEnv + ResolvedEnv map[string]string + + // AuthParams + AuthParams map[string]string + + // PodIdentity + PodIdentity kedav1alpha1.AuthPodIdentity + + // TriggerIndex + TriggerIndex int + + // TriggerUniqueKey for the scaler across KEDA. Useful to identify uniquely the scaler, eg: AWS credentials cache + TriggerUniqueKey string + + // MetricType + MetricType v2.MetricTargetType + + // When we use the scaler for composite scaler, we shouldn't require the value because it'll be ignored + AsMetricSource bool +} diff --git a/pkg/scalers/selenium_grid_scaler.go b/pkg/scalers/selenium_grid_scaler.go index 508d857c424..486e40a678f 100644 --- a/pkg/scalers/selenium_grid_scaler.go +++ b/pkg/scalers/selenium_grid_scaler.go @@ -16,6 +16,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -74,7 +75,7 @@ const ( DefaultPlatformName string = "linux" ) -func NewSeleniumGridScaler(config *ScalerConfig) (Scaler, error) { +func NewSeleniumGridScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -98,7 +99,7 @@ func NewSeleniumGridScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseSeleniumGridScalerMetadata(config *ScalerConfig) (*seleniumGridScalerMetadata, error) { +func parseSeleniumGridScalerMetadata(config *scalersconfig.ScalerConfig) (*seleniumGridScalerMetadata, error) { meta := seleniumGridScalerMetadata{ targetValue: 1, } diff --git a/pkg/scalers/selenium_grid_scaler_test.go b/pkg/scalers/selenium_grid_scaler_test.go index 5d40b47da4a..4a2fb412d52 100644 --- a/pkg/scalers/selenium_grid_scaler_test.go +++ b/pkg/scalers/selenium_grid_scaler_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/go-logr/logr" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) func Test_getCountFromSeleniumResponse(t *testing.T) { @@ -516,7 +518,7 @@ func Test_getCountFromSeleniumResponse(t *testing.T) { func Test_parseSeleniumGridScalerMetadata(t *testing.T) { type args struct { - config *ScalerConfig + config *scalersconfig.ScalerConfig } tests := []struct { name string @@ -527,7 +529,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "invalid url string should throw error", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{}, }, }, @@ -536,7 +538,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "invalid browsername string should throw error", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "url": "", }, @@ -547,7 +549,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "valid url and browsername should return metadata", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "url": "http://selenium-hub:4444/graphql", "browserName": "chrome", @@ -567,7 +569,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "valid url, browsername, and sessionbrowsername should return metadata", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "url": "http://selenium-hub:4444/graphql", "browserName": "MicrosoftEdge", @@ -588,7 +590,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "valid url in AuthParams, browsername, and sessionbrowsername should return metadata", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ AuthParams: map[string]string{ "url": "http://user:password@selenium-hub:4444/graphql", }, @@ -611,7 +613,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "valid url and browsername should return metadata", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "url": "http://selenium-hub:4444/graphql", "browserName": "chrome", @@ -634,7 +636,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "valid url, browsername, unsafeSsl and activationThreshold should return metadata", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "url": "http://selenium-hub:4444/graphql", "browserName": "chrome", @@ -659,7 +661,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "valid url, browsername and unsafeSsl but invalid activationThreshold should throw an error", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "url": "http://selenium-hub:4444/graphql", "browserName": "chrome", @@ -674,7 +676,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "valid url, browsername, unsafeSsl and activationThreshold with default platformName should return metadata", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "url": "http://selenium-hub:4444/graphql", "browserName": "chrome", @@ -699,7 +701,7 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { { name: "valid url, browsername, unsafeSsl, activationThreshold and platformName should return metadata", args: args{ - config: &ScalerConfig{ + config: &scalersconfig.ScalerConfig{ TriggerMetadata: map[string]string{ "url": "http://selenium-hub:4444/graphql", "browserName": "chrome", diff --git a/pkg/scalers/solace_scaler.go b/pkg/scalers/solace_scaler.go index 30c2c4744fb..ed958afc93a 100644 --- a/pkg/scalers/solace_scaler.go +++ b/pkg/scalers/solace_scaler.go @@ -13,6 +13,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -135,7 +136,7 @@ type solaceSEMPMetadata struct { } // NewSolaceScaler is the constructor for SolaceScaler -func NewSolaceScaler(config *ScalerConfig) (Scaler, error) { +func NewSolaceScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { // Create HTTP Client httpClient := kedautil.CreateHTTPClient(config.GlobalHTTPTimeout, false) @@ -162,7 +163,7 @@ func NewSolaceScaler(config *ScalerConfig) (Scaler, error) { } // Called by constructor -func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { +func parseSolaceMetadata(config *scalersconfig.ScalerConfig) (*SolaceMetadata, error) { meta := SolaceMetadata{} // GET THE SEMP API ENDPOINT if val, ok := config.TriggerMetadata[solaceMetaSempBaseURL]; ok && val != "" { @@ -267,7 +268,7 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) { return &meta, nil } -func getSolaceSempCredentials(config *ScalerConfig) (u string, p string, err error) { +func getSolaceSempCredentials(config *scalersconfig.ScalerConfig) (u string, p string, err error) { // GET CREDENTIALS // The username must be a valid broker ADMIN user identifier with read access to SEMP for the broker, VPN, and relevant objects // The scaler will attempt to acquire username and then password independently. For each: diff --git a/pkg/scalers/solace_scaler_test.go b/pkg/scalers/solace_scaler_test.go index c9dfbbf7013..fcd9442626b 100644 --- a/pkg/scalers/solace_scaler_test.go +++ b/pkg/scalers/solace_scaler_test.go @@ -9,6 +9,8 @@ import ( "testing" v2 "k8s.io/api/autoscaling/v2" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type testSolaceMetadata struct { @@ -532,7 +534,7 @@ var testSolaceExpectedMetricNames = map[string]string{ func TestSolaceParseSolaceMetadata(t *testing.T) { for _, testData := range testParseSolaceMetadata { fmt.Print(testData.testID) - meta, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil, TriggerIndex: testData.triggerIndex}) + meta, err := parseSolaceMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil, TriggerIndex: testData.triggerIndex}) switch { case err != nil && !testData.isError: t.Error("expected success but got error: ", err) @@ -550,7 +552,7 @@ func TestSolaceParseSolaceMetadata(t *testing.T) { } for _, testData := range testSolaceEnvCreds { fmt.Print(testData.testID) - _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: nil, TriggerIndex: testData.triggerIndex}) + _, err := parseSolaceMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: nil, TriggerIndex: testData.triggerIndex}) switch { case err != nil && !testData.isError: t.Error("expected success but got error: ", err) @@ -564,7 +566,7 @@ func TestSolaceParseSolaceMetadata(t *testing.T) { } for _, testData := range testSolaceK8sSecretCreds { fmt.Print(testData.testID) - _, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID, TriggerIndex: testData.triggerIndex}) + _, err := parseSolaceMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID, TriggerIndex: testData.triggerIndex}) switch { case err != nil && !testData.isError: t.Error("expected success but got error: ", err) @@ -584,7 +586,7 @@ func TestSolaceGetMetricSpec(t *testing.T) { fmt.Print(testData.testID) var err error var solaceMeta *SolaceMetadata - solaceMeta, err = parseSolaceMetadata(&ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID, TriggerIndex: testData.triggerIndex}) + solaceMeta, err = parseSolaceMetadata(&scalersconfig.ScalerConfig{ResolvedEnv: testDataSolaceResolvedEnvVALID, TriggerMetadata: testData.metadata, AuthParams: testDataSolaceAuthParamsVALID, TriggerIndex: testData.triggerIndex}) if err != nil { fmt.Printf("\n Failed to parse metadata: %v", err) } else { diff --git a/pkg/scalers/solr_scaler.go b/pkg/scalers/solr_scaler.go index 83698056c96..723e9f01179 100644 --- a/pkg/scalers/solr_scaler.go +++ b/pkg/scalers/solr_scaler.go @@ -12,6 +12,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -42,7 +43,7 @@ type solrResponse struct { } // NewSolrScaler creates a new solr Scaler -func NewSolrScaler(config *ScalerConfig) (Scaler, error) { +func NewSolrScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -65,7 +66,7 @@ func NewSolrScaler(config *ScalerConfig) (Scaler, error) { } // parseSolrMetadata parses the metadata and returns a solrMetadata or an error if the ScalerConfig is invalid. -func parseSolrMetadata(config *ScalerConfig) (*solrMetadata, error) { +func parseSolrMetadata(config *scalersconfig.ScalerConfig) (*solrMetadata, error) { meta := solrMetadata{} if val, ok := config.TriggerMetadata["host"]; ok { diff --git a/pkg/scalers/solr_scaler_test.go b/pkg/scalers/solr_scaler_test.go index 0ebfb012123..44441299787 100644 --- a/pkg/scalers/solr_scaler_test.go +++ b/pkg/scalers/solr_scaler_test.go @@ -4,6 +4,8 @@ import ( "context" "net/http" "testing" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseSolrMetadataTestData struct { @@ -45,7 +47,7 @@ var solrMetricIdentifiers = []solrMetricIdentifier{ func TestSolrParseMetadata(t *testing.T) { testCaseNum := 1 for _, testData := range testSolrMetadata { - _, err := parseSolrMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, err := parseSolrMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Errorf("Expected success but got error for unit test # %v", testCaseNum) } @@ -59,7 +61,7 @@ func TestSolrParseMetadata(t *testing.T) { func TestSolrGetMetricSpecForScaling(t *testing.T) { for _, testData := range solrMetricIdentifiers { ctx := context.Background() - meta, err := parseSolrMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex, AuthParams: testData.metadataTestData.authParams}) + meta, err := parseSolrMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex, AuthParams: testData.metadataTestData.authParams}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scalers/stan_scaler.go b/pkg/scalers/stan_scaler.go index 23945d63e14..c9bc49756c1 100644 --- a/pkg/scalers/stan_scaler.go +++ b/pkg/scalers/stan_scaler.go @@ -12,6 +12,7 @@ import ( v2 "k8s.io/api/autoscaling/v2" "k8s.io/metrics/pkg/apis/external_metrics" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" kedautil "github.com/kedacore/keda/v2/pkg/util" ) @@ -62,7 +63,7 @@ const ( ) // NewStanScaler creates a new stanScaler -func NewStanScaler(config *ScalerConfig) (Scaler, error) { +func NewStanScaler(config *scalersconfig.ScalerConfig) (Scaler, error) { metricType, err := GetMetricTargetType(config) if err != nil { return nil, fmt.Errorf("error getting scaler metric type: %w", err) @@ -82,7 +83,7 @@ func NewStanScaler(config *ScalerConfig) (Scaler, error) { }, nil } -func parseStanMetadata(config *ScalerConfig) (stanMetadata, error) { +func parseStanMetadata(config *scalersconfig.ScalerConfig) (stanMetadata, error) { meta := stanMetadata{} if config.TriggerMetadata["queueGroup"] == "" { diff --git a/pkg/scalers/stan_scaler_test.go b/pkg/scalers/stan_scaler_test.go index 1bf12001885..6825b4c778a 100644 --- a/pkg/scalers/stan_scaler_test.go +++ b/pkg/scalers/stan_scaler_test.go @@ -7,6 +7,8 @@ import ( "testing" "github.com/stretchr/testify/assert" + + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) type parseStanMetadataTestData struct { @@ -49,7 +51,7 @@ var stanMetricIdentifiers = []stanMetricIdentifier{ func TestStanParseMetadata(t *testing.T) { for _, testData := range testStanMetadata { - _, err := parseStanMetadata(&ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) + _, err := parseStanMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, AuthParams: testData.authParams}) if err != nil && !testData.isError { t.Error("Expected success but got error", err) } else if testData.isError && err == nil { @@ -61,7 +63,7 @@ func TestStanParseMetadata(t *testing.T) { func TestStanGetMetricSpecForScaling(t *testing.T) { for _, testData := range stanMetricIdentifiers { ctx := context.Background() - meta, err := parseStanMetadata(&ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) + meta, err := parseStanMetadata(&scalersconfig.ScalerConfig{TriggerMetadata: testData.metadataTestData.metadata, TriggerIndex: testData.triggerIndex}) if err != nil { t.Fatal("Could not parse metadata:", err) } diff --git a/pkg/scaling/cache/scalers_cache.go b/pkg/scaling/cache/scalers_cache.go index b7315cf1644..49042f86f0d 100644 --- a/pkg/scaling/cache/scalers_cache.go +++ b/pkg/scaling/cache/scalers_cache.go @@ -29,6 +29,7 @@ import ( kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/kedacore/keda/v2/pkg/scalers" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" ) var log = logf.Log.WithName("scalers_cache") @@ -43,14 +44,14 @@ type ScalersCache struct { type ScalerBuilder struct { Scaler scalers.Scaler - ScalerConfig scalers.ScalerConfig - Factory func() (scalers.Scaler, *scalers.ScalerConfig, error) + ScalerConfig scalersconfig.ScalerConfig + Factory func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) } // GetScalers returns array of scalers and scaler config stored in the cache -func (c *ScalersCache) GetScalers() ([]scalers.Scaler, []scalers.ScalerConfig) { +func (c *ScalersCache) GetScalers() ([]scalers.Scaler, []scalersconfig.ScalerConfig) { scalersList := make([]scalers.Scaler, 0, len(c.Scalers)) - configsList := make([]scalers.ScalerConfig, 0, len(c.Scalers)) + configsList := make([]scalersconfig.ScalerConfig, 0, len(c.Scalers)) for _, s := range c.Scalers { scalersList = append(scalersList, s.Scaler) configsList = append(configsList, s.ScalerConfig) diff --git a/pkg/scaling/scale_handler.go b/pkg/scaling/scale_handler.go index 3c28fa830a9..fcc060dc97c 100644 --- a/pkg/scaling/scale_handler.go +++ b/pkg/scaling/scale_handler.go @@ -42,6 +42,7 @@ import ( "github.com/kedacore/keda/v2/pkg/fallback" "github.com/kedacore/keda/v2/pkg/metricscollector" "github.com/kedacore/keda/v2/pkg/scalers" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/scaling/cache" "github.com/kedacore/keda/v2/pkg/scaling/cache/metricscache" "github.com/kedacore/keda/v2/pkg/scaling/executor" @@ -498,7 +499,7 @@ func (h *scaleHandler) GetScaledObjectMetrics(ctx context.Context, scaledObjectN // if compositeScaler is used, override with current metric, otherwise do nothing metricName := spec.External.Metric.Name wg.Add(1) - go func(results chan metricResult, wg *sync.WaitGroup, metricName string, triggerIndex int, scalerConfig scalers.ScalerConfig, spec v2.MetricSpec) { + go func(results chan metricResult, wg *sync.WaitGroup, metricName string, triggerIndex int, scalerConfig scalersconfig.ScalerConfig, spec v2.MetricSpec) { result := metricResult{} // Pair metric values with their trigger names. This is applied only when @@ -623,7 +624,7 @@ func (h *scaleHandler) getScaledObjectState(ctx context.Context, scaledObject *k wg := sync.WaitGroup{} for scalerIndex := 0; scalerIndex < len(allScalers); scalerIndex++ { wg.Add(1) - go func(scaler scalers.Scaler, index int, scalerConfig scalers.ScalerConfig, results chan scalerState, wg *sync.WaitGroup) { + go func(scaler scalers.Scaler, index int, scalerConfig scalersconfig.ScalerConfig, results chan scalerState, wg *sync.WaitGroup) { results <- h.getScalerState(ctx, scaler, index, scalerConfig, cache, logger, scaledObject) wg.Done() }(allScalers[scalerIndex], scalerIndex, scalerConfigs[scalerIndex], results, &wg) @@ -709,7 +710,7 @@ type scalerState struct { // for an specific scaler. The state contains if it's active or // with erros, but also the records for the cache and he metrics // for the custom formulas -func (*scaleHandler) getScalerState(ctx context.Context, scaler scalers.Scaler, triggerIndex int, scalerConfig scalers.ScalerConfig, +func (*scaleHandler) getScalerState(ctx context.Context, scaler scalers.Scaler, triggerIndex int, scalerConfig scalersconfig.ScalerConfig, cache *cache.ScalersCache, logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject) scalerState { result := scalerState{ IsActive: false, diff --git a/pkg/scaling/scale_handler_test.go b/pkg/scaling/scale_handler_test.go index ca42f772754..65adfbdc637 100644 --- a/pkg/scaling/scale_handler_test.go +++ b/pkg/scaling/scale_handler_test.go @@ -43,6 +43,7 @@ import ( mock_scalers "github.com/kedacore/keda/v2/pkg/mock/mock_scaler" "github.com/kedacore/keda/v2/pkg/mock/mock_scaling/mock_executor" "github.com/kedacore/keda/v2/pkg/scalers" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/scaling/cache" "github.com/kedacore/keda/v2/pkg/scaling/cache/metricscache" ) @@ -75,8 +76,8 @@ func TestGetScaledObjectMetrics_DirectCall(t *testing.T) { scaler := mock_scalers.NewMockScaler(ctrl) // we are going to query metrics directly - scalerConfig := scalers.ScalerConfig{TriggerUseCachedMetrics: false} - factory := func() (scalers.Scaler, *scalers.ScalerConfig, error) { + scalerConfig := scalersconfig.ScalerConfig{TriggerUseCachedMetrics: false} + factory := func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { return scaler, &scalerConfig, nil } @@ -166,8 +167,8 @@ func TestGetScaledObjectMetrics_FromCache(t *testing.T) { scaler := mock_scalers.NewMockScaler(ctrl) // we are going to use cache for metrics values - scalerConfig := scalers.ScalerConfig{TriggerUseCachedMetrics: true} - factory := func() (scalers.Scaler, *scalers.ScalerConfig, error) { + scalerConfig := scalersconfig.ScalerConfig{TriggerUseCachedMetrics: true} + factory := func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { return scaler, &scalerConfig, nil } @@ -273,15 +274,15 @@ func TestGetScaledObjectMetrics_InParallel(t *testing.T) { time.Sleep(200 * time.Millisecond) return []external_metrics.ExternalMetricValue{scalers.GenerateMetricInMili(metricNames[index], float64(10))} } - scalerConfigFn := func(index int) *scalers.ScalerConfig { - return &scalers.ScalerConfig{ + scalerConfigFn := func(index int) *scalersconfig.ScalerConfig { + return &scalersconfig.ScalerConfig{ TriggerUseCachedMetrics: false, TriggerIndex: index, } } - scalerFactoryFn := func(index int) func() (scalers.Scaler, *scalers.ScalerConfig, error) { - return func() (scalers.Scaler, *scalers.ScalerConfig, error) { + scalerFactoryFn := func(index int) func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { + return func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { return scalerCollection[index], scalerConfigFn(index), nil } } @@ -386,11 +387,11 @@ func TestCheckScaledObjectScalersWithError(t *testing.T) { scaler.EXPECT().GetMetricsAndActivity(gomock.Any(), gomock.Any()).Return([]external_metrics.ExternalMetricValue{}, false, errors.New("some error")) scaler.EXPECT().Close(gomock.Any()) - factory := func() (scalers.Scaler, *scalers.ScalerConfig, error) { + factory := func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { scaler := mock_scalers.NewMockScaler(ctrl) scaler.EXPECT().GetMetricsAndActivity(gomock.Any(), gomock.Any()).Return([]external_metrics.ExternalMetricValue{}, false, errors.New("some error")) scaler.EXPECT().Close(gomock.Any()) - return scaler, &scalers.ScalerConfig{}, nil + return scaler, &scalersconfig.ScalerConfig{}, nil } scaledObject := kedav1alpha1.ScaledObject{ @@ -443,11 +444,11 @@ func TestCheckScaledObjectScalersWithTriggerAuthError(t *testing.T) { scaler := mock_scalers.NewMockScaler(ctrl) scaler.EXPECT().Close(gomock.Any()) - factory := func() (scalers.Scaler, *scalers.ScalerConfig, error) { + factory := func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { scaler := mock_scalers.NewMockScaler(ctrl) scaler.EXPECT().GetMetricsAndActivity(gomock.Any(), gomock.Any()).Return([]external_metrics.ExternalMetricValue{}, false, errors.New("some error")) scaler.EXPECT().Close(gomock.Any()) - return scaler, &scalers.ScalerConfig{}, nil + return scaler, &scalersconfig.ScalerConfig{}, nil } deployment := appsv1.Deployment{ @@ -562,21 +563,21 @@ func TestCheckScaledObjectFindFirstActiveNotIgnoreOthers(t *testing.T) { metricsSpecs := []v2.MetricSpec{createMetricSpec(1, "metric-name")} - activeFactory := func() (scalers.Scaler, *scalers.ScalerConfig, error) { + activeFactory := func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { scaler := mock_scalers.NewMockScaler(ctrl) scaler.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs) scaler.EXPECT().GetMetricsAndActivity(gomock.Any(), gomock.Any()).Return([]external_metrics.ExternalMetricValue{}, true, nil) scaler.EXPECT().Close(gomock.Any()) - return scaler, &scalers.ScalerConfig{}, nil + return scaler, &scalersconfig.ScalerConfig{}, nil } activeScaler, _, err := activeFactory() assert.Nil(t, err) - failingFactory := func() (scalers.Scaler, *scalers.ScalerConfig, error) { + failingFactory := func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { scaler := mock_scalers.NewMockScaler(ctrl) scaler.EXPECT().GetMetricsAndActivity(gomock.Any(), gomock.Any()).Return([]external_metrics.ExternalMetricValue{}, false, errors.New("some error")) scaler.EXPECT().Close(gomock.Any()) - return scaler, &scalers.ScalerConfig{}, nil + return scaler, &scalersconfig.ScalerConfig{}, nil } failingScaler := mock_scalers.NewMockScaler(ctrl) failingScaler.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs) @@ -639,8 +640,8 @@ func TestIsScaledJobActive(t *testing.T) { scalerCache := cache.ScalersCache{ Scalers: []cache.ScalerBuilder{{ Scaler: createScaler(ctrl, int64(20), int64(2), true, metricName), - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { - return createScaler(ctrl, int64(20), int64(2), true, metricName), &scalers.ScalerConfig{}, nil + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { + return createScaler(ctrl, int64(20), int64(2), true, metricName), &scalersconfig.ScalerConfig{}, nil }, }}, Recorder: recorder, @@ -676,23 +677,23 @@ func TestIsScaledJobActive(t *testing.T) { scaledJob := createScaledJob(scalerTestData.MinReplicaCount, scalerTestData.MaxReplicaCount, scalerTestData.MultipleScalersCalculation) scalersToTest := []cache.ScalerBuilder{{ Scaler: createScaler(ctrl, scalerTestData.Scaler1QueueLength, scalerTestData.Scaler1AverageValue, scalerTestData.Scaler1IsActive, scalerTestData.MetricName), - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { - return createScaler(ctrl, scalerTestData.Scaler1QueueLength, scalerTestData.Scaler1AverageValue, scalerTestData.Scaler1IsActive, scalerTestData.MetricName), &scalers.ScalerConfig{}, nil + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { + return createScaler(ctrl, scalerTestData.Scaler1QueueLength, scalerTestData.Scaler1AverageValue, scalerTestData.Scaler1IsActive, scalerTestData.MetricName), &scalersconfig.ScalerConfig{}, nil }, }, { Scaler: createScaler(ctrl, scalerTestData.Scaler2QueueLength, scalerTestData.Scaler2AverageValue, scalerTestData.Scaler2IsActive, scalerTestData.MetricName), - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { - return createScaler(ctrl, scalerTestData.Scaler2QueueLength, scalerTestData.Scaler2AverageValue, scalerTestData.Scaler2IsActive, scalerTestData.MetricName), &scalers.ScalerConfig{}, nil + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { + return createScaler(ctrl, scalerTestData.Scaler2QueueLength, scalerTestData.Scaler2AverageValue, scalerTestData.Scaler2IsActive, scalerTestData.MetricName), &scalersconfig.ScalerConfig{}, nil }, }, { Scaler: createScaler(ctrl, scalerTestData.Scaler3QueueLength, scalerTestData.Scaler3AverageValue, scalerTestData.Scaler3IsActive, scalerTestData.MetricName), - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { - return createScaler(ctrl, scalerTestData.Scaler3QueueLength, scalerTestData.Scaler3AverageValue, scalerTestData.Scaler3IsActive, scalerTestData.MetricName), &scalers.ScalerConfig{}, nil + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { + return createScaler(ctrl, scalerTestData.Scaler3QueueLength, scalerTestData.Scaler3AverageValue, scalerTestData.Scaler3IsActive, scalerTestData.MetricName), &scalersconfig.ScalerConfig{}, nil }, }, { Scaler: createScaler(ctrl, scalerTestData.Scaler4QueueLength, scalerTestData.Scaler4AverageValue, scalerTestData.Scaler4IsActive, scalerTestData.MetricName), - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { - return createScaler(ctrl, scalerTestData.Scaler4QueueLength, scalerTestData.Scaler4AverageValue, scalerTestData.Scaler4IsActive, scalerTestData.MetricName), &scalers.ScalerConfig{}, nil + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { + return createScaler(ctrl, scalerTestData.Scaler4QueueLength, scalerTestData.Scaler4AverageValue, scalerTestData.Scaler4IsActive, scalerTestData.MetricName), &scalersconfig.ScalerConfig{}, nil }, }} @@ -731,8 +732,8 @@ func TestIsScaledJobActiveIfQueueEmptyButMinReplicaCountGreaterZero(t *testing.T scaledJobSingle := createScaledJob(1, 100, "") // testing default = max scalerSingle := []cache.ScalerBuilder{{ Scaler: createScaler(ctrl, int64(0), int64(1), true, metricName), - Factory: func() (scalers.Scaler, *scalers.ScalerConfig, error) { - return createScaler(ctrl, int64(0), int64(1), true, metricName), &scalers.ScalerConfig{}, nil + Factory: func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { + return createScaler(ctrl, int64(0), int64(1), true, metricName), &scalersconfig.ScalerConfig{}, nil }, }} @@ -913,12 +914,12 @@ func TestScalingModifiersFormula(t *testing.T) { scaler1 := mock_scalers.NewMockScaler(ctrl) scaler2 := mock_scalers.NewMockScaler(ctrl) // dont use cached metrics - scalerConfig1 := scalers.ScalerConfig{TriggerUseCachedMetrics: false, TriggerName: triggerName1, TriggerIndex: 0} - scalerConfig2 := scalers.ScalerConfig{TriggerUseCachedMetrics: false, TriggerName: triggerName2, TriggerIndex: 1} - factory1 := func() (scalers.Scaler, *scalers.ScalerConfig, error) { + scalerConfig1 := scalersconfig.ScalerConfig{TriggerUseCachedMetrics: false, TriggerName: triggerName1, TriggerIndex: 0} + scalerConfig2 := scalersconfig.ScalerConfig{TriggerUseCachedMetrics: false, TriggerName: triggerName2, TriggerIndex: 1} + factory1 := func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { return scaler1, &scalerConfig1, nil } - factory2 := func() (scalers.Scaler, *scalers.ScalerConfig, error) { + factory2 := func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { return scaler2, &scalerConfig2, nil } diff --git a/pkg/scaling/scalers_builder.go b/pkg/scaling/scalers_builder.go index 3d3f63d057c..afcfc574bb1 100644 --- a/pkg/scaling/scalers_builder.go +++ b/pkg/scaling/scalers_builder.go @@ -27,6 +27,7 @@ import ( "github.com/kedacore/keda/v2/pkg/common/message" "github.com/kedacore/keda/v2/pkg/eventreason" "github.com/kedacore/keda/v2/pkg/scalers" + "github.com/kedacore/keda/v2/pkg/scalers/scalersconfig" "github.com/kedacore/keda/v2/pkg/scaling/cache" "github.com/kedacore/keda/v2/pkg/scaling/resolver" ) @@ -45,14 +46,14 @@ func (h *scaleHandler) buildScalers(ctx context.Context, withTriggers *kedav1alp for i, t := range withTriggers.Spec.Triggers { triggerIndex, trigger := i, t - factory := func() (scalers.Scaler, *scalers.ScalerConfig, error) { + factory := func() (scalers.Scaler, *scalersconfig.ScalerConfig, error) { if podTemplateSpec != nil { resolvedEnv, err = resolver.ResolveContainerEnv(ctx, h.client, logger, &podTemplateSpec.Spec, containerName, withTriggers.Namespace, h.secretsLister) if err != nil { return nil, nil, fmt.Errorf("error resolving secrets for ScaleTarget: %w", err) } } - config := &scalers.ScalerConfig{ + config := &scalersconfig.ScalerConfig{ ScalableObjectName: withTriggers.Name, ScalableObjectNamespace: withTriggers.Namespace, ScalableObjectType: withTriggers.Kind, @@ -118,7 +119,7 @@ func (h *scaleHandler) buildScalers(ctx context.Context, withTriggers *kedav1alp } // buildScaler builds a scaler form input config and trigger type -func buildScaler(ctx context.Context, client client.Client, triggerType string, config *scalers.ScalerConfig) (scalers.Scaler, error) { +func buildScaler(ctx context.Context, client client.Client, triggerType string, config *scalersconfig.ScalerConfig) (scalers.Scaler, error) { // TRIGGERS-START switch triggerType { case "activemq": diff --git a/vendor/github.com/aws/aws-sdk-go-v2/aws/config.go b/vendor/github.com/aws/aws-sdk-go-v2/aws/config.go index 1ee54cfe0f6..2264200c169 100644 --- a/vendor/github.com/aws/aws-sdk-go-v2/aws/config.go +++ b/vendor/github.com/aws/aws-sdk-go-v2/aws/config.go @@ -170,8 +170,7 @@ func NewConfig() *Config { return &Config{} } -// Copy will return a shallow copy of the Config object. If any additional -// configurations are provided they will be merged into the new config returned. +// Copy will return a shallow copy of the Config object. func (c Config) Copy() Config { cp := c return cp diff --git a/vendor/github.com/aws/aws-sdk-go-v2/aws/go_module_metadata.go b/vendor/github.com/aws/aws-sdk-go-v2/aws/go_module_metadata.go index 9a844f30e51..66d09630308 100644 --- a/vendor/github.com/aws/aws-sdk-go-v2/aws/go_module_metadata.go +++ b/vendor/github.com/aws/aws-sdk-go-v2/aws/go_module_metadata.go @@ -3,4 +3,4 @@ package aws // goModuleVersion is the tagged release for this module -const goModuleVersion = "1.24.0" +const goModuleVersion = "1.24.1" diff --git a/vendor/github.com/aws/aws-sdk-go-v2/aws/retry/middleware.go b/vendor/github.com/aws/aws-sdk-go-v2/aws/retry/middleware.go index 722ca34c6a0..dc703d482d2 100644 --- a/vendor/github.com/aws/aws-sdk-go-v2/aws/retry/middleware.go +++ b/vendor/github.com/aws/aws-sdk-go-v2/aws/retry/middleware.go @@ -328,10 +328,12 @@ func AddRetryMiddlewares(stack *smithymiddle.Stack, options AddRetryMiddlewaresO middleware.LogAttempts = options.LogRetryAttempts }) - if err := stack.Finalize.Add(attempt, smithymiddle.After); err != nil { + // index retry to before signing, if signing exists + if err := stack.Finalize.Insert(attempt, "Signing", smithymiddle.Before); err != nil { return err } - if err := stack.Finalize.Add(&MetricsHeader{}, smithymiddle.After); err != nil { + + if err := stack.Finalize.Insert(&MetricsHeader{}, attempt.ID(), smithymiddle.After); err != nil { return err } return nil diff --git a/vendor/github.com/aws/aws-sdk-go-v2/internal/configsources/CHANGELOG.md b/vendor/github.com/aws/aws-sdk-go-v2/internal/configsources/CHANGELOG.md index 5ceb3b82f47..dc87ec41027 100644 --- a/vendor/github.com/aws/aws-sdk-go-v2/internal/configsources/CHANGELOG.md +++ b/vendor/github.com/aws/aws-sdk-go-v2/internal/configsources/CHANGELOG.md @@ -1,3 +1,7 @@ +# v1.2.10 (2024-01-04) + +* **Dependency Update**: Updated to the latest SDK module versions + # v1.2.9 (2023-12-07) * **Dependency Update**: Updated to the latest SDK module versions diff --git a/vendor/github.com/aws/aws-sdk-go-v2/internal/configsources/go_module_metadata.go b/vendor/github.com/aws/aws-sdk-go-v2/internal/configsources/go_module_metadata.go index da7d0d813ef..41ee0bfbe3e 100644 --- a/vendor/github.com/aws/aws-sdk-go-v2/internal/configsources/go_module_metadata.go +++ b/vendor/github.com/aws/aws-sdk-go-v2/internal/configsources/go_module_metadata.go @@ -3,4 +3,4 @@ package configsources // goModuleVersion is the tagged release for this module -const goModuleVersion = "1.2.9" +const goModuleVersion = "1.2.10" diff --git a/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/partitions.json b/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/partitions.json index ab107ca5511..f376f6908aa 100644 --- a/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/partitions.json +++ b/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/partitions.json @@ -50,6 +50,9 @@ "ca-central-1" : { "description" : "Canada (Central)" }, + "ca-west-1" : { + "description" : "Canada West (Calgary)" + }, "eu-central-1" : { "description" : "Europe (Frankfurt)" }, diff --git a/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/v2/CHANGELOG.md b/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/v2/CHANGELOG.md index 761cc992b8e..e0265474c4f 100644 --- a/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/v2/CHANGELOG.md +++ b/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/v2/CHANGELOG.md @@ -1,3 +1,7 @@ +# v2.5.10 (2024-01-04) + +* **Dependency Update**: Updated to the latest SDK module versions + # v2.5.9 (2023-12-07) * **Dependency Update**: Updated to the latest SDK module versions diff --git a/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/v2/go_module_metadata.go b/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/v2/go_module_metadata.go index caabf668d49..bec2c6a1e9c 100644 --- a/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/v2/go_module_metadata.go +++ b/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/v2/go_module_metadata.go @@ -3,4 +3,4 @@ package endpoints // goModuleVersion is the tagged release for this module -const goModuleVersion = "2.5.9" +const goModuleVersion = "2.5.10" diff --git a/vendor/modules.txt b/vendor/modules.txt index 03e95d2f187..d32ebcaf4d4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -267,7 +267,7 @@ github.com/arangodb/go-velocypack # github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 ## explicit; go 1.13 github.com/asaskevich/govalidator -# github.com/aws/aws-sdk-go-v2 v1.24.0 +# github.com/aws/aws-sdk-go-v2 v1.24.1 ## explicit; go 1.19 github.com/aws/aws-sdk-go-v2/aws github.com/aws/aws-sdk-go-v2/aws/defaults @@ -313,10 +313,10 @@ github.com/aws/aws-sdk-go-v2/credentials/stscreds ## explicit; go 1.19 github.com/aws/aws-sdk-go-v2/feature/ec2/imds github.com/aws/aws-sdk-go-v2/feature/ec2/imds/internal/config -# github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 +# github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 ## explicit; go 1.19 github.com/aws/aws-sdk-go-v2/internal/configsources -# github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 +# github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 ## explicit; go 1.19 github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 # github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2