-
Notifications
You must be signed in to change notification settings - Fork 520
Add automatic RBAC creation for prometheus receiver #3459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iblancasa
wants to merge
9
commits into
open-telemetry:main
Choose a base branch
from
iblancasa:3078
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
551ed20
Add automatic RBAC creation for prometheus receiver
iblancasa 452f02f
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa 8c15d26
Fix labels
iblancasa f73b702
Merge branch 'main' into 3078
iblancasa c8bb8b5
Merge branch 'main' into 3078
iblancasa a66d50e
Merge branch 'main' into 3078
iblancasa 1d9e5e8
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
iblancasa 813e160
Fix ci
iblancasa 5ee5abf
Merge branch '3078' of github.com:iblancasa/opentelemetry-operator in…
iblancasa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) | ||
component: collector | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Create RBAC automatically for the Prometheus receiver | ||
|
||
# One or more tracking issues related to the change | ||
issues: [3078] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/tools/record" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
||
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" | ||
"github.com/open-telemetry/opentelemetry-operator/internal/config" | ||
) | ||
|
||
func TestReconcile(t *testing.T) { | ||
logger := zap.New() | ||
ctx := context.Background() | ||
|
||
scheme := runtime.NewScheme() | ||
require.NoError(t, v1beta1.AddToScheme(scheme)) | ||
require.NoError(t, corev1.AddToScheme(scheme)) | ||
|
||
tests := []struct { | ||
name string | ||
existingState []runtime.Object | ||
expectedResult ctrl.Result | ||
expectedError bool | ||
}{ | ||
{ | ||
name: "collector not found", | ||
existingState: []runtime.Object{}, | ||
expectedResult: ctrl.Result{}, | ||
expectedError: false, | ||
}, | ||
{ | ||
name: "unmanaged collector", | ||
existingState: []runtime.Object{ | ||
&v1beta1.OpenTelemetryCollector{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-collector", | ||
Namespace: "default", | ||
}, | ||
Spec: v1beta1.OpenTelemetryCollectorSpec{ | ||
OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ | ||
ManagementState: v1beta1.ManagementStateUnmanaged, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedResult: ctrl.Result{}, | ||
expectedError: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
client := fake.NewClientBuilder(). | ||
WithScheme(scheme). | ||
WithRuntimeObjects(tt.existingState...). | ||
Build() | ||
|
||
r := &OpenTelemetryCollectorReconciler{ | ||
Client: client, | ||
log: logger, | ||
scheme: scheme, | ||
config: config.New(), | ||
recorder: record.NewFakeRecorder(100), | ||
} | ||
|
||
result, err := r.Reconcile(ctx, ctrl.Request{}) | ||
|
||
if tt.expectedError { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
assert.Equal(t, tt.expectedResult, result) | ||
}) | ||
} | ||
} | ||
|
||
func TestNewReconciler(t *testing.T) { | ||
scheme := runtime.NewScheme() | ||
client := fake.NewClientBuilder().WithScheme(scheme).Build() | ||
recorder := record.NewFakeRecorder(100) | ||
logger := zap.New() | ||
cfg := config.New() | ||
|
||
params := Params{ | ||
Client: client, | ||
Recorder: recorder, | ||
Scheme: scheme, | ||
Log: logger, | ||
Config: cfg, | ||
} | ||
|
||
r := NewReconciler(params) | ||
|
||
assert.Equal(t, client, r.Client) | ||
assert.Equal(t, recorder, r.recorder) | ||
assert.Equal(t, scheme, r.scheme) | ||
assert.Equal(t, logger, r.log) | ||
assert.Equal(t, cfg, r.config) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.