@@ -30,7 +30,9 @@ import (
30
30
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
31
31
32
32
"github.com/open-telemetry/opentelemetry-operator/internal/config"
33
+ ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
33
34
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
35
+ "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
34
36
)
35
37
36
38
var (
@@ -357,28 +359,27 @@ func (c CollectorWebhook) validateTargetAllocatorConfig(ctx context.Context, r *
357
359
if r .Spec .TargetAllocator .AllocationStrategy == OpenTelemetryTargetAllocatorAllocationStrategyPerNode && r .Spec .Mode != ModeDaemonSet {
358
360
return nil , fmt .Errorf ("target allocation strategy %s is only supported in OpenTelemetry Collector mode %s" , OpenTelemetryTargetAllocatorAllocationStrategyPerNode , ModeDaemonSet )
359
361
}
360
- // TODO: Fix cycle
361
- //// validate Prometheus config for target allocation
362
- //promCfg, err := ta.ConfigToPromConfig(r.Spec.Config)
363
- //if err != nil {
364
- // return nil, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err)
365
- //}
366
- //err = ta.ValidatePromConfig(promCfg, r.Spec.TargetAllocator.Enabled, featuregate.EnableTargetAllocatorRewrite.IsEnabled())
367
- //if err != nil {
368
- // return nil, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err)
369
- //}
370
- //err = ta.ValidateTargetAllocatorConfig(r.Spec.TargetAllocator.PrometheusCR.Enabled, promCfg)
371
- //if err != nil {
372
- // return nil, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err)
373
- //}
374
- //// if the prometheusCR is enabled, it needs a suite of permissions to function
375
- //if r.Spec.TargetAllocator.PrometheusCR.Enabled {
376
- // if subjectAccessReviews, err := c.reviewer.CheckPolicyRules(ctx, r.GetNamespace(), r.Spec.TargetAllocator.ServiceAccount, targetAllocatorCRPolicyRules...); err != nil {
377
- // return nil, fmt.Errorf("unable to check rbac rules %w", err)
378
- // } else if allowed, deniedReviews := rbac.AllSubjectAccessReviewsAllowed(subjectAccessReviews); !allowed {
379
- // return warningsGroupedByResource(deniedReviews), nil
380
- // }
381
- //}
362
+ // validate Prometheus config for target allocation
363
+ promCfg , err := ta .ConfigToPromConfig (r .Spec .Config )
364
+ if err != nil {
365
+ return nil , fmt .Errorf ("the OpenTelemetry Spec Prometheus configuration is incorrect, %w" , err )
366
+ }
367
+ err = ta .ValidatePromConfig (promCfg , r .Spec .TargetAllocator .Enabled , featuregate .EnableTargetAllocatorRewrite .IsEnabled ())
368
+ if err != nil {
369
+ return nil , fmt .Errorf ("the OpenTelemetry Spec Prometheus configuration is incorrect, %w" , err )
370
+ }
371
+ err = ta .ValidateTargetAllocatorConfig (r .Spec .TargetAllocator .PrometheusCR .Enabled , promCfg )
372
+ if err != nil {
373
+ return nil , fmt .Errorf ("the OpenTelemetry Spec Prometheus configuration is incorrect, %w" , err )
374
+ }
375
+ // if the prometheusCR is enabled, it needs a suite of permissions to function
376
+ if r .Spec .TargetAllocator .PrometheusCR .Enabled {
377
+ if subjectAccessReviews , err := c .reviewer .CheckPolicyRules (ctx , r .GetNamespace (), r .Spec .TargetAllocator .ServiceAccount , targetAllocatorCRPolicyRules ... ); err != nil {
378
+ return nil , fmt .Errorf ("unable to check rbac rules %w" , err )
379
+ } else if allowed , deniedReviews := rbac .AllSubjectAccessReviewsAllowed (subjectAccessReviews ); ! allowed {
380
+ return warningsGroupedByResource (deniedReviews ), nil
381
+ }
382
+ }
382
383
383
384
return nil , nil
384
385
}
0 commit comments