Skip to content

Commit

Permalink
Remove option for metric type, add triggerauthentications to rbac (#1125
Browse files Browse the repository at this point in the history
)

* Remove option for metric type, add triggerauthentications to rbac

* remove default constant

* update schema
  • Loading branch information
Richard87 authored May 31, 2024
1 parent d2ee76d commit 7ffd8b1
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 165 deletions.
4 changes: 2 additions & 2 deletions charts/radix-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions charts/radix-operator/templates/radix-operator-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ rules:
- keda.sh
resources:
- scaledobjects
- triggerauthentications
verbs:
- get
- list
Expand Down
66 changes: 18 additions & 48 deletions charts/radix-operator/templates/radixapplication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
40 changes: 4 additions & 36 deletions json-schema/radixapplication.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/deployment/scaledobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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),
},
Expand All @@ -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),
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/deployment/scaledobject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}},
},
Expand Down
44 changes: 6 additions & 38 deletions pkg/apis/radix/v1/radixhorizontalscalingtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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),
},
})
}
Expand All @@ -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),
},
})
}
Expand All @@ -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,
},
})
}
Expand Down
Loading

0 comments on commit 7ffd8b1

Please sign in to comment.