Skip to content
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

feat: configmap, rbac, service, serviceaccount apply annotations-filter #3163

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/3151-feat-annotations-filter.yaml
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: "Configmap, rbac, service, serviceaccount apply annotations-filter."

# One or more tracking issues related to the change
issues: [3151]

# (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:
86 changes: 54 additions & 32 deletions controllers/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ service:
},
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
"prometheus.io/path": "/metrics",
"prometheus.io/port": "8888",
"prometheus.io/scrape": "true",
},
},
Spec: appsv1.DeploymentSpec{
Expand Down Expand Up @@ -239,7 +236,9 @@ service:
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "latest",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Data: map[string]string{
"collector.yaml": "receivers:\n examplereceiver:\n endpoint: 0.0.0.0:12345\nexporters:\n logging: null\nservice:\n pipelines:\n metrics:\n exporters:\n - logging\n receivers:\n - examplereceiver\n",
Expand All @@ -257,7 +256,9 @@ service:
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "latest",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
},
&corev1.Service{
Expand All @@ -273,7 +274,9 @@ service:
"app.kubernetes.io/version": "latest",
"operator.opentelemetry.io/collector-service-type": "base",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
Expand Down Expand Up @@ -302,6 +305,7 @@ service:
},
Annotations: map[string]string{
"service.beta.openshift.io/serving-cert-secret-name": "test-collector-headless-tls",
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -330,7 +334,9 @@ service:
"operator.opentelemetry.io/collector-service-type": "monitoring",
"operator.opentelemetry.io/collector-monitoring-service": "Exists",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
Expand Down Expand Up @@ -386,9 +392,6 @@ service:
},
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
"prometheus.io/path": "/metrics",
"prometheus.io/port": "8888",
"prometheus.io/scrape": "true",
},
},
Spec: appsv1.DeploymentSpec{
Expand Down Expand Up @@ -490,7 +493,9 @@ service:
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "latest",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Data: map[string]string{
"collector.yaml": "receivers:\n examplereceiver:\n endpoint: 0.0.0.0:12345\nexporters:\n logging: null\nservice:\n pipelines:\n metrics:\n exporters:\n - logging\n receivers:\n - examplereceiver\n",
Expand All @@ -508,7 +513,9 @@ service:
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "latest",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
},
&corev1.Service{
Expand All @@ -524,7 +531,9 @@ service:
"app.kubernetes.io/version": "latest",
"operator.opentelemetry.io/collector-service-type": "base",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
Expand Down Expand Up @@ -553,6 +562,7 @@ service:
},
Annotations: map[string]string{
"service.beta.openshift.io/serving-cert-secret-name": "test-collector-headless-tls",
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -581,7 +591,9 @@ service:
"operator.opentelemetry.io/collector-service-type": "monitoring",
"operator.opentelemetry.io/collector-monitoring-service": "Exists",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
Expand Down Expand Up @@ -673,9 +685,6 @@ service:
},
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
"prometheus.io/path": "/metrics",
"prometheus.io/port": "8888",
"prometheus.io/scrape": "true",
},
},
Spec: appsv1.DeploymentSpec{
Expand Down Expand Up @@ -777,7 +786,9 @@ service:
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "latest",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Data: map[string]string{
"collector.yaml": "receivers:\n examplereceiver:\n endpoint: 0.0.0.0:12345\nexporters:\n logging: null\nservice:\n pipelines:\n metrics:\n exporters:\n - logging\n receivers:\n - examplereceiver\n",
Expand All @@ -796,7 +807,9 @@ service:
"app.kubernetes.io/version": "latest",
"operator.opentelemetry.io/collector-service-type": "base",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
Expand Down Expand Up @@ -825,6 +838,7 @@ service:
},
Annotations: map[string]string{
"service.beta.openshift.io/serving-cert-secret-name": "test-collector-headless-tls",
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -853,7 +867,9 @@ service:
"operator.opentelemetry.io/collector-service-type": "monitoring",
"operator.opentelemetry.io/collector-monitoring-service": "Exists",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
Expand Down Expand Up @@ -1203,9 +1219,6 @@ service:
},
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
"prometheus.io/path": "/metrics",
"prometheus.io/port": "8888",
"prometheus.io/scrape": "true",
},
},
Spec: appsv1.StatefulSetSpec{
Expand Down Expand Up @@ -1308,7 +1321,9 @@ service:
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "latest",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
},
},
Data: map[string]string{
"collector.yaml": "exporters:\n logging: null\nreceivers:\n prometheus:\n config: {}\n target_allocator:\n collector_id: ${POD_NAME}\n endpoint: http://test-targetallocator:80\n interval: 30s\nservice:\n pipelines:\n metrics:\n exporters:\n - logging\n receivers:\n - prometheus\n",
Expand All @@ -1326,7 +1341,9 @@ service:
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "latest",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
},
},
},
&corev1.Service{
Expand All @@ -1343,7 +1360,9 @@ service:
"operator.opentelemetry.io/collector-service-type": "monitoring",
"operator.opentelemetry.io/collector-monitoring-service": "Exists",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
Expand Down Expand Up @@ -1599,9 +1618,6 @@ prometheus_cr:
},
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
"prometheus.io/path": "/metrics",
"prometheus.io/port": "8888",
"prometheus.io/scrape": "true",
},
},
Spec: appsv1.StatefulSetSpec{
Expand Down Expand Up @@ -1704,7 +1720,9 @@ prometheus_cr:
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "latest",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
},
},
Data: map[string]string{
"collector.yaml": "exporters:\n logging: null\nreceivers:\n prometheus:\n config: {}\n target_allocator:\n collector_id: ${POD_NAME}\n endpoint: http://test-targetallocator:80\n interval: 30s\nservice:\n pipelines:\n metrics:\n exporters:\n - logging\n receivers:\n - prometheus\n",
Expand All @@ -1722,7 +1740,9 @@ prometheus_cr:
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/version": "latest",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
},
},
},
&corev1.Service{
Expand All @@ -1739,7 +1759,9 @@ prometheus_cr:
"operator.opentelemetry.io/collector-service-type": "monitoring",
"operator.opentelemetry.io/collector-monitoring-service": "Exists",
},
Annotations: nil,
Annotations: map[string]string{
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
Expand Down
12 changes: 10 additions & 2 deletions controllers/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
exists, err = populateObjectIfExists(t, sa, namespacedObjectName(naming.ServiceAccount(params.Name), params.Namespace))
assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, map[string]string{annotationName: "true"}, sa.Annotations)
assert.Equal(t, map[string]string{
annotationName: "true",
"opentelemetry-operator-config/sha256": "11d309a64c15c034827053656adb6be67c0885d11092dc63c976a65328bbbbe1",
}, sa.Annotations)
saPatch := sa.DeepCopy()
saPatch.Annotations["user-defined-annotation"] = "value"
err = k8sClient.Patch(ctx, saPatch, client.MergeFrom(sa))
Expand Down Expand Up @@ -213,7 +216,12 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
exists, err = populateObjectIfExists(t, sa, namespacedObjectName(naming.ServiceAccount(params.Name), params.Namespace))
assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, map[string]string{annotationName: "true", "user-defined-annotation": "value", "new-annotation": "new-value"}, sa.Annotations)
assert.Equal(t, map[string]string{
annotationName: "true",
"user-defined-annotation": "value",
"new-annotation": "new-value",
"opentelemetry-operator-config/sha256": "11d309a64c15c034827053656adb6be67c0885d11092dc63c976a65328bbbbe1",
}, sa.Annotations)
},
},
wantErr: assert.NoError,
Expand Down
7 changes: 6 additions & 1 deletion internal/manifests/collector/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
collectorName := naming.Collector(params.OtelCol.Name)
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, collectorName, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{})

