diff --git a/charts/radix-operator/Chart.yaml b/charts/radix-operator/Chart.yaml index 9d03ba675..9406b2349 100644 --- a/charts/radix-operator/Chart.yaml +++ b/charts/radix-operator/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: radix-operator -version: 1.35.1 -appVersion: 1.55.1 +version: 1.35.2 +appVersion: 1.55.2 kubeVersion: ">=1.24.0" description: Radix Operator keywords: diff --git a/charts/radix-operator/templates/radix-operator-rbac.yaml b/charts/radix-operator/templates/radix-operator-rbac.yaml index 9378d9dcb..1172205d7 100644 --- a/charts/radix-operator/templates/radix-operator-rbac.yaml +++ b/charts/radix-operator/templates/radix-operator-rbac.yaml @@ -185,6 +185,7 @@ rules: - keda.sh resources: - scaledobjects + - triggerauthentications verbs: - get - list diff --git a/charts/radix-operator/templates/radixapplication.yaml b/charts/radix-operator/templates/radixapplication.yaml index ea5cabe05..52a175ce3 100644 --- a/charts/radix-operator/templates/radixapplication.yaml +++ b/charts/radix-operator/templates/radixapplication.yaml @@ -577,19 +577,12 @@ spec: description: Cpu defines a trigger based on CPU usage properties: - metricType: - description: Defines the type of metric - to use. Options are Utilization or AverageValue. - Defaults to AverageValue. - enum: - - Utilization - - AverageValue - type: string value: - description: |- - Value to trigger scaling actions for: - When using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. - When using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity). + description: Value - the target value is + the average of the resource metric across + all relevant pods, represented as a percentage + of the requested value of the resource + for the pods. minimum: 15 type: integer required: @@ -634,19 +627,12 @@ spec: description: Memory defines a trigger based on memory usage properties: - metricType: - description: Defines the type of metric - to use. Options are Utilization or AverageValue. - Defaults to AverageValue. - enum: - - Utilization - - AverageValue - type: string value: - description: |- - Value to trigger scaling actions for: - When using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. - When using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity). + description: Value - the target value is + the average of the resource metric across + all relevant pods, represented as a percentage + of the requested value of the resource + for the pods. minimum: 15 type: integer required: @@ -1273,19 +1259,11 @@ spec: cpu: description: Cpu defines a trigger based on CPU usage properties: - metricType: - description: Defines the type of metric to use. - Options are Utilization or AverageValue. Defaults - to AverageValue. - enum: - - Utilization - - AverageValue - type: string value: - description: |- - Value to trigger scaling actions for: - When using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. - When using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity). + description: Value - the target value is the average + of the resource metric across all relevant pods, + represented as a percentage of the requested + value of the resource for the pods. minimum: 15 type: integer required: @@ -1328,19 +1306,11 @@ spec: description: Memory defines a trigger based on memory usage properties: - metricType: - description: Defines the type of metric to use. - Options are Utilization or AverageValue. Defaults - to AverageValue. - enum: - - Utilization - - AverageValue - type: string value: - description: |- - Value to trigger scaling actions for: - When using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. - When using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity). + description: Value - the target value is the average + of the resource metric across all relevant pods, + represented as a percentage of the requested + value of the resource for the pods. minimum: 15 type: integer required: diff --git a/json-schema/radixapplication.json b/json-schema/radixapplication.json index 3ce9e5d09..87a6181b2 100644 --- a/json-schema/radixapplication.json +++ b/json-schema/radixapplication.json @@ -553,16 +553,8 @@ "cpu": { "description": "Cpu defines a trigger based on CPU usage", "properties": { - "metricType": { - "description": "Defines the type of metric to use. Options are Utilization or AverageValue. Defaults to AverageValue.", - "enum": [ - "Utilization", - "AverageValue" - ], - "type": "string" - }, "value": { - "description": "Value to trigger scaling actions for:\nWhen using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.\nWhen using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity).", + "description": "Value - the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.", "minimum": 15, "type": "integer" } @@ -606,16 +598,8 @@ "memory": { "description": "Memory defines a trigger based on memory usage", "properties": { - "metricType": { - "description": "Defines the type of metric to use. Options are Utilization or AverageValue. Defaults to AverageValue.", - "enum": [ - "Utilization", - "AverageValue" - ], - "type": "string" - }, "value": { - "description": "Value to trigger scaling actions for:\nWhen using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.\nWhen using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity).", + "description": "Value - the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.", "minimum": 15, "type": "integer" } @@ -1253,16 +1237,8 @@ "cpu": { "description": "Cpu defines a trigger based on CPU usage", "properties": { - "metricType": { - "description": "Defines the type of metric to use. Options are Utilization or AverageValue. Defaults to AverageValue.", - "enum": [ - "Utilization", - "AverageValue" - ], - "type": "string" - }, "value": { - "description": "Value to trigger scaling actions for:\nWhen using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.\nWhen using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity).", + "description": "Value - the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.", "minimum": 15, "type": "integer" } @@ -1306,16 +1282,8 @@ "memory": { "description": "Memory defines a trigger based on memory usage", "properties": { - "metricType": { - "description": "Defines the type of metric to use. Options are Utilization or AverageValue. Defaults to AverageValue.", - "enum": [ - "Utilization", - "AverageValue" - ], - "type": "string" - }, "value": { - "description": "Value to trigger scaling actions for:\nWhen using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.\nWhen using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity).", + "description": "Value - the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.", "minimum": 15, "type": "integer" } diff --git a/pkg/apis/deployment/scaledobject.go b/pkg/apis/deployment/scaledobject.go index 7f0816943..363e13cb6 100644 --- a/pkg/apis/deployment/scaledobject.go +++ b/pkg/apis/deployment/scaledobject.go @@ -14,6 +14,7 @@ import ( kedav1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" "github.com/rs/zerolog/log" appsv1 "k8s.io/api/apps/v1" + autoscalingv2 "k8s.io/api/autoscaling/v2" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -177,7 +178,7 @@ func getScalingTriggers(componentName string, config *radixv1.RadixHorizontalSca triggers = append(triggers, kedav1.ScaleTriggers{ Name: trigger.Name, Type: "cpu", - MetricType: trigger.Cpu.MetricType, + MetricType: autoscalingv2.UtilizationMetricType, Metadata: map[string]string{ "value": strconv.Itoa(trigger.Cpu.Value), }, @@ -186,7 +187,7 @@ func getScalingTriggers(componentName string, config *radixv1.RadixHorizontalSca triggers = append(triggers, kedav1.ScaleTriggers{ Name: trigger.Name, Type: "memory", - MetricType: trigger.Memory.MetricType, + MetricType: autoscalingv2.UtilizationMetricType, Metadata: map[string]string{ "value": strconv.Itoa(trigger.Memory.Value), }, diff --git a/pkg/apis/deployment/scaledobject_test.go b/pkg/apis/deployment/scaledobject_test.go index d2aa30d61..c646e4ac4 100644 --- a/pkg/apis/deployment/scaledobject_test.go +++ b/pkg/apis/deployment/scaledobject_test.go @@ -189,14 +189,14 @@ func TestScalerTriggers(t *testing.T) { { name: "CPU", builder: utils.NewHorizontalScalingBuilder().WithCPUTrigger(80), - expected: v1alpha1.ScaleTriggers{Name: "cpu", Type: "cpu", MetricType: autoscalingv2.AverageValueMetricType, Metadata: map[string]string{ + expected: v1alpha1.ScaleTriggers{Name: "cpu", Type: "cpu", MetricType: autoscalingv2.UtilizationMetricType, Metadata: map[string]string{ "value": "80", }}, }, { name: "Memory", builder: utils.NewHorizontalScalingBuilder().WithMemoryTrigger(80), - expected: v1alpha1.ScaleTriggers{Name: "memory", Type: "memory", MetricType: autoscalingv2.AverageValueMetricType, Metadata: map[string]string{ + expected: v1alpha1.ScaleTriggers{Name: "memory", Type: "memory", MetricType: autoscalingv2.UtilizationMetricType, Metadata: map[string]string{ "value": "80", }}, }, diff --git a/pkg/apis/radix/v1/radixhorizontalscalingtypes.go b/pkg/apis/radix/v1/radixhorizontalscalingtypes.go index 432f0a08d..5c2aad4b4 100644 --- a/pkg/apis/radix/v1/radixhorizontalscalingtypes.go +++ b/pkg/apis/radix/v1/radixhorizontalscalingtypes.go @@ -2,8 +2,6 @@ package v1 import ( "github.com/equinor/radix-common/utils/pointers" - // "github.com/equinor/radix-operator/pkg/apis/deployment" - autoscalingv2 "k8s.io/api/autoscaling/v2" ) const ( @@ -85,26 +83,13 @@ type RadixHorizontalScalingTrigger struct { } type RadixHorizontalScalingCPUTrigger struct { - // Defines the type of metric to use. Options are Utilization or AverageValue. Defaults to AverageValue. - // +optional - // +kubebuilder:validation:Enum=Utilization;AverageValue - MetricType autoscalingv2.MetricTargetType `json:"metricType,omitempty"` - - // Value to trigger scaling actions for: - // When using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. - // When using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity). + // Value - the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. // +kubebuilder:validation:Minimum=15 Value int `json:"value"` } -type RadixHorizontalScalingMemoryTrigger struct { - // Defines the type of metric to use. Options are Utilization or AverageValue. Defaults to AverageValue. - // +optional - // +kubebuilder:validation:Enum=Utilization;AverageValue - MetricType autoscalingv2.MetricTargetType `json:"metricType,omitempty"` - // Value to trigger scaling actions for: - // When using Utilization, the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. - // When using AverageValue, the target value is the target value of the average of the metric across all relevant pods (quantity). +type RadixHorizontalScalingMemoryTrigger struct { + // Value - the target value is the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. // +kubebuilder:validation:Minimum=15 Value int `json:"value"` } @@ -192,8 +177,7 @@ func (c *RadixHorizontalScaling) NormalizeConfig() *RadixHorizontalScaling { config.Triggers = append(config.Triggers, RadixHorizontalScalingTrigger{ Name: "CPU", Cpu: &RadixHorizontalScalingCPUTrigger{ - MetricType: autoscalingv2.UtilizationMetricType, - Value: int(*c.RadixHorizontalScalingResources.Cpu.AverageUtilization), + Value: int(*c.RadixHorizontalScalingResources.Cpu.AverageUtilization), }, }) } @@ -202,8 +186,7 @@ func (c *RadixHorizontalScaling) NormalizeConfig() *RadixHorizontalScaling { config.Triggers = append(config.Triggers, RadixHorizontalScalingTrigger{ Name: "Memory", Memory: &RadixHorizontalScalingMemoryTrigger{ - MetricType: autoscalingv2.UtilizationMetricType, - Value: int(*c.RadixHorizontalScalingResources.Memory.AverageUtilization), + Value: int(*c.RadixHorizontalScalingResources.Memory.AverageUtilization), }, }) } @@ -213,26 +196,11 @@ func (c *RadixHorizontalScaling) NormalizeConfig() *RadixHorizontalScaling { config.MinReplicas = pointers.Ptr[int32](1) } - // Set defaults for triggers - for _, trigger := range config.Triggers { - switch { - case trigger.Cpu != nil: - if trigger.Cpu.MetricType == "" { - trigger.Cpu.MetricType = autoscalingv2.AverageValueMetricType - } - case trigger.Memory != nil: - if trigger.Memory.MetricType == "" { - trigger.Memory.MetricType = autoscalingv2.AverageValueMetricType - } - } - } - if len(config.Triggers) == 0 { config.Triggers = append(config.Triggers, RadixHorizontalScalingTrigger{ Name: "default-cpu", Cpu: &RadixHorizontalScalingCPUTrigger{ - MetricType: autoscalingv2.AverageValueMetricType, - Value: DefaultTargetCPUUtilizationPercentage, + Value: DefaultTargetCPUUtilizationPercentage, }, }) } diff --git a/pkg/apis/radixvalidators/validate_ra.go b/pkg/apis/radixvalidators/validate_ra.go index 559f4f689..aeaa2bd11 100644 --- a/pkg/apis/radixvalidators/validate_ra.go +++ b/pkg/apis/radixvalidators/validate_ra.go @@ -26,7 +26,6 @@ import ( radixclient "github.com/equinor/radix-operator/pkg/client/clientset/versioned" "github.com/google/uuid" "github.com/robfig/cron/v3" - autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) @@ -1224,11 +1223,6 @@ func validateTriggerDefintion(config *radixv1.RadixHorizontalScaling) error { errs = append(errs, fmt.Errorf("invalid trigger %s: value must be set: %w", trigger.Name, ErrInvalidTriggerDefinition)) } - validCpuMetricTypes := []autoscalingv2.MetricTargetType{autoscalingv2.AverageValueMetricType, autoscalingv2.UtilizationMetricType} - if !slices.Contains(validCpuMetricTypes, trigger.Cpu.MetricType) { - errs = append(errs, fmt.Errorf("invalid trigger %s: metric type %s is invalid: %w", trigger.Name, trigger.Cpu.MetricType, ErrInvalidTriggerDefinition)) - } - } if trigger.Memory != nil { definitions++ @@ -1236,11 +1230,6 @@ func validateTriggerDefintion(config *radixv1.RadixHorizontalScaling) error { if trigger.Memory.Value == 0 { errs = append(errs, fmt.Errorf("invalid trigger %s: value must be set: %w", trigger.Name, ErrInvalidTriggerDefinition)) } - - validMemoryMetricTypes := []autoscalingv2.MetricTargetType{autoscalingv2.AverageValueMetricType, autoscalingv2.UtilizationMetricType} - if !slices.Contains(validMemoryMetricTypes, trigger.Memory.MetricType) { - errs = append(errs, fmt.Errorf("invalid trigger %s: metric type %s is invalid: %w", trigger.Name, trigger.Memory.MetricType, ErrInvalidTriggerDefinition)) - } } if trigger.Cron != nil { definitions++ diff --git a/pkg/apis/radixvalidators/validate_ra_test.go b/pkg/apis/radixvalidators/validate_ra_test.go index 4f6de30fc..5f0dd6bed 100644 --- a/pkg/apis/radixvalidators/validate_ra_test.go +++ b/pkg/apis/radixvalidators/validate_ra_test.go @@ -1872,26 +1872,6 @@ func Test_HorizontalScaling_Validation(t *testing.T) { }, []error{radixvalidators.ErrDuplicateTriggerName}, }, - { - "Cpu trigger must have valid metricType", - func(ra *radixv1.RadixApplication) { - ra.Spec.Components[0].EnvironmentConfig[0].HorizontalScaling = utils.NewHorizontalScalingBuilder(). - WithMinReplicas(1). - WithTrigger(radixv1.RadixHorizontalScalingTrigger{Name: "test", Cpu: &radixv1.RadixHorizontalScalingCPUTrigger{Value: 99, MetricType: "test"}}). - Build() - }, - []error{radixvalidators.ErrInvalidTriggerDefinition}, - }, - { - "Memory trigger must have valid metricType", - func(ra *radixv1.RadixApplication) { - ra.Spec.Components[0].EnvironmentConfig[0].HorizontalScaling = utils.NewHorizontalScalingBuilder(). - WithMinReplicas(1). - WithTrigger(radixv1.RadixHorizontalScalingTrigger{Name: "test", Memory: &radixv1.RadixHorizontalScalingMemoryTrigger{Value: 99, MetricType: "test"}}). - Build() - }, - []error{radixvalidators.ErrInvalidTriggerDefinition}, - }, } _, client := validRASetup() diff --git a/pkg/apis/utils/horizontalscaling_builder.go b/pkg/apis/utils/horizontalscaling_builder.go index 6768bce84..d5d44d921 100644 --- a/pkg/apis/utils/horizontalscaling_builder.go +++ b/pkg/apis/utils/horizontalscaling_builder.go @@ -2,7 +2,6 @@ package utils import ( radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1" - v2 "k8s.io/api/autoscaling/v2" ) type HorizontalScalingBuilderStruct struct { @@ -81,7 +80,7 @@ func (h *HorizontalScalingBuilderStruct) WithPollingInterval(pollingInterval int func (h *HorizontalScalingBuilderStruct) WithCPUTrigger(value int) *HorizontalScalingBuilderStruct { h.WithTrigger(radixv1.RadixHorizontalScalingTrigger{ Name: "cpu", - Cpu: &radixv1.RadixHorizontalScalingCPUTrigger{Value: value, MetricType: v2.AverageValueMetricType}, + Cpu: &radixv1.RadixHorizontalScalingCPUTrigger{Value: value}, }) return h } @@ -89,7 +88,7 @@ func (h *HorizontalScalingBuilderStruct) WithCPUTrigger(value int) *HorizontalSc func (h *HorizontalScalingBuilderStruct) WithMemoryTrigger(value int) *HorizontalScalingBuilderStruct { h.WithTrigger(radixv1.RadixHorizontalScalingTrigger{ Name: "memory", - Memory: &radixv1.RadixHorizontalScalingMemoryTrigger{Value: value, MetricType: v2.AverageValueMetricType}, + Memory: &radixv1.RadixHorizontalScalingMemoryTrigger{Value: value}, }) return h } diff --git a/pkg/apis/utils/horizontalscaling_builder_test.go b/pkg/apis/utils/horizontalscaling_builder_test.go index 2682ca628..c7d2d9c23 100644 --- a/pkg/apis/utils/horizontalscaling_builder_test.go +++ b/pkg/apis/utils/horizontalscaling_builder_test.go @@ -8,7 +8,6 @@ import ( "github.com/equinor/radix-operator/pkg/apis/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - autoscalingv2 "k8s.io/api/autoscaling/v2" ) func Test_EmptyHorizontalScalingBuilder(t *testing.T) { @@ -50,12 +49,12 @@ func Test_HorizontalScalingBuilder_Triggers(t *testing.T) { { name: "CPU", actual: utils.NewHorizontalScalingBuilder().WithCPUTrigger(80).Build(), - expected: radixv1.RadixHorizontalScalingTrigger{Name: "cpu", Cpu: &radixv1.RadixHorizontalScalingCPUTrigger{Value: 80, MetricType: autoscalingv2.AverageValueMetricType}}, + expected: radixv1.RadixHorizontalScalingTrigger{Name: "cpu", Cpu: &radixv1.RadixHorizontalScalingCPUTrigger{Value: 80}}, }, { name: "Memory", actual: utils.NewHorizontalScalingBuilder().WithMemoryTrigger(80).Build(), - expected: radixv1.RadixHorizontalScalingTrigger{Name: "memory", Memory: &radixv1.RadixHorizontalScalingMemoryTrigger{Value: 80, MetricType: autoscalingv2.AverageValueMetricType}}, + expected: radixv1.RadixHorizontalScalingTrigger{Name: "memory", Memory: &radixv1.RadixHorizontalScalingMemoryTrigger{Value: 80}}, }, { name: "Cron",