Skip to content
Open
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
6 changes: 3 additions & 3 deletions must-gather/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ Example must-gather for cluster-logging output (use `tree` for up-to-date struct
```
├── cluster-logging
│  ├── clo
│  │  ├── cluster-logging-operator-xxxxxxxxxx-xxxxx
│  │  └── version
│  │  └── cluster-logging-operator-xxxxxxxxxx-xxxxx
│  └── namespaces
│ │ └── [nampespace_name] ## including openshift-logging
│ │ ├── collector-xxxxx.describe
Expand Down Expand Up @@ -171,4 +170,5 @@ Example must-gather for cluster-logging output (use `tree` for up-to-date struct
│   ├── [...]
│  └── openshift-operators-redhat
│   ├── [...]
└── timestamp
├── timestamp
└── version
4 changes: 4 additions & 0 deletions must-gather/gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/openshift/cluster-logging-operator/must-gather/internal/metrics"
"github.com/openshift/cluster-logging-operator/must-gather/internal/namespace"
"github.com/openshift/cluster-logging-operator/must-gather/internal/ui"
"github.com/openshift/cluster-logging-operator/must-gather/internal/version"
)

var (
Expand Down Expand Up @@ -102,6 +103,9 @@ func (g *Gather) Run(ctx context.Context) error {
func (g *Gather) createCollectors() []api.Collector {
collectors := make([]api.Collector, 0)

// Version collector
collectors = append(collectors, version.NewCollector(g.logger, g.config.DestDir))

// Cluster-scoped resources collector
collectors = append(collectors, cluster.NewCollector(g.client, g.logger, g.config.DestDir))

Expand Down
13 changes: 13 additions & 0 deletions must-gather/internal/version/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package version_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestSuite(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "must-gather/internal/version suite")
}
37 changes: 37 additions & 0 deletions must-gather/internal/version/version_collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package version

import (
"context"
"fmt"

"github.com/openshift/cluster-logging-operator/must-gather/internal/api"
"github.com/openshift/cluster-logging-operator/version"

"k8s.io/apimachinery/pkg/runtime/schema"
)

const productName = "Red Hat OpenShift Logging"

type Collector struct {
logger api.Logger
destDir api.Path
}

func NewCollector(logger api.Logger, destDir api.Path) *Collector {
return &Collector{
logger: logger,
destDir: destDir,
}
}

func (c *Collector) Name() string {
return "VersionCollector"
}

func (c *Collector) Collect(_ context.Context, _ ...schema.GroupVersionResource) error {
defer c.logger.Begin("writing version file ...")()

content := fmt.Sprintf("%s/must-gather\n%s\n", productName, version.Version)
versionFile := c.destDir.Add("version")
return versionFile.WriteFile([]byte(content))
}
46 changes: 46 additions & 0 deletions must-gather/internal/version/version_collector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package version_test

import (
"context"
"os"
"path/filepath"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/openshift/cluster-logging-operator/must-gather/internal/api"
"github.com/openshift/cluster-logging-operator/must-gather/internal/version"
projectVersion "github.com/openshift/cluster-logging-operator/version"
)

var _ = Describe("VersionCollector", func() {
var (
tmpDir string
destDir api.Path
)

BeforeEach(func() {
var err error
tmpDir, err = os.MkdirTemp("", "version-collector-test")
Expect(err).ToNot(HaveOccurred())
destDir = api.NewPath(tmpDir)
})

AfterEach(func() {
Expect(os.RemoveAll(tmpDir)).To(Succeed())
})

It("should write a version file with the product name and version", func() {
collector := version.NewCollector(api.NewLogger(GinkgoWriter), destDir)
err := collector.Collect(context.Background())
Expect(err).ToNot(HaveOccurred())

content, err := os.ReadFile(filepath.Join(tmpDir, "version"))
Expect(err).ToNot(HaveOccurred())
Expect(string(content)).To(Equal("Red Hat OpenShift Logging/must-gather\n" + projectVersion.Version + "\n"))
})

It("should report its name", func() {
collector := version.NewCollector(api.NewLogger(GinkgoWriter), destDir)
Expect(collector.Name()).To(Equal("VersionCollector"))
})
})