Skip to content

Commit 7a79233

Browse files
authored
fix(collector-webhook): ensure stabilizationWindowSeconds validation matches k8s.io/api/autoscaling/v2 requirements (#3346)
* fix(collector-webhook): ensure `stabilizationWindowSeconds` validation matches `k8s.io/api/autoscaling/v2` requirements * chore: add changelog for fix
1 parent 3147097 commit 7a79233

File tree

3 files changed

+62
-10
lines changed

3 files changed

+62
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector-webhook
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: "Fixed validation of `stabilizationWindowSeconds` in autoscaler behaviour"
9+
10+
# One or more tracking issues related to the change
11+
issues: [3345]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: |
17+
The validation of `stabilizationWindowSeconds` in the `autoscaler.behaviour.scale[Up|Down]` incorrectly rejected 0 as an invalid value.
18+
This has been fixed to ensure that the value is validated correctly (should be >=0 and <=3600) and the error messsage has been updated to reflect this.

apis/v1beta1/collector_webhook.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,13 @@ func ValidatePorts(ports []PortsSpec) error {
385385
func checkAutoscalerSpec(autoscaler *AutoscalerSpec) error {
386386
if autoscaler.Behavior != nil {
387387
if autoscaler.Behavior.ScaleDown != nil && autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds != nil &&
388-
*autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds < int32(1) {
389-
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, scaleDown should be one or more")
388+
(*autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds < int32(0) || *autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds > 3600) {
389+
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, scaleDown.stabilizationWindowSeconds should be >=0 and <=3600")
390390
}
391391

392392
if autoscaler.Behavior.ScaleUp != nil && autoscaler.Behavior.ScaleUp.StabilizationWindowSeconds != nil &&
393-
*autoscaler.Behavior.ScaleUp.StabilizationWindowSeconds < int32(1) {
394-
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, scaleUp should be one or more")
393+
(*autoscaler.Behavior.ScaleUp.StabilizationWindowSeconds < int32(0) || *autoscaler.Behavior.ScaleUp.StabilizationWindowSeconds > 3600) {
394+
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, scaleUp.stabilizationWindowSeconds should be >=0 and <=3600")
395395
}
396396
}
397397
if autoscaler.TargetCPUUtilization != nil && *autoscaler.TargetCPUUtilization < int32(1) {

apis/v1beta1/collector_webhook_test.go

+40-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package v1beta1_test
1717
import (
1818
"context"
1919
"fmt"
20+
"math"
2021
"os"
2122
"testing"
2223

@@ -582,6 +583,7 @@ func TestOTELColValidatingWebhook(t *testing.T) {
582583
one := int32(1)
583584
three := int32(3)
584585
five := int32(5)
586+
maxInt := int32(math.MaxInt32)
585587

586588
cfg := v1beta1.Config{}
587589
err := yaml.Unmarshal([]byte(cfgYaml), &cfg)
@@ -913,36 +915,68 @@ func TestOTELColValidatingWebhook(t *testing.T) {
913915
expectedErr: "minReplicas should be one or more",
914916
},
915917
{
916-
name: "invalid autoscaler scale down",
918+
name: "invalid autoscaler scale down stablization window - <0",
917919
otelcol: v1beta1.OpenTelemetryCollector{
918920
Spec: v1beta1.OpenTelemetryCollectorSpec{
919921
Autoscaler: &v1beta1.AutoscalerSpec{
920922
MaxReplicas: &three,
921923
Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{
922924
ScaleDown: &autoscalingv2.HPAScalingRules{
923-
StabilizationWindowSeconds: &zero,
925+
StabilizationWindowSeconds: &minusOne,
924926
},
925927
},
926928
},
927929
},
928930
},
929-
expectedErr: "scaleDown should be one or more",
931+
expectedErr: "scaleDown.stabilizationWindowSeconds should be >=0 and <=3600",
930932
},
931933
{
932-
name: "invalid autoscaler scale up",
934+
name: "invalid autoscaler scale down stablization window - >3600",
935+
otelcol: v1beta1.OpenTelemetryCollector{
936+
Spec: v1beta1.OpenTelemetryCollectorSpec{
937+
Autoscaler: &v1beta1.AutoscalerSpec{
938+
MaxReplicas: &three,
939+
Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{
940+
ScaleDown: &autoscalingv2.HPAScalingRules{
941+
StabilizationWindowSeconds: &maxInt,
942+
},
943+
},
944+
},
945+
},
946+
},
947+
expectedErr: "scaleDown.stabilizationWindowSeconds should be >=0 and <=3600",
948+
},
949+
{
950+
name: "invalid autoscaler scale up stablization window - <0",
951+
otelcol: v1beta1.OpenTelemetryCollector{
952+
Spec: v1beta1.OpenTelemetryCollectorSpec{
953+
Autoscaler: &v1beta1.AutoscalerSpec{
954+
MaxReplicas: &three,
955+
Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{
956+
ScaleUp: &autoscalingv2.HPAScalingRules{
957+
StabilizationWindowSeconds: &minusOne,
958+
},
959+
},
960+
},
961+
},
962+
},
963+
expectedErr: "scaleUp.stabilizationWindowSeconds should be >=0 and <=3600",
964+
},
965+
{
966+
name: "invalid autoscaler scale up stablization window - >3600",
933967
otelcol: v1beta1.OpenTelemetryCollector{
934968
Spec: v1beta1.OpenTelemetryCollectorSpec{
935969
Autoscaler: &v1beta1.AutoscalerSpec{
936970
MaxReplicas: &three,
937971
Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{
938972
ScaleUp: &autoscalingv2.HPAScalingRules{
939-
StabilizationWindowSeconds: &zero,
973+
StabilizationWindowSeconds: &maxInt,
940974
},
941975
},
942976
},
943977
},
944978
},
945-
expectedErr: "scaleUp should be one or more",
979+
expectedErr: "scaleUp.stabilizationWindowSeconds should be >=0 and <=3600",
946980
},
947981
{
948982
name: "invalid autoscaler target cpu utilization",

0 commit comments

Comments
 (0)