From f2401fcab584ecdb1e60c99b8c7335459a6616c0 Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Fri, 6 Jun 2025 15:57:36 +0200
Subject: [PATCH 1/4] Fix OpenShift must-gather for target allocator CR
Signed-off-by: Pavol Loffay
---
.chloggen/fix-must-gather.yaml | 16 ++++++
cmd/gather/cluster/cluster.go | 49 ++++++++++++++++++-
cmd/gather/cluster/write.go | 5 +-
cmd/gather/main.go | 4 ++
.../must-gather/check_must_gather.sh | 1 +
5 files changed, 71 insertions(+), 4 deletions(-)
create mode 100644 .chloggen/fix-must-gather.yaml
diff --git a/.chloggen/fix-must-gather.yaml b/.chloggen/fix-must-gather.yaml
new file mode 100644
index 0000000000..4a9a078f17
--- /dev/null
+++ b/.chloggen/fix-must-gather.yaml
@@ -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: target allocator
+
+# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
+note: Fix OpenShift must-gather for Target Allocator
+
+# One or more tracking issues related to the change
+issues: []
+
+# (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:
diff --git a/cmd/gather/cluster/cluster.go b/cmd/gather/cluster/cluster.go
index b5567a6e84..7ed04d65be 100644
--- a/cmd/gather/cluster/cluster.go
+++ b/cmd/gather/cluster/cluster.go
@@ -248,6 +248,33 @@ func (c *Cluster) GetOpenTelemetryCollectors() error {
return nil
}
+func (c *Cluster) GetTargetAllocators() error {
+ tas := otelv1alpha1.TargetAllocatorList{}
+
+ err := c.config.KubernetesClient.List(context.TODO(), &tas)
+ if err != nil {
+ return err
+ }
+
+ log.Println("TargetAllocators found:", len(tas.Items))
+
+ errorDetected := false
+
+ for _, ta := range tas.Items {
+ otelTA := ta
+ err := c.processOTELTargetAllocator(&otelTA)
+ if err != nil {
+ log.Fatalln(err)
+ errorDetected = true
+ }
+ }
+
+ if errorDetected {
+ return fmt.Errorf("something failed while getting the targetallocators")
+ }
+ return nil
+}
+
func (c *Cluster) GetInstrumentations() error {
instrumentations := otelv1alpha1.InstrumentationList{}
@@ -281,7 +308,7 @@ func (c *Cluster) GetInstrumentations() error {
func (c *Cluster) processOTELCollector(otelCol *otelv1beta1.OpenTelemetryCollector) error {
log.Printf("Processing OpenTelemetryCollector %s/%s", otelCol.Namespace, otelCol.Name)
- folder, err := createOTELFolder(c.config.CollectionDir, otelCol)
+ folder, err := createOTELFolder(c.config.CollectionDir, otelCol.ObjectMeta)
if err != nil {
return err
}
@@ -295,11 +322,28 @@ func (c *Cluster) processOTELCollector(otelCol *otelv1beta1.OpenTelemetryCollect
return nil
}
+func (c *Cluster) processOTELTargetAllocator(ta *otelv1alpha1.TargetAllocator) error {
+ log.Printf("Processing TargetAllocator %s/%s", ta.Namespace, ta.Name)
+ folder, err := createOTELFolder(c.config.CollectionDir, ta.ObjectMeta)
+ if err != nil {
+ return err
+ }
+ writeToFile(folder, ta)
+
+ err = c.processOwnedResources(ta, folder)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
func (c *Cluster) processOwnedResources(owner interface{}, folder string) error {
resourceTypes := []struct {
list client.ObjectList
apiCheck func() bool
}{
+ {&otelv1alpha1.TargetAllocatorList{}, func() bool { return true }},
{&appsv1.DaemonSetList{}, func() bool { return true }},
{&appsv1.DeploymentList{}, func() bool { return true }},
{&appsv1.StatefulSetList{}, func() bool { return true }},
@@ -401,6 +445,9 @@ func hasOwnerReference(obj client.Object, owner interface{}) bool {
case *otelv1beta1.OpenTelemetryCollector:
ownerKind = o.Kind
ownerUID = o.UID
+ case *otelv1alpha1.TargetAllocator:
+ ownerKind = o.Kind
+ ownerUID = o.UID
default:
return false
}
diff --git a/cmd/gather/cluster/write.go b/cmd/gather/cluster/write.go
index 76cbb7264d..bf345679ff 100644
--- a/cmd/gather/cluster/write.go
+++ b/cmd/gather/cluster/write.go
@@ -14,16 +14,15 @@ import (
"strings"
corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
cgocorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
-
- "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
)
-func createOTELFolder(collectionDir string, otelCol *v1beta1.OpenTelemetryCollector) (string, error) {
+func createOTELFolder(collectionDir string, otelCol metav1.ObjectMeta) (string, error) {
outputDir := filepath.Join(collectionDir, "namespaces", otelCol.Namespace, otelCol.Name)
err := os.MkdirAll(outputDir, os.ModePerm)
if err != nil {
diff --git a/cmd/gather/main.go b/cmd/gather/main.go
index 8d0c401029..ab8d30afe4 100644
--- a/cmd/gather/main.go
+++ b/cmd/gather/main.go
@@ -68,6 +68,10 @@ func main() {
if err != nil {
log.Fatalln(err)
}
+ err = cluster.GetTargetAllocators()
+ if err != nil {
+ log.Fatalln(err)
+ }
err = cluster.GetInstrumentations()
if err != nil {
log.Fatalln(err)
diff --git a/tests/e2e-openshift/must-gather/check_must_gather.sh b/tests/e2e-openshift/must-gather/check_must_gather.sh
index 56221ebf11..ab16f17944 100755
--- a/tests/e2e-openshift/must-gather/check_must_gather.sh
+++ b/tests/e2e-openshift/must-gather/check_must_gather.sh
@@ -15,6 +15,7 @@ REQUIRED_ITEMS=(
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/subscription-opentelemetry-operator-v*-sub.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-headless.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector.yaml
+ ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/targetallocator-stateful.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/deployment-stateful-targetallocator.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-monitoring.yaml
ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-targetallocator.yaml
From b8a18abb96ff120f75d4aba4b3cd36db0f88c084 Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Fri, 6 Jun 2025 15:58:12 +0200
Subject: [PATCH 2/4] Fix OpenShift must-gather for target allocator CR
Signed-off-by: Pavol Loffay
---
.chloggen/fix-must-gather.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.chloggen/fix-must-gather.yaml b/.chloggen/fix-must-gather.yaml
index 4a9a078f17..08e02a5592 100644
--- a/.chloggen/fix-must-gather.yaml
+++ b/.chloggen/fix-must-gather.yaml
@@ -8,7 +8,7 @@ component: target allocator
note: Fix OpenShift must-gather for Target Allocator
# One or more tracking issues related to the change
-issues: []
+issues: [4084]
# (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.
From 470c4527f7519874a4c7599eb6109d6791e0d3f4 Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Fri, 6 Jun 2025 16:02:32 +0200
Subject: [PATCH 3/4] Fix OpenShift must-gather for target allocator CR
Signed-off-by: Pavol Loffay
---
cmd/gather/cluster/write_test.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmd/gather/cluster/write_test.go b/cmd/gather/cluster/write_test.go
index 0d2e26696c..494f5c6cd4 100644
--- a/cmd/gather/cluster/write_test.go
+++ b/cmd/gather/cluster/write_test.go
@@ -182,7 +182,7 @@ func TestCreateOTELFolder(t *testing.T) {
},
}
- outputDir, err := createOTELFolder(collectionDir, otelCol)
+ outputDir, err := createOTELFolder(collectionDir, otelCol.ObjectMeta)
expectedDir := filepath.Join(collectionDir, "namespaces", otelCol.Namespace, otelCol.Name)
assert.NoError(t, err)
From 64a32fae2a55427faec43f56b3f906382f67f253 Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Fri, 6 Jun 2025 16:09:15 +0200
Subject: [PATCH 4/4] Allow running with a custom image
Signed-off-by: Pavol Loffay
---
.../must-gather/check_must_gather.sh | 52 +++++++++----------
.../otlp-metrics-traces/check_must_gather.sh | 28 +++++-----
2 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/tests/e2e-openshift/must-gather/check_must_gather.sh b/tests/e2e-openshift/must-gather/check_must_gather.sh
index ab16f17944..0d33f0b698 100755
--- a/tests/e2e-openshift/must-gather/check_must_gather.sh
+++ b/tests/e2e-openshift/must-gather/check_must_gather.sh
@@ -9,32 +9,32 @@ oc adm must-gather --dest-dir=$MUST_GATHER_DIR --image=ghcr.io/open-telemetry/op
# Define required files and directories
REQUIRED_ITEMS=(
event-filter.html
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/*opentelemetry-operato*.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/clusterserviceversion-opentelemetry-operator-v*.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/installplan-install-*.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/subscription-opentelemetry-operator-v*-sub.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-headless.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/targetallocator-stateful.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/deployment-stateful-targetallocator.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-monitoring.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-targetallocator.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-targetallocator.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-collector-*.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-targetallocator.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/statefulset-stateful-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/opentelemetrycollector-stateful.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/serviceaccount-stateful-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/opentelemetrycollector-sidecar.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-monitoring.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/configmap-sidecar-collector-*.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/serviceaccount-sidecar-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-headless.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/chainsaw-must-gather/instrumentation-nodejs.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/opentelemetry-operator-controller-manager-*
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/deployment-opentelemetry-operator-controller-manager.yaml
+ *-must-gather-sha256-*/olm/*opentelemetry-operato*.yaml
+ *-must-gather-sha256-*/olm/clusterserviceversion-opentelemetry-operator-v*.yaml
+ *-must-gather-sha256-*/olm/installplan-install-*.yaml
+ *-must-gather-sha256-*/olm/subscription-opentelemetry-operator-v*-sub.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-headless.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/targetallocator-stateful.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/deployment-stateful-targetallocator.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-collector-monitoring.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-targetallocator.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/poddisruptionbudget-stateful-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/service-stateful-targetallocator.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-collector-*.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/configmap-stateful-targetallocator.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/statefulset-stateful-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/opentelemetrycollector-stateful.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/stateful/serviceaccount-stateful-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/opentelemetrycollector-sidecar.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-monitoring.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/configmap-sidecar-collector-*.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/serviceaccount-sidecar-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-must-gather/sidecar/service-sidecar-collector-headless.yaml
+ *-must-gather-sha256-*/chainsaw-must-gather/instrumentation-nodejs.yaml
+ *-must-gather-sha256-*/opentelemetry-operator-controller-manager-*
+ *-must-gather-sha256-*/deployment-opentelemetry-operator-controller-manager.yaml
timestamp
)
diff --git a/tests/e2e-openshift/otlp-metrics-traces/check_must_gather.sh b/tests/e2e-openshift/otlp-metrics-traces/check_must_gather.sh
index 6c2d5b6e0b..b09237836a 100755
--- a/tests/e2e-openshift/otlp-metrics-traces/check_must_gather.sh
+++ b/tests/e2e-openshift/otlp-metrics-traces/check_must_gather.sh
@@ -10,20 +10,20 @@ oc adm must-gather --dest-dir=$MUST_GATHER_DIR --image=ghcr.io/open-telemetry/op
# Define required files and directories
REQUIRED_ITEMS=(
event-filter.html
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/clusterserviceversion-opentelemetry-operator-*.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/*opentelemetry-operator*.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/installplan-install-*.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/olm/subscription-opentelemetry-operator-v*-sub.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/service-cluster-collector-collector-headless.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/deployment-cluster-collector-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/service-cluster-collector-collector-monitoring.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/opentelemetrycollector-cluster-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/configmap-cluster-collector-collector-*.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/serviceaccount-cluster-collector-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/service-cluster-collector-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/poddisruptionbudget-cluster-collector-collector.yaml
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/opentelemetry-operator-controller-manager-*
- ghcr-io-open-telemetry-opentelemetry-operator-must-gather-sha256-*/deployment-opentelemetry-operator-controller-manager.yaml
+ *-must-gather-sha256-*/olm/clusterserviceversion-opentelemetry-operator-*.yaml
+ *-must-gather-sha256-*/olm/*opentelemetry-operator*.yaml
+ *-must-gather-sha256-*/olm/installplan-install-*.yaml
+ *-must-gather-sha256-*/olm/subscription-opentelemetry-operator-v*-sub.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/service-cluster-collector-collector-headless.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/deployment-cluster-collector-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/service-cluster-collector-collector-monitoring.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/opentelemetrycollector-cluster-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/configmap-cluster-collector-collector-*.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/serviceaccount-cluster-collector-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/service-cluster-collector-collector.yaml
+ *-must-gather-sha256-*/namespaces/chainsaw-otlp-metrics/cluster-collector/poddisruptionbudget-cluster-collector-collector.yaml
+ *-must-gather-sha256-*/opentelemetry-operator-controller-manager-*
+ *-must-gather-sha256-*/deployment-opentelemetry-operator-controller-manager.yaml
timestamp
)