diff --git a/apis/v1beta1/collector_webhook.go b/apis/v1beta1/collector_webhook.go index dba9770ba5..9d89912ee9 100644 --- a/apis/v1beta1/collector_webhook.go +++ b/apis/v1beta1/collector_webhook.go @@ -177,7 +177,7 @@ func (c CollectorWebhook) ValidateCreate(ctx context.Context, obj runtime.Object c.metrics.create(ctx, otelcol) } if c.bv != nil { - newWarnings, err := c.bv(*otelcol) + newWarnings := c.bv(*otelcol) if err != nil { return append(warnings, newWarnings...), err } @@ -207,7 +207,7 @@ func (c CollectorWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj run } if c.bv != nil { - newWarnings, err := c.bv(*otelcol) + newWarnings := c.bv(*otelcol) if err != nil { return append(warnings, newWarnings...), err } @@ -469,7 +469,7 @@ func checkAutoscalerSpec(autoscaler *AutoscalerSpec) error { } // BuildValidator is mostly used for testing purposes -type BuildValidator func(c OpenTelemetryCollector) (admission.Warnings, error) +type BuildValidator func(c OpenTelemetryCollector) admission.Warnings func NewCollectorWebhook( logger logr.Logger, diff --git a/apis/v1beta1/collector_webhook_test.go b/apis/v1beta1/collector_webhook_test.go index e686b46304..e795d2a691 100644 --- a/apis/v1beta1/collector_webhook_test.go +++ b/apis/v1beta1/collector_webhook_test.go @@ -99,7 +99,8 @@ func TestValidate(t *testing.T) { }, } - bv := func(collector v1beta1.OpenTelemetryCollector) (admission.Warnings, error) { + bv := func(collector v1beta1.OpenTelemetryCollector) admission.Warnings { + var warnings admission.Warnings cfg := config.New( config.WithCollectorImage("default-collector"), config.WithTargetAllocatorImage("default-ta-allocator"), @@ -111,9 +112,10 @@ func TestValidate(t *testing.T) { } _, err := collectorManifests.Build(params) if err != nil { - return nil, err + warnings := append(warnings, err.Error()) + return warnings } - return nil, nil + return nil } for _, tt := range tests { @@ -546,7 +548,8 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, } - bv := func(collector v1beta1.OpenTelemetryCollector) (admission.Warnings, error) { + bv := func(collector v1beta1.OpenTelemetryCollector) admission.Warnings { + var warnings admission.Warnings cfg := config.New( config.WithCollectorImage("default-collector"), config.WithTargetAllocatorImage("default-ta-allocator"), @@ -558,9 +561,10 @@ func TestCollectorDefaultingWebhook(t *testing.T) { } _, err := collectorManifests.Build(params) if err != nil { - return nil, err + warnings := append(warnings, err.Error()) + return warnings } - return nil, nil + return nil } for _, test := range tests { @@ -1311,7 +1315,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, } - bv := func(collector v1beta1.OpenTelemetryCollector) (admission.Warnings, error) { + bv := func(collector v1beta1.OpenTelemetryCollector) admission.Warnings { + var warnings admission.Warnings cfg := config.New( config.WithCollectorImage("default-collector"), config.WithTargetAllocatorImage("default-ta-allocator"), @@ -1323,9 +1328,10 @@ func TestOTELColValidatingWebhook(t *testing.T) { } _, err := collectorManifests.Build(params) if err != nil { - return nil, err + warnings := append(warnings, err.Error()) + return warnings } - return nil, nil + return nil } for _, test := range tests { diff --git a/main.go b/main.go index 0e98cf7aea..3e7abc8bb4 100644 --- a/main.go +++ b/main.go @@ -394,16 +394,19 @@ func main() { } - bv := func(collector otelv1beta1.OpenTelemetryCollector) (admission.Warnings, error) { + bv := func(collector otelv1beta1.OpenTelemetryCollector) admission.Warnings { + var warnings admission.Warnings params, err := collectorReconciler.GetParams(collector) if err != nil { - return nil, err + warnings = append(warnings, err.Error()) + return warnings } _, err = collectorManifests.Build(params) if err != nil { - return nil, err + warnings = append(warnings, err.Error()) + return warnings } - return nil, nil + return warnings } if err = otelv1beta1.SetupCollectorWebhook(mgr, cfg, reviewer, crdMetrics, bv); err != nil {