Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/fix-must-gather.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: 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:
49 changes: 48 additions & 1 deletion cmd/gather/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this cause conflicts if you have a OpenTelemetryCollector and TargetAllocator with the same name?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, there is even a test for it

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 }},
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/gather/cluster/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/gather/cluster/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmd/gather/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 26 additions & 25 deletions tests/e2e-openshift/must-gather/check_must_gather.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
28 changes: 14 additions & 14 deletions tests/e2e-openshift/otlp-metrics-traces/check_must_gather.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
Loading