-
Notifications
You must be signed in to change notification settings - Fork 473
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
Cleanup cluster roles and bindings #2938
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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: bug_fix | ||
|
||
# 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: Cleanup ClusterRoles and ClusterRoleBindings created by the operator | ||
|
||
# One or more tracking issues related to the change | ||
issues: [2938] | ||
|
||
# (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: The operator uses finalizer on the collector to run the cleanup |
This file contains 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 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 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 |
---|---|---|
|
@@ -73,14 +73,14 @@ var ( | |
type check[T any] func(t *testing.T, params T) | ||
|
||
func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | ||
jaronoff97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
addedMetadataDeployment := testCollectorWithMode(v1alpha1.ModeDeployment) | ||
addedMetadataDeployment := testCollectorWithMode("test-deployment", v1alpha1.ModeDeployment) | ||
addedMetadataDeployment.Labels = map[string]string{ | ||
labelName: labelVal, | ||
} | ||
addedMetadataDeployment.Annotations = map[string]string{ | ||
annotationName: annotationVal, | ||
} | ||
deploymentExtraPorts := testCollectorWithModeAndReplicas(v1alpha1.ModeDeployment, 3) | ||
deploymentExtraPorts := testCollectorWithModeAndReplicas("test-deployment", v1alpha1.ModeDeployment, 3) | ||
deploymentExtraPorts.Spec.Ports = append(deploymentExtraPorts.Spec.Ports, extraPorts) | ||
deploymentExtraPorts.Spec.DeploymentUpdateStrategy = appsv1.DeploymentStrategy{ | ||
RollingUpdate: &appsv1.RollingUpdateDeployment{ | ||
|
@@ -94,20 +94,20 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
}, | ||
}, | ||
} | ||
ingressParams := testCollectorAssertNoErr(t, "", testFileIngress) | ||
ingressParams := testCollectorAssertNoErr(t, "test-ingress", "", testFileIngress) | ||
ingressParams.Spec.Ingress.Type = "ingress" | ||
updatedIngressParams := testCollectorAssertNoErr(t, "", testFileIngress) | ||
updatedIngressParams := testCollectorAssertNoErr(t, "test-ingress", "", testFileIngress) | ||
updatedIngressParams.Spec.Ingress.Type = "ingress" | ||
updatedIngressParams.Spec.Ingress.Annotations = map[string]string{"blub": "blob"} | ||
updatedIngressParams.Spec.Ingress.Hostname = expectHostname | ||
routeParams := testCollectorAssertNoErr(t, "", testFileIngress) | ||
routeParams := testCollectorAssertNoErr(t, "test-route", "", testFileIngress) | ||
routeParams.Spec.Ingress.Type = v1alpha1.IngressTypeRoute | ||
routeParams.Spec.Ingress.Route.Termination = v1alpha1.TLSRouteTerminationTypeInsecure | ||
updatedRouteParams := testCollectorAssertNoErr(t, "", testFileIngress) | ||
updatedRouteParams := testCollectorAssertNoErr(t, "test-route", "", testFileIngress) | ||
updatedRouteParams.Spec.Ingress.Type = v1alpha1.IngressTypeRoute | ||
updatedRouteParams.Spec.Ingress.Route.Termination = v1alpha1.TLSRouteTerminationTypeInsecure | ||
updatedRouteParams.Spec.Ingress.Hostname = expectHostname | ||
deletedParams := testCollectorWithMode(v1alpha1.ModeDeployment) | ||
deletedParams := testCollectorWithMode("test2", v1alpha1.ModeDeployment) | ||
now := metav1.NewTime(time.Now()) | ||
deletedParams.DeletionTimestamp = &now | ||
|
||
|
@@ -158,7 +158,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
assert.True(t, exists) | ||
assert.Equal(t, svc.Spec.Selector, map[string]string{ | ||
"app.kubernetes.io/component": "opentelemetry-collector", | ||
"app.kubernetes.io/instance": "default.test", | ||
"app.kubernetes.io/instance": "default.test-deployment", | ||
"app.kubernetes.io/managed-by": "opentelemetry-operator", | ||
"app.kubernetes.io/part-of": "opentelemetry", | ||
}) | ||
|
@@ -192,7 +192,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
assert.Contains(t, actual.Spec.Ports, extraPorts.ServicePort) | ||
assert.Equal(t, actual.Spec.Selector, map[string]string{ | ||
"app.kubernetes.io/component": "opentelemetry-collector", | ||
"app.kubernetes.io/instance": "default.test", | ||
"app.kubernetes.io/instance": "default.test-deployment", | ||
"app.kubernetes.io/managed-by": "opentelemetry-operator", | ||
"app.kubernetes.io/part-of": "opentelemetry", | ||
}) | ||
|
@@ -206,7 +206,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
{ | ||
name: "invalid mode", | ||
args: args{ | ||
params: testCollectorWithMode("bad"), | ||
params: testCollectorWithMode("test-invalid", "bad"), | ||
updates: []v1alpha1.OpenTelemetryCollector{}, | ||
}, | ||
want: []want{ | ||
|
@@ -223,7 +223,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
{ | ||
name: "invalid prometheus configuration", | ||
args: args{ | ||
params: testCollectorAssertNoErr(t, baseTaImage, testFileIngress), | ||
params: testCollectorAssertNoErr(t, "test-invalid-prom", baseTaImage, testFileIngress), | ||
updates: []v1alpha1.OpenTelemetryCollector{}, | ||
}, | ||
want: []want{ | ||
|
@@ -285,7 +285,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
checks: []check[v1alpha1.OpenTelemetryCollector]{ | ||
func(t *testing.T, params v1alpha1.OpenTelemetryCollector) { | ||
got := routev1.Route{} | ||
nsn := types.NamespacedName{Namespace: params.Namespace, Name: "otlp-grpc-test-route"} | ||
nsn := types.NamespacedName{Namespace: params.Namespace, Name: "otlp-grpc-test-route-route"} | ||
exists, err := populateObjectIfExists(t, &got, nsn) | ||
assert.NoError(t, err) | ||
assert.True(t, exists) | ||
|
@@ -299,7 +299,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
checks: []check[v1alpha1.OpenTelemetryCollector]{ | ||
func(t *testing.T, params v1alpha1.OpenTelemetryCollector) { | ||
got := routev1.Route{} | ||
nsn := types.NamespacedName{Namespace: params.Namespace, Name: "otlp-grpc-test-route"} | ||
nsn := types.NamespacedName{Namespace: params.Namespace, Name: "otlp-grpc-test-route-route"} | ||
exists, err := populateObjectIfExists(t, &got, nsn) | ||
assert.NoError(t, err) | ||
assert.True(t, exists) | ||
|
@@ -396,7 +396,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
{ | ||
name: "daemonset collector", | ||
args: args{ | ||
params: testCollectorWithMode(v1alpha1.ModeDaemonSet), | ||
params: testCollectorWithMode("test-daemonset", v1alpha1.ModeDaemonSet), | ||
}, | ||
want: []want{ | ||
{ | ||
|
@@ -416,11 +416,11 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
{ | ||
name: "stateful should update collector with TA", | ||
args: args{ | ||
params: testCollectorWithMode(v1alpha1.ModeStatefulSet), | ||
params: testCollectorWithMode("test-stateful-ta", v1alpha1.ModeStatefulSet), | ||
updates: []v1alpha1.OpenTelemetryCollector{ | ||
testCollectorAssertNoErr(t, baseTaImage, promFile), | ||
testCollectorAssertNoErr(t, baseTaImage, updatedPromFile), | ||
testCollectorAssertNoErr(t, updatedTaImage, updatedPromFile), | ||
testCollectorAssertNoErr(t, "test-stateful-ta", baseTaImage, promFile), | ||
testCollectorAssertNoErr(t, "test-stateful-ta", baseTaImage, updatedPromFile), | ||
testCollectorAssertNoErr(t, "test-stateful-ta", updatedTaImage, updatedPromFile), | ||
}, | ||
}, | ||
want: []want{ | ||
|
@@ -463,13 +463,13 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { | |
exists, err = populateObjectIfExists(t, &v1.ServiceAccount{}, namespacedObjectName(naming.TargetAllocatorServiceAccount(params.Name), params.Namespace)) | ||
assert.NoError(t, err) | ||
assert.True(t, exists) | ||
promConfig, err := ta.ConfigToPromConfig(testCollectorAssertNoErr(t, baseTaImage, promFile).Spec.Config) | ||
promConfig, err := ta.ConfigToPromConfig(testCollectorAssertNoErr(t, "test-stateful-ta", baseTaImage, promFile).Spec.Config) | ||
assert.NoError(t, err) | ||
|
||
taConfig := make(map[interface{}]interface{}) | ||
taConfig["collector_selector"] = metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
"app.kubernetes.io/instance": "default.test", | ||
"app.kubernetes.io/instance": "default.test-stateful-ta", | ||
"app.kubernetes.io/managed-by": "opentelemetry-operator", | ||
"app.kubernetes.io/component": "opentelemetry-collector", | ||
"app.kubernetes.io/part-of": "opentelemetry", | ||
|
@@ -681,7 +681,7 @@ func TestOpAMPBridgeReconciler_Reconcile(t *testing.T) { | |
exists, err = populateObjectIfExists(t, &v1.Service{}, namespacedObjectName(naming.OpAMPBridgeService(params.Name), params.Namespace)) | ||
assert.NoError(t, err) | ||
assert.True(t, exists) | ||
exists, err = populateObjectIfExists(t, &v1.ServiceAccount{}, namespacedObjectName(naming.ServiceAccount(params.Name), params.Namespace)) | ||
exists, err = populateObjectIfExists(t, &v1.ServiceAccount{}, namespacedObjectName(naming.OpAMPBridgeServiceAccount(params.Name), params.Namespace)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was accidentally passing bc the SA was there from the previous test. |
||
assert.NoError(t, err) | ||
assert.True(t, exists) | ||
}, | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given we have to do this for a fair amount of resources now, I think it may be worth it to make this a generic method that works on [T client.Object]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be a list e.g. `[]metav1.List`` but then I am not able to get the UID for the map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may be able to
[]v1.Object
(from the metav1 package)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we cannot use the
client.List
and rely on labels like other methods in this file. Instead we would need to change toclient.Get
and pass as well the[] types.NamespacedName
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot make the method more generic and look simple