make targetQueryValue configurable in postgreSQL scaler
@@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/metrics/pkg/apis/external_metrics"
logf "sigs.k8s.io/controller-runtime/pkg/log"
+ "strconv"
)
const (
@@ -24,6 +25,7 @@ type postgreSQLScaler struct {
}
type postgreSQLMetadata struct {
+ targetQueryValue int
connection string
userName string
password string
@@ -62,6 +64,16 @@ func parsePostgreSQLMetadata(resolvedEnv, metadata, authParams map[string]string
return nil, fmt.Errorf("no query given")
}
+ if val, ok := metadata["targetQueryValue"]; ok {
+ targetQueryValue, err := strconv.Atoi(val)
+ if err != nil {
+ return nil, fmt.Errorf("queryValue parsing error %s", err.Error())
+ }
+ meta.targetQueryValue = targetQueryValue
+ } else {
+ return nil, fmt.Errorf("no targetQueryValue given")
+ }
+
if val, ok := authParams["connection"]; ok {
meta.connection = val
} else if val, ok := metadata["connection"]; ok {
@@ -171,10 +183,10 @@ func (s *postgreSQLScaler) getActiveNumber() (int, error) {
// GetMetricSpecForScaling returns the MetricSpec for the Horizontal Pod Autoscaler
func (s *postgreSQLScaler) GetMetricSpecForScaling() []v2beta1.MetricSpec {
- targetListLengthQty := resource.NewQuantity(1, resource.DecimalSI)
+ targetQueryValue := resource.NewQuantity(int64(s.metadata.targetQueryValue), resource.DecimalSI)
externalMetric := &v2beta1.ExternalMetricSource{
MetricName: pgMetricName,
- TargetAverageValue: targetListLengthQty,
+ TargetAverageValue: targetQueryValue,
}
metricSpec := v2beta1.MetricSpec{
External: externalMetric, Type: externalMetricType,
