Skip to content

Commit

Permalink
add validation for autoscale
Browse files Browse the repository at this point in the history
Signed-off-by: Sergei Semenchuk <[email protected]>
  • Loading branch information
binjip978 committed Mar 3, 2022
1 parent 5600157 commit 93d8131
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,20 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error {
}
}

// validate autoscale with horizontal pod autoscaler
if r.Spec.Autoscale != nil && *r.Spec.Autoscale {
if r.Spec.Replicas != nil {
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, replicas should be nil")
}

if r.Spec.MaxReplicas == nil || *r.Spec.MaxReplicas < int32(1) {
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, maaxReplicas should be defined and more than one")
}

if r.Spec.MinReplicas != nil && *r.Spec.MinReplicas > *r.Spec.MaxReplicas {
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, minReplicas must not be greater than maxReplicas")
}
}

return nil
}

0 comments on commit 93d8131

Please sign in to comment.