From 93d8131482ddadcd7a75ffc2f6d3bc49387ccf67 Mon Sep 17 00:00:00 2001 From: Sergei Semenchuk Date: Sun, 27 Feb 2022 09:47:18 +0000 Subject: [PATCH] add validation for autoscale Signed-off-by: Sergei Semenchuk --- apis/v1alpha1/opentelemetrycollector_webhook.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apis/v1alpha1/opentelemetrycollector_webhook.go b/apis/v1alpha1/opentelemetrycollector_webhook.go index a531b059dc..f5998d9b6c 100644 --- a/apis/v1alpha1/opentelemetrycollector_webhook.go +++ b/apis/v1alpha1/opentelemetrycollector_webhook.go @@ -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 }