Skip to content

Commit f31ce5b

Browse files
author
Kristina Pathak
authored
Add missing nil checks in collector validating webhook (open-telemetry#1136)
* add missing nil checks in validating webhook * fix imports
1 parent a180bac commit f31ce5b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

apis/v1alpha1/opentelemetrycollector_webhook.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error {
134134
// validate autoscale with horizontal pod autoscaler
135135
if r.Spec.MaxReplicas != nil {
136136
if *r.Spec.MaxReplicas < int32(1) {
137-
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, maxReplicas should be defined and more than one")
137+
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, maxReplicas should be defined and one or more")
138138
}
139139

140140
if r.Spec.Replicas != nil && *r.Spec.Replicas > *r.Spec.MaxReplicas {
@@ -150,15 +150,17 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error {
150150
}
151151

152152
if r.Spec.Autoscaler != nil && r.Spec.Autoscaler.Behavior != nil {
153-
if r.Spec.Autoscaler.Behavior.ScaleDown != nil && *r.Spec.Autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds < int32(1) {
153+
if r.Spec.Autoscaler.Behavior.ScaleDown != nil && r.Spec.Autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds != nil &&
154+
*r.Spec.Autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds < int32(1) {
154155
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, scaleDown should be one or more")
155156
}
156157

157-
if r.Spec.Autoscaler.Behavior.ScaleUp != nil && *r.Spec.Autoscaler.Behavior.ScaleUp.StabilizationWindowSeconds < int32(1) {
158+
if r.Spec.Autoscaler.Behavior.ScaleUp != nil && r.Spec.Autoscaler.Behavior.ScaleUp.StabilizationWindowSeconds != nil &&
159+
*r.Spec.Autoscaler.Behavior.ScaleUp.StabilizationWindowSeconds < int32(1) {
158160
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, scaleUp should be one or more")
159161
}
160162
}
161-
if r.Spec.Autoscaler.TargetCPUUtilization != nil && (*r.Spec.Autoscaler.TargetCPUUtilization < int32(1) || *r.Spec.Autoscaler.TargetCPUUtilization > int32(99)) {
163+
if r.Spec.Autoscaler != nil && r.Spec.Autoscaler.TargetCPUUtilization != nil && (*r.Spec.Autoscaler.TargetCPUUtilization < int32(1) || *r.Spec.Autoscaler.TargetCPUUtilization > int32(99)) {
162164
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, targetCPUUtilization should be greater than 0 and less than 100")
163165
}
164166

apis/v1alpha1/opentelemetrycollector_webhook_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func TestOTELColValidatingWebhook(t *testing.T) {
241241
MaxReplicas: &zero,
242242
},
243243
},
244-
expectedErr: "maxReplicas should be defined and more than one",
244+
expectedErr: "maxReplicas should be defined and one or more",
245245
},
246246
{
247247
name: "invalid replicas, greater than max",

0 commit comments

Comments
 (0)