Skip to content

Commit

Permalink
changing to warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
taniyourstruly committed Jul 30, 2024
1 parent 1f420d8 commit 0eae73d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
6 changes: 3 additions & 3 deletions apis/v1beta1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 15 additions & 9 deletions apis/v1beta1/collector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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 {
Expand Down Expand Up @@ -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"),
Expand All @@ -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 {
Expand Down Expand Up @@ -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"),
Expand All @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0eae73d

Please sign in to comment.