diff --git a/.chloggen/fix-must-gather.yaml b/.chloggen/fix-must-gather.yaml new file mode 100644 index 0000000000..08e02a5592 --- /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: [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. +# 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/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) 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..0d33f0b698 100755 --- a/tests/e2e-openshift/must-gather/check_must_gather.sh +++ b/tests/e2e-openshift/must-gather/check_must_gather.sh @@ -9,31 +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/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 )