Skip to content

Commit 94b336e

Browse files
committed
Validate mode and strategy
Signed-off-by: Matej Gera <[email protected]>
1 parent 6d08c78 commit 94b336e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

apis/v1alpha1/collector_webhook.go

+4
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ func (c CollectorWebhook) validate(r *OpenTelemetryCollector) (admission.Warning
200200
return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the target allocation deployment", r.Spec.Mode)
201201
}
202202

203+
if r.Spec.TargetAllocator.Enabled && (r.Spec.Mode == ModeDaemonSet && r.Spec.TargetAllocator.AllocationStrategy != OpenTelemetryTargetAllocatorAllocationStrategyPerNode) {
204+
return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which must be used with target allocation strategy %s ", r.Spec.Mode, OpenTelemetryTargetAllocatorAllocationStrategyPerNode)
205+
}
206+
203207
if r.Spec.TargetAllocator.AllocationStrategy == OpenTelemetryTargetAllocatorAllocationStrategyPerNode && r.Spec.Mode != ModeDaemonSet {
204208
return warnings, fmt.Errorf("target allocation strategy %s is only supported in OpenTelemetry Collector mode %s", OpenTelemetryTargetAllocatorAllocationStrategyPerNode, ModeDaemonSet)
205209
}

apis/v1alpha1/collector_webhook_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,19 @@ func TestOTELColValidatingWebhook(t *testing.T) {
539539
},
540540
expectedErr: "the OpenTelemetry Spec Prometheus configuration is incorrect",
541541
},
542+
{
543+
name: "invalid target allocation strategy",
544+
otelcol: OpenTelemetryCollector{
545+
Spec: OpenTelemetryCollectorSpec{
546+
Mode: ModeDaemonSet,
547+
TargetAllocator: OpenTelemetryTargetAllocator{
548+
Enabled: true,
549+
AllocationStrategy: OpenTelemetryTargetAllocatorAllocationStrategyLeastWeighted,
550+
},
551+
},
552+
},
553+
expectedErr: "does not support the target allocation deployment",
554+
},
542555
{
543556
name: "invalid port name",
544557
otelcol: OpenTelemetryCollector{

0 commit comments

Comments
 (0)