Skip to content

Commit 6acd9b6

Browse files
author
Israel Blancas
committed
Show an admission warning
Signed-off-by: Israel Blancas <[email protected]>
1 parent c3908f1 commit 6acd9b6

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

internal/manifests/collector/collector.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
package collector
1616

1717
import (
18+
"errors"
19+
"fmt"
20+
1821
"sigs.k8s.io/controller-runtime/pkg/client"
1922

2023
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
@@ -81,7 +84,7 @@ func Build(params manifests.Params) ([]client.Object, error) {
8184
}
8285
}
8386

84-
if params.Config.CreateRBACPermissions() == rbac.NotAvailable && params.Reviewer != nil {
87+
if params.ErrorAsWarning && params.Config.CreateRBACPermissions() == rbac.NotAvailable && params.Reviewer != nil {
8588
saName := params.OtelCol.Spec.ServiceAccount
8689
if saName == "" {
8790
sa, err := manifests.Factory(ServiceAccount)(params)
@@ -92,13 +95,14 @@ func Build(params manifests.Params) ([]client.Object, error) {
9295
}
9396
warnings, err := CheckRbacRules(params, saName)
9497
if err != nil {
95-
params.Log.Error(err, "Error checking RBAC rules", "serviceAccount", saName)
98+
return nil, fmt.Errorf("error checking RBAC rules for serviceAccount %s: %w", saName, err)
9699
}
97100

101+
var w []error
98102
for _, warning := range warnings {
99-
params.Log.V(1).Info("RBAC rules are missing", "warning", warning, "serviceAccount", saName)
103+
w = append(w, fmt.Errorf("RBAC rules are missing: %s", warning))
100104
}
101-
105+
return nil, errors.Join(w...)
102106
}
103107

104108
routes, err := Routes(params)

internal/manifests/params.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ type Params struct {
3737
OpAMPBridge v1alpha1.OpAMPBridge
3838
Config config.Config
3939
Reviewer *rbac.Reviewer
40+
ErrorAsWarning bool
4041
}

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ func main() {
457457
warnings = append(warnings, newErr.Error())
458458
return warnings
459459
}
460+
461+
params.ErrorAsWarning = true
460462
_, newErr = collectorManifests.Build(params)
461463
if newErr != nil {
462464
warnings = append(warnings, newErr.Error())

0 commit comments

Comments
 (0)