annotations, err := manifestutils.Annotations(params.OtelCol, params.Config.AnnotationsFilter())
if err != nil {
return nil, err
}

replacedConf, err := ReplaceConfig(params.OtelCol, params.TargetAllocator)
if err != nil {
params.Log.V(2).Info("failed to update prometheus config to use sharded targets: ", "err", err)
Expand All @@ -43,7 +48,7 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
Name: name,
Namespace: params.OtelCol.Namespace,
Labels: labels,
Annotations: params.OtelCol.Annotations,
Annotations: annotations,
},
Data: map[string]string{
"collector.yaml": replacedConf,
Expand Down
17 changes: 7 additions & 10 deletions internal/manifests/collector/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ func TestDaemonSetNewDefault(t *testing.T) {
// verify
assert.Equal(t, "my-instance-collector", d.Name)
assert.Equal(t, "my-instance-collector", d.Labels["app.kubernetes.io/name"])
assert.Equal(t, "true", d.Annotations["prometheus.io/scrape"])
assert.Equal(t, "8888", d.Annotations["prometheus.io/port"])
assert.Equal(t, "/metrics", d.Annotations["prometheus.io/path"])
jaronoff97 marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, testTolerationValues, d.Spec.Template.Spec.Tolerations)

assert.Len(t, d.Spec.Template.Spec.Containers, 1)
Expand Down Expand Up @@ -269,7 +266,7 @@ func TestDaemonsetFilterAnnotations(t *testing.T) {
d, err := DaemonSet(params)
require.NoError(t, err)

assert.Len(t, d.ObjectMeta.Annotations, 4)
assert.Len(t, d.ObjectMeta.Annotations, 1)
for k := range excludedAnnotations {
assert.NotContains(t, d.ObjectMeta.Annotations, k)
}
Expand Down Expand Up @@ -443,9 +440,9 @@ func TestDaemonSetInitContainer(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "my-instance-collector", d.Name)
assert.Equal(t, "my-instance-collector", d.Labels["app.kubernetes.io/name"])
assert.Equal(t, "true", d.Annotations["prometheus.io/scrape"])
assert.Equal(t, "8888", d.Annotations["prometheus.io/port"])
assert.Equal(t, "/metrics", d.Annotations["prometheus.io/path"])
assert.Equal(t, "true", d.Spec.Template.Annotations["prometheus.io/scrape"])
assert.Equal(t, "8888", d.Spec.Template.Annotations["prometheus.io/port"])
assert.Equal(t, "/metrics", d.Spec.Template.Annotations["prometheus.io/path"])
assert.Len(t, d.Spec.Template.Spec.InitContainers, 1)
}

Expand Down Expand Up @@ -479,9 +476,9 @@ func TestDaemonSetAdditionalContainer(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "my-instance-collector", d.Name)
assert.Equal(t, "my-instance-collector", d.Labels["app.kubernetes.io/name"])
assert.Equal(t, "true", d.Annotations["prometheus.io/scrape"])
assert.Equal(t, "8888", d.Annotations["prometheus.io/port"])
assert.Equal(t, "/metrics", d.Annotations["prometheus.io/path"])
assert.Equal(t, "true", d.Spec.Template.Annotations["prometheus.io/scrape"])
assert.Equal(t, "8888", d.Spec.Template.Annotations["prometheus.io/port"])
assert.Equal(t, "/metrics", d.Spec.Template.Annotations["prometheus.io/path"])
assert.Len(t, d.Spec.Template.Spec.Containers, 2)
assert.Equal(t, v1.Container{Name: "test"}, d.Spec.Template.Spec.Containers[0])
}
Expand Down
Loading
Loading