Skip to content

Commit b548a41

Browse files
committed
Apply changes requested in code review
Signed-off-by: Israel Blancas <[email protected]>
1 parent 1213cd9 commit b548a41

File tree

10 files changed

+98
-30
lines changed

10 files changed

+98
-30
lines changed

controllers/suite_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import (
5656
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect"
5757
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
5858
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
59-
autoRbac "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
59+
autoRBAC "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
6060
"github.com/open-telemetry/opentelemetry-operator/internal/config"
6161
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
6262
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/testdata"
@@ -96,7 +96,7 @@ var _ autodetect.AutoDetect = (*mockAutoDetect)(nil)
9696
type mockAutoDetect struct {
9797
OpenShiftRoutesAvailabilityFunc func() (openshift.RoutesAvailability, error)
9898
PrometheusCRsAvailabilityFunc func() (prometheus.Availability, error)
99-
RBACPermissionsFunc func(ctx context.Context) (autoRbac.Availability, error)
99+
RBACPermissionsFunc func(ctx context.Context) (autoRBAC.Availability, error)
100100
}
101101

102102
func (m *mockAutoDetect) PrometheusCRsAvailability() (prometheus.Availability, error) {
@@ -113,11 +113,11 @@ func (m *mockAutoDetect) OpenShiftRoutesAvailability() (openshift.RoutesAvailabi
113113
return openshift.RoutesNotAvailable, nil
114114
}
115115

116-
func (m *mockAutoDetect) RBACPermissions(ctx context.Context) (autoRbac.Availability, error) {
116+
func (m *mockAutoDetect) RBACPermissions(ctx context.Context) (autoRBAC.Availability, error) {
117117
if m.RBACPermissionsFunc != nil {
118118
return m.RBACPermissionsFunc(ctx)
119119
}
120-
return autoRbac.NotAvailable, nil
120+
return autoRBAC.NotAvailable, nil
121121
}
122122

123123
func TestMain(m *testing.M) {

internal/autodetect/main.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
2626
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
27-
autoRbac "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
27+
autoRBAC "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
2828
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
2929
)
3030

@@ -34,7 +34,7 @@ var _ AutoDetect = (*autoDetect)(nil)
3434
type AutoDetect interface {
3535
OpenShiftRoutesAvailability() (openshift.RoutesAvailability, error)
3636
PrometheusCRsAvailability() (prometheus.Availability, error)
37-
RBACPermissions(ctx context.Context) (autoRbac.Availability, error)
37+
RBACPermissions(ctx context.Context) (autoRBAC.Availability, error)
3838
}
3939

4040
type autoDetect struct {
@@ -92,14 +92,14 @@ func (a *autoDetect) OpenShiftRoutesAvailability() (openshift.RoutesAvailability
9292
return openshift.RoutesNotAvailable, nil
9393
}
9494

95-
func (a *autoDetect) RBACPermissions(ctx context.Context) (autoRbac.Availability, error) {
96-
w, err := autoRbac.CheckRbacPermissions(ctx, a.reviewer)
95+
func (a *autoDetect) RBACPermissions(ctx context.Context) (autoRBAC.Availability, error) {
96+
w, err := autoRBAC.CheckRBACPermissions(ctx, a.reviewer)
9797
if err != nil {
98-
return autoRbac.NotAvailable, err
98+
return autoRBAC.NotAvailable, err
9999
}
100100
if w != nil {
101-
return autoRbac.NotAvailable, fmt.Errorf("missing permissions: %s", w)
101+
return autoRBAC.NotAvailable, fmt.Errorf("missing permissions: %s", w)
102102
}
103103

104-
return autoRbac.Available, nil
104+
return autoRBAC.Available, nil
105105
}

internal/autodetect/main_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect"
3636
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
3737
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
38-
autoRbac "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
38+
autoRBAC "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
3939
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
4040
)
4141

@@ -155,7 +155,7 @@ func TestDetectRBACPermissionsBasedOnAvailableClusterRoles(t *testing.T) {
155155

156156
for _, tt := range []struct {
157157
description string
158-
expectedAvailability autoRbac.Availability
158+
expectedAvailability autoRBAC.Availability
159159
shouldError bool
160160
namespace string
161161
serviceAccount string
@@ -165,7 +165,7 @@ func TestDetectRBACPermissionsBasedOnAvailableClusterRoles(t *testing.T) {
165165
description: "Not possible to read the namespace",
166166
namespace: "default",
167167
shouldError: true,
168-
expectedAvailability: autoRbac.NotAvailable,
168+
expectedAvailability: autoRBAC.NotAvailable,
169169
clientGenerator: reactorFactory(v1.SubjectAccessReviewStatus{
170170
Allowed: true,
171171
}),
@@ -187,7 +187,7 @@ func TestDetectRBACPermissionsBasedOnAvailableClusterRoles(t *testing.T) {
187187
clientGenerator: reactorFactory(v1.SubjectAccessReviewStatus{
188188
Allowed: false,
189189
}),
190-
expectedAvailability: autoRbac.NotAvailable,
190+
expectedAvailability: autoRBAC.NotAvailable,
191191
},
192192
{
193193
description: "RBAC resources are there",
@@ -198,13 +198,13 @@ func TestDetectRBACPermissionsBasedOnAvailableClusterRoles(t *testing.T) {
198198
clientGenerator: reactorFactory(v1.SubjectAccessReviewStatus{
199199
Allowed: true,
200200
}),
201-
expectedAvailability: autoRbac.Available,
201+
expectedAvailability: autoRBAC.Available,
202202
},
203203
} {
204204
t.Run(tt.description, func(t *testing.T) {
205205
// These settings can be get from env vars
206-
t.Setenv(autoRbac.NAMESPACE_ENV_VAR, tt.namespace)
207-
t.Setenv(autoRbac.SA_ENV_VAR, tt.serviceAccount)
206+
t.Setenv(autoRBAC.NAMESPACE_ENV_VAR, tt.namespace)
207+
t.Setenv(autoRBAC.SA_ENV_VAR, tt.serviceAccount)
208208

209209
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {}))
210210
defer server.Close()

internal/autodetect/rbac/check.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ func getOperatorServiceAccount() (string, error) {
5252
return sa, nil
5353
}
5454

55-
// CheckRbacPermissions checks if the operator has the needed permissions to create RBAC resources automatically.
55+
// CheckRBACPermissions checks if the operator has the needed permissions to create RBAC resources automatically.
5656
// If the RBAC is there, no errors nor warnings are returned.
57-
func CheckRbacPermissions(ctx context.Context, reviewer *rbac.Reviewer) (admission.Warnings, error) {
57+
func CheckRBACPermissions(ctx context.Context, reviewer *rbac.Reviewer) (admission.Warnings, error) {
5858
namespace, err := getOperatorNamespace()
5959
if err != nil {
6060
return nil, fmt.Errorf("%s: %w", "not possible to check RBAC rules", err)

internal/config/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect"
2626
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
2727
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
28-
autoRbac "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
28+
autoRBAC "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
2929
"github.com/open-telemetry/opentelemetry-operator/internal/version"
3030
)
3131

@@ -45,7 +45,7 @@ type Config struct {
4545
autoInstrumentationPythonImage string
4646
collectorImage string
4747
collectorConfigMapEntry string
48-
createRBACPermissions autoRbac.Availability
48+
createRBACPermissions autoRBAC.Availability
4949
enableMultiInstrumentation bool
5050
enableApacheHttpdInstrumentation bool
5151
enableDotNetInstrumentation bool
@@ -72,7 +72,7 @@ func New(opts ...Option) Config {
7272
o := options{
7373
prometheusCRAvailability: prometheus.NotAvailable,
7474
openshiftRoutesAvailability: openshift.RoutesNotAvailable,
75-
createRBACPermissions: autoRbac.NotAvailable,
75+
createRBACPermissions: autoRBAC.NotAvailable,
7676
collectorConfigMapEntry: defaultCollectorConfigMapEntry,
7777
targetAllocatorConfigMapEntry: defaultTargetAllocatorConfigMapEntry,
7878
operatorOpAMPBridgeConfigMapEntry: defaultOperatorOpAMPBridgeConfigMapEntry,
@@ -176,7 +176,7 @@ func (c *Config) CollectorConfigMapEntry() string {
176176
}
177177

178178
// CreateRBACPermissions is true when the operator can create RBAC permissions for SAs running a collector instance. Immutable.
179-
func (c *Config) CreateRBACPermissions() autoRbac.Availability {
179+
func (c *Config) CreateRBACPermissions() autoRBAC.Availability {
180180
return c.createRBACPermissions
181181
}
182182

internal/config/options.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect"
2424
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
2525
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
26-
autoRbac "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
26+
autoRBAC "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
2727
"github.com/open-telemetry/opentelemetry-operator/internal/version"
2828
)
2929

@@ -43,7 +43,7 @@ type options struct {
4343
autoInstrumentationNginxImage string
4444
collectorImage string
4545
collectorConfigMapEntry string
46-
createRBACPermissions autoRbac.Availability
46+
createRBACPermissions autoRBAC.Availability
4747
enableMultiInstrumentation bool
4848
enableApacheHttpdInstrumentation bool
4949
enableDotNetInstrumentation bool
@@ -184,7 +184,7 @@ func WithPrometheusCRAvailability(pcrd prometheus.Availability) Option {
184184
}
185185
}
186186

187-
func WithRBACPermissions(rAuto autoRbac.Availability) Option {
187+
func WithRBACPermissions(rAuto autoRBAC.Availability) Option {
188188
return func(o *options) {
189189
o.createRBACPermissions = rAuto
190190
}

tests/e2e-automatic-rbac/processor-k8sattributes/01-assert.yaml

+18-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,21 @@ rules:
1919
verbs:
2020
- get
2121
- watch
22-
- list
22+
- list
23+
---
24+
apiVersion: rbac.authorization.k8s.io/v1
25+
kind: ClusterRoleBinding
26+
metadata:
27+
labels:
28+
app.kubernetes.io/component: opentelemetry-collector
29+
app.kubernetes.io/instance: chainsaw-k8sattributes.simplest
30+
app.kubernetes.io/managed-by: opentelemetry-operator
31+
app.kubernetes.io/name: simplest-collector
32+
roleRef:
33+
apiGroup: rbac.authorization.k8s.io
34+
kind: ClusterRole
35+
name: simplest-chainsaw-resourcedetection-cluster-role
36+
subjects:
37+
- kind: ServiceAccount
38+
name: simplest-collector
39+
namespace: chainsaw-k8sattributes

tests/e2e-automatic-rbac/processor-k8sattributes/02-assert.yaml

+18-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,21 @@ rules:
1919
verbs:
2020
- get
2121
- watch
22-
- list
22+
- list
23+
---
24+
apiVersion: rbac.authorization.k8s.io/v1
25+
kind: ClusterRoleBinding
26+
metadata:
27+
labels:
28+
app.kubernetes.io/component: opentelemetry-collector
29+
app.kubernetes.io/instance: chainsaw-k8sattributes.simplest
30+
app.kubernetes.io/managed-by: opentelemetry-operator
31+
app.kubernetes.io/name: simplest-collector
32+
roleRef:
33+
apiGroup: rbac.authorization.k8s.io
34+
kind: ClusterRole
35+
name: simplest-chainsaw-resourcedetection-cluster-role
36+
subjects:
37+
- kind: ServiceAccount
38+
name: simplest-collector
39+
namespace: chainsaw-k8sattributes

tests/e2e-automatic-rbac/processor-resourcedetection/01-assert.yaml

+18-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,21 @@ rules:
1111
verbs:
1212
- get
1313
- watch
14-
- list
14+
- list
15+
---
16+
apiVersion: rbac.authorization.k8s.io/v1
17+
kind: ClusterRoleBinding
18+
metadata:
19+
labels:
20+
app.kubernetes.io/component: opentelemetry-collector
21+
app.kubernetes.io/instance: chainsaw-resourcedetection.simplest
22+
app.kubernetes.io/managed-by: opentelemetry-operator
23+
app.kubernetes.io/name: simplest-collector
24+
roleRef:
25+
apiGroup: rbac.authorization.k8s.io
26+
kind: ClusterRole
27+
name: simplest-chainsaw-resourcedetection-cluster-role
28+
subjects:
29+
- kind: ServiceAccount
30+
name: simplest-collector
31+
namespace: chainsaw-resourcedetection

tests/e2e-automatic-rbac/processor-resourcedetection/02-assert.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,20 @@ rules:
1010
verbs:
1111
- get
1212
- list
13+
---
14+
apiVersion: rbac.authorization.k8s.io/v1
15+
kind: ClusterRoleBinding
16+
metadata:
17+
labels:
18+
app.kubernetes.io/component: opentelemetry-collector
19+
app.kubernetes.io/instance: chainsaw-resourcedetection.simplest
20+
app.kubernetes.io/managed-by: opentelemetry-operator
21+
app.kubernetes.io/name: simplest-collector
22+
roleRef:
23+
apiGroup: rbac.authorization.k8s.io
24+
kind: ClusterRole
25+
name: simplest-chainsaw-resourcedetection-cluster-role
26+
subjects:
27+
- kind: ServiceAccount
28+
name: simplest-collector
29+
namespace: chainsaw-resourcedetection

0 commit comments

Comments
 (0)