Skip to content

Commit

Permalink
Change option name from MultipleScalersOption to MultipleScalersCalcu…
Browse files Browse the repository at this point in the history
…lation

Signed-off-by: Tsuyoshi Ushio <ushio@simplearchitect.com>
  • Loading branch information
TsuyoshiUshio committed Sep 4, 2021
1 parent e604a68 commit 784bc7c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion apis/keda/v1alpha1/scaledjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type ScalingStrategy struct {
// +optional
PendingPodConditions []string `json:"pendingPodConditions,omitempty"`
// +optional
MultipleScalersOption string `json:"multipleScalersOption,omitempty"`
MultipleScalersCalculation string `json:"multipleScalersCalculation,omitempty"`
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/keda.sh_scaledjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7362,7 +7362,7 @@ spec:
type: integer
customScalingRunningJobPercentage:
type: string
multipleScalersOption:
multipleScalersCalculation:
type: string
pendingPodConditions:
items:
Expand Down
6 changes: 3 additions & 3 deletions pkg/scaling/scaledjob/scale_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/go-logr/logr"
kedav1alpha1 "github.com/kedacore/keda/v2/api/v1alpha1"
kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
"github.com/kedacore/keda/v2/pkg/eventreason"
"github.com/kedacore/keda/v2/pkg/scalers"
"k8s.io/api/autoscaling/v2beta2"
Expand All @@ -28,7 +28,7 @@ func GetScaleMetrics(ctx context.Context, scalers []scalers.Scaler, scaledJob *k

logger := logf.Log.WithName("scalemetrics")
scalersMetrics := getScalersMetrics(ctx, scalers, scaledJob, logger, recorder)
switch scaledJob.Spec.ScalingStrategy.MultipleScalersOption {
switch scaledJob.Spec.ScalingStrategy.MultipleScalersCalculation {
case "min":
for _, metrics := range scalersMetrics {
if (queueLength == 0 || metrics.queueLength < queueLength) && metrics.isActive {
Expand Down Expand Up @@ -71,7 +71,7 @@ func GetScaleMetrics(ctx context.Context, scalers []scalers.Scaler, scaledJob *k
}
}
maxValue = min(scaledJob.MaxReplicaCount(), maxValue)
logger.V(1).WithValues("ScaledJob", scaledJob.Name).Info("Checking if ScaleJob scalers are active", "isActive", isActive, "maxValue", maxValue, "MultipleScalersOption", scaledJob.Spec.ScalingStrategy.MultipleScalersOption)
logger.V(1).WithValues("ScaledJob", scaledJob.Name).Info("Checking if ScaleJob scalers are active", "isActive", isActive, "maxValue", maxValue, "MultipleScalersCalculation", scaledJob.Spec.ScalingStrategy.MultipleScalersCalculation)

return isActive, queueLength, maxValue
}
Expand Down
80 changes: 40 additions & 40 deletions pkg/scaling/scaledjob/scale_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/go-playground/assert/v2"
"github.com/golang/mock/gomock"
kedav1alpha1 "github.com/kedacore/keda/v2/api/v1alpha1"
kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
mock_scalers "github.com/kedacore/keda/v2/pkg/mock/mock_scaler"
"github.com/kedacore/keda/v2/pkg/scalers"
"k8s.io/api/autoscaling/v2beta2"
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestIsScaledJobActive(t *testing.T) {
}

for index, scalerTestData := range scalerTestDatam {
scaledJob := createScaledObject(scalerTestData.MaxReplicaCount, scalerTestData.MultipleScalersOption)
scaledJob := createScaledObject(scalerTestData.MaxReplicaCount, scalerTestData.MultipleScalersCalculation)
scalers := []scalers.Scaler{
createScaler(ctrl, scalerTestData.Scaler1QueueLength, scalerTestData.Scaler1AverageValue, scalerTestData.Scaler1IsActive),
createScaler(ctrl, scalerTestData.Scaler2QueueLength, scalerTestData.Scaler2AverageValue, scalerTestData.Scaler2IsActive),
Expand All @@ -112,7 +112,7 @@ func TestIsScaledJobActive(t *testing.T) {

func newScalerTestData(
maxReplicaCount int,
multipleScalersOption string,
multipleScalersCalculation string,
scaler1QueueLength, //nolint:golint,unparam
scaler1AverageValue int, //nolint:golint,unparam
scaler1IsActive bool, //nolint:golint,unparam
Expand All @@ -129,53 +129,53 @@ func newScalerTestData(
resultQueueLength,
resultMaxLength int) scalerTestData {
return scalerTestData{
MaxReplicaCount: int32(maxReplicaCount),
MultipleScalersOption: multipleScalersOption,
Scaler1QueueLength: int64(scaler1QueueLength),
Scaler1AverageValue: int32(scaler1AverageValue),
Scaler1IsActive: scaler1IsActive,
Scaler2QueueLength: int64(scaler2QueueLength),
Scaler2AverageValue: int32(scaler2AverageValue),
Scaler2IsActive: scaler2IsActive,
Scaler3QueueLength: int64(scaler3QueueLength),
Scaler3AverageValue: int32(scaler3AverageValue),
Scaler3IsActive: scaler3IsActive,
Scaler4QueueLength: int64(scaler4QueueLength),
Scaler4AverageValue: int32(scaler4AverageValue),
Scaler4IsActive: scaler4IsActive,
ResultIsActive: resultIsActive,
ResultQueueLength: int64(resultQueueLength),
ResultMaxValue: int64(resultMaxLength),
MaxReplicaCount: int32(maxReplicaCount),
MultipleScalersCalculation: multipleScalersCalculation,
Scaler1QueueLength: int64(scaler1QueueLength),
Scaler1AverageValue: int32(scaler1AverageValue),
Scaler1IsActive: scaler1IsActive,
Scaler2QueueLength: int64(scaler2QueueLength),
Scaler2AverageValue: int32(scaler2AverageValue),
Scaler2IsActive: scaler2IsActive,
Scaler3QueueLength: int64(scaler3QueueLength),
Scaler3AverageValue: int32(scaler3AverageValue),
Scaler3IsActive: scaler3IsActive,
Scaler4QueueLength: int64(scaler4QueueLength),
Scaler4AverageValue: int32(scaler4AverageValue),
Scaler4IsActive: scaler4IsActive,
ResultIsActive: resultIsActive,
ResultQueueLength: int64(resultQueueLength),
ResultMaxValue: int64(resultMaxLength),
}
}

type scalerTestData struct {
MaxReplicaCount int32
MultipleScalersOption string
Scaler1QueueLength int64
Scaler1AverageValue int32
Scaler1IsActive bool
Scaler2QueueLength int64
Scaler2AverageValue int32
Scaler2IsActive bool
Scaler3QueueLength int64
Scaler3AverageValue int32
Scaler3IsActive bool
Scaler4QueueLength int64
Scaler4AverageValue int32
Scaler4IsActive bool
ResultIsActive bool
ResultQueueLength int64
ResultMaxValue int64
MaxReplicaCount int32
MultipleScalersCalculation string
Scaler1QueueLength int64
Scaler1AverageValue int32
Scaler1IsActive bool
Scaler2QueueLength int64
Scaler2AverageValue int32
Scaler2IsActive bool
Scaler3QueueLength int64
Scaler3AverageValue int32
Scaler3IsActive bool
Scaler4QueueLength int64
Scaler4AverageValue int32
Scaler4IsActive bool
ResultIsActive bool
ResultQueueLength int64
ResultMaxValue int64
}

func createScaledObject(maxReplicaCount int32, multipleScalersOption string) *kedav1alpha1.ScaledJob {
if multipleScalersOption != "" {
func createScaledObject(maxReplicaCount int32, multipleScalersCalculation string) *kedav1alpha1.ScaledJob {
if multipleScalersCalculation != "" {
return &kedav1alpha1.ScaledJob{
Spec: kedav1alpha1.ScaledJobSpec{
MaxReplicaCount: &maxReplicaCount,
ScalingStrategy: kedav1alpha1.ScalingStrategy{
MultipleScalersOption: multipleScalersOption,
MultipleScalersCalculation: multipleScalersCalculation,
},
},
}
Expand Down

0 comments on commit 784bc7c

Please sign in to comment.