From 84ffa49104e1076c6a1f14ebae71eeae8d07454a Mon Sep 17 00:00:00 2001 From: Matt Hagenbuch Date: Fri, 10 May 2024 15:05:35 -0400 Subject: [PATCH] rename func, name label --- controllers/builder_test.go | 10 +++++----- controllers/opentelemetrycollector_controller.go | 6 +++--- internal/manifests/collector/configmap.go | 3 ++- internal/manifests/collector/configmap_test.go | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 2f612e2108..209f739c29 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -234,7 +234,7 @@ service: "app.kubernetes.io/component": "opentelemetry-collector", "app.kubernetes.io/instance": "test.test", "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-collector-" + goodConfigHash, + "app.kubernetes.io/name": "test-collector", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", }, @@ -481,7 +481,7 @@ service: "app.kubernetes.io/component": "opentelemetry-collector", "app.kubernetes.io/instance": "test.test", "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-collector-" + goodConfigHash, + "app.kubernetes.io/name": "test-collector", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", }, @@ -764,7 +764,7 @@ service: "app.kubernetes.io/component": "opentelemetry-collector", "app.kubernetes.io/instance": "test.test", "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-collector-" + goodConfigHash, + "app.kubernetes.io/name": "test-collector", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", }, @@ -1290,7 +1290,7 @@ service: "app.kubernetes.io/component": "opentelemetry-collector", "app.kubernetes.io/instance": "test.test", "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-collector-" + goodConfigHash, + "app.kubernetes.io/name": "test-collector", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", }, @@ -1684,7 +1684,7 @@ prometheus_cr: "app.kubernetes.io/component": "opentelemetry-collector", "app.kubernetes.io/instance": "test.test", "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-collector-" + goodConfigHash, + "app.kubernetes.io/name": "test-collector", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", }, diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index eaf46f2cf0..ca232e3558 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -134,7 +134,7 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont if err != nil { return nil, fmt.Errorf("error listing ConfigMaps: %w", err) } - ownedConfigMaps := r.getConfigMapsToReconcile(params.OtelCol.Spec.ConfigVersions, configMapList) + ownedConfigMaps := r.getConfigMapsToRemove(params.OtelCol.Spec.ConfigVersions, configMapList) for i := range ownedConfigMaps { ownedObjects[ownedConfigMaps[i].GetUID()] = &ownedConfigMaps[i] } @@ -142,9 +142,9 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont return ownedObjects, nil } -// getConfigMapsToReconcile returns a list of ConfigMaps to reconcile based on the number of ConfigMaps to keep. +// getConfigMapsToRemove returns a list of ConfigMaps to remove based on the number of ConfigMaps to keep. // It keeps the newest ConfigMap, the `configVersionsToKeep` next newest ConfigMaps, and returns the remainder. -func (r *OpenTelemetryCollectorReconciler) getConfigMapsToReconcile(configVersionsToKeep int, configMapList *corev1.ConfigMapList) []corev1.ConfigMap { +func (r *OpenTelemetryCollectorReconciler) getConfigMapsToRemove(configVersionsToKeep int, configMapList *corev1.ConfigMapList) []corev1.ConfigMap { ownedConfigMaps := []corev1.ConfigMap{} sort.Slice(configMapList.Items, func(i, j int) bool { iTime := configMapList.Items[i].GetCreationTimestamp().Time diff --git a/internal/manifests/collector/configmap.go b/internal/manifests/collector/configmap.go index 137232683d..74f90f28d5 100644 --- a/internal/manifests/collector/configmap.go +++ b/internal/manifests/collector/configmap.go @@ -29,7 +29,8 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) { return nil, err } name := naming.ConfigMap(params.OtelCol.Name, hash) - labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{}) + collectorName := naming.Collector(params.OtelCol.Name) + labels := manifestutils.Labels(params.OtelCol.ObjectMeta, collectorName, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{}) replacedConf, err := ReplaceConfig(params.OtelCol) if err != nil { diff --git a/internal/manifests/collector/configmap_test.go b/internal/manifests/collector/configmap_test.go index 2555666bce..d1c2f91001 100644 --- a/internal/manifests/collector/configmap_test.go +++ b/internal/manifests/collector/configmap_test.go @@ -61,7 +61,7 @@ service: expectedName := naming.ConfigMap("test", hash) expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector" - expectedLables["app.kubernetes.io/name"] = expectedName + expectedLables["app.kubernetes.io/name"] = "test-collector" expectedLables["app.kubernetes.io/version"] = "0.47.0" actual, err := ConfigMap(param) @@ -104,7 +104,7 @@ service: expectedName := naming.ConfigMap("test", hash) expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector" - expectedLables["app.kubernetes.io/name"] = expectedName + expectedLables["app.kubernetes.io/name"] = "test-collector" expectedLables["app.kubernetes.io/version"] = "latest" param.OtelCol.Spec.TargetAllocator.Enabled = true