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
21 changes: 11 additions & 10 deletions cmd/gather-sysinfo/gather-sysinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ func collectMachineinfo(knitOpts *knit.KnitOptions, destPath string) error {
}

func makeSnapshot(cmd *cobra.Command, knitOpts *knit.KnitOptions, opts *snapshotOptions, args []string) error {
fileSpecs := dedupExpectedContent(kniExpectedCloneContent(), snapshot.ExpectedCloneContent())
ctx := cmd.Context()

fileSpecs, err := snapshot.ExpectedCloneContent(ctx)
if err != nil {
return fmt.Errorf("error getting expected clone content: %v", err)
}
fileSpecs = dedupExpectedContent(kniExpectedCloneContent(), fileSpecs)

if opts.dumpList {
for _, fileSpec := range fileSpecs {
fmt.Printf("%s\n", fileSpec)
Expand All @@ -79,12 +86,6 @@ func makeSnapshot(cmd *cobra.Command, knitOpts *knit.KnitOptions, opts *snapshot
return fmt.Errorf("--output is required")
}

if knitOpts.Debug {
snapshot.SetTraceFunction(func(msg string, args ...interface{}) {
knitOpts.Log.Printf(msg, args...)
})
}

scratchDir, err := os.MkdirTemp("", "perf-must-gather-*")
if err != nil {
return err
Expand All @@ -95,7 +96,7 @@ func makeSnapshot(cmd *cobra.Command, knitOpts *knit.KnitOptions, opts *snapshot
fileSpecs = chrootFileSpecs(fileSpecs, opts.rootDir)
}

if err := snapshot.CopyFilesInto(fileSpecs, scratchDir, nil); err != nil {
if err := snapshot.CopyFilesInto(ctx, fileSpecs, scratchDir, nil); err != nil {
return fmt.Errorf("error cloning extra files into %q: %v", scratchDir, err)
}

Expand All @@ -115,10 +116,10 @@ func makeSnapshot(cmd *cobra.Command, knitOpts *knit.KnitOptions, opts *snapshot

dest := opts.output
if dest == "-" {
err = snapshot.PackWithWriter(os.Stdout, scratchDir)
err = snapshot.PackWithWriter(ctx, os.Stdout, scratchDir)
dest = "stdout"
} else {
err = snapshot.PackFrom(dest, scratchDir)
err = snapshot.PackFrom(ctx, dest, scratchDir)
}
if err != nil {
return fmt.Errorf("error packing %q to %q: %v", scratchDir, dest, err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/docker/go-units v0.5.0
github.com/go-logr/stdr v1.2.2
github.com/google/go-cmp v0.7.0
github.com/jaypipes/ghw v0.20.0
github.com/jaypipes/ghw v0.23.0
github.com/kevinburke/go-bindata v3.24.0+incompatible
github.com/onsi/ginkgo/v2 v2.28.1
github.com/onsi/gomega v1.39.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+h
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jaypipes/ghw v0.20.0 h1:8efvHHtyrj0P4qVZ9KE43iW9tMThKoh6dEOo38f3a4w=
github.com/jaypipes/ghw v0.20.0/go.mod h1:GPrvwbtPoxYUenr74+nAnWbardIZq600vJDD5HnPsPE=
github.com/jaypipes/ghw v0.23.0 h1:WOL4hpLcIu1kIm+z5Oz19Tk1HNw/Sncrx/6GS8O0Kl0=
github.com/jaypipes/ghw v0.23.0/go.mod h1:fUNUjMZ0cjahKo+/u+32m9FutIx53Nkbi0Ti0m7j5HY=
github.com/jaypipes/pcidb v1.1.1 h1:QmPhpsbmmnCwZmHeYAATxEaoRuiMAJusKYkUncMC0ro=
github.com/jaypipes/pcidb v1.1.1/go.mod h1:x27LT2krrUgjf875KxQXKB0Ha/YXLdZRVmw6hH0G7g8=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
10 changes: 10 additions & 0 deletions pkg/performanceprofile/profilecreator/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ func executeInfoMode(mustGatherDirPath string, createForHypershift bool, infoOpt
if err != nil {
return fmt.Errorf("failed to parse the cluster data: %w", err)
}
defer func() {
for _, handlers := range clusterData {
for _, handler := range handlers {
if err := handler.Cleanup(); err != nil {
Alert("Warning: failed to cleanup handler: %v\n", err)
}
}
}
}()

clusterInfo := makeClusterInfoFromClusterData(clusterData)
if err := showClusterInfo(clusterInfo, infoOpts); err != nil {
return fmt.Errorf("unable to show cluster info %w", err)
Expand Down
7 changes: 7 additions & 0 deletions pkg/performanceprofile/profilecreator/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ func NewRootCommand() *cobra.Command {
if err != nil {
return err
}
defer func() {
for _, handler := range nodesHandlers {
if err := handler.Cleanup(); err != nil {
Alert("Warning: failed to cleanup handler: %v\n", err)
}
}
}()

err = profilecreator.EnsureNodesHaveTheSameHardware(nodesHandlers, tols)
if err != nil {
Expand Down
43 changes: 37 additions & 6 deletions pkg/performanceprofile/profilecreator/ghwhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import (
"os"
"path"
"sort"
"strings"

"github.com/jaypipes/ghw"
"github.com/jaypipes/ghw/pkg/cpu"
"github.com/jaypipes/ghw/pkg/option"
"github.com/jaypipes/ghw/pkg/snapshot"
"github.com/jaypipes/ghw/pkg/topology"

v1 "k8s.io/api/core/v1"
Expand All @@ -38,21 +40,50 @@ func NewGHWHandler(mustGatherDirPath string, node *v1.Node) (*GHWHandler, error)
if err != nil {
return nil, fmt.Errorf("can't obtain the node path %s: %v", nodeName, err)
}
_, err = os.Stat(path.Join(nodepath, nodeName, sysInfoFileName))
snapshotPath := path.Join(nodepath, nodeName, sysInfoFileName)
_, err = os.Stat(snapshotPath)
Comment thread
jmencak marked this conversation as resolved.
if err != nil {
return nil, fmt.Errorf("can't obtain the path: %s for node %s: %v", nodeName, nodepath, err)
}
options := ghw.WithSnapshot(ghw.SnapshotOptions{
Path: path.Join(nodepath, nodeName, sysInfoFileName),
})
ghwHandler := &GHWHandler{snapShotOptions: options, Node: node}

var chrootPath string
var tmpDir string

if strings.HasSuffix(snapshotPath, ".tgz") || strings.HasSuffix(snapshotPath, ".tar.gz") {
tmpDir, err = snapshot.Unpack(snapshotPath)
if err != nil {
if tmpDir != "" {
_ = os.RemoveAll(tmpDir)
}
return nil, fmt.Errorf("failed to unpack snapshot %s: %v", snapshotPath, err)
}
Comment thread
jmencak marked this conversation as resolved.
chrootPath = tmpDir
} else {
chrootPath = snapshotPath
}

options := option.WithChroot(chrootPath)
ghwHandler := &GHWHandler{
snapShotOptions: options,
Node: node,
tmpDir: tmpDir,
}
return ghwHandler, nil
}

// GHWHandler is a wrapper around ghw to get the API object
type GHWHandler struct {
snapShotOptions *option.Option
snapShotOptions option.Option
Node *v1.Node
tmpDir string
}

// Cleanup removes any temporary directories created during handler initialization
func (ghwHandler *GHWHandler) Cleanup() error {
if ghwHandler.tmpDir != "" {
return os.RemoveAll(ghwHandler.tmpDir)
}
return nil
}

// CPU returns a CPUInfo struct that contains information about the CPUs on the host system
Expand Down
20 changes: 20 additions & 0 deletions pkg/performanceprofile/profilecreator/profilecreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ var _ = Describe("PerformanceProfileCreator: Consuming GHW Snapshot from Must Ga
Expect(err).ToNot(HaveOccurred())
handle, err := NewGHWHandler(mustGatherDirAbsolutePath, node)
Expect(err).ToNot(HaveOccurred())
DeferCleanup(handle.Cleanup)
cpuInfo, err := handle.CPU()
Expect(err).ToNot(HaveOccurred())
Expect(len(cpuInfo.Processors)).To(Equal(2))
Expand Down Expand Up @@ -853,6 +854,14 @@ var _ = Describe("PerformanceProfileCreator: Populating Reserved and Isolated CP
BeforeEach(func() {
node = newTestNode(worker1)
})

AfterEach(func() {
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.

IIRC this can be racy if we run the tests in parallel, which (IIRC again) we don't.

if handle != nil {
Expect(handle.Cleanup()).To(Succeed())
handle = nil
}
})

Context("Check if reserved and isolated CPUs are properly populated in the performance profile", func() {
It("Ensure reserved CPUs populated are correctly when splitReservedCPUsAcrossNUMA is disabled and disableHT is disabled", func() {
reservedCPUCount = 20 // random number, no special meaning
Expand Down Expand Up @@ -1390,6 +1399,13 @@ var _ = Describe("PerformanceProfileCreator: Check if Hyperthreading enabled/dis
var handle *GHWHandler
var err error

AfterEach(func() {
if handle != nil {
Expect(handle.Cleanup()).To(Succeed())
handle = nil
}
})

Context("Check if hyperthreading is enabled on the system or not", func() {
It("Ensure we detect correctly that hyperthreading is enabled on a system", func() {
node = newTestNode(worker1)
Expand Down Expand Up @@ -1608,11 +1624,13 @@ var _ = Describe("PerformanceProfileCreator: Ensuring Nodes hardware equality",
Expect(err).ToNot(HaveOccurred())
node1Handle, err := NewGHWHandler(mustGatherDirAbsolutePath, node1)
Expect(err).ToNot(HaveOccurred())
DeferCleanup(node1Handle.Cleanup)

node2, err := getNode(mustGatherDirAbsolutePath, worker1+".yaml")
Expect(err).ToNot(HaveOccurred())
node2Handle, err := NewGHWHandler(mustGatherDirAbsolutePath, node2)
Expect(err).ToNot(HaveOccurred())
DeferCleanup(node2Handle.Cleanup)

nodeHandles := []*GHWHandler{node1Handle, node2Handle}
tols := toleration.Set{}
Expand All @@ -1632,11 +1650,13 @@ var _ = Describe("PerformanceProfileCreator: Ensuring Nodes hardware equality",
Expect(err).ToNot(HaveOccurred())
node1Handle, err := NewGHWHandler(mustGatherDirAbsolutePath, node1)
Expect(err).ToNot(HaveOccurred())
DeferCleanup(node1Handle.Cleanup)

node2, err := getNode(mustGatherDirAbsolutePath, worker2+".yaml")
Expect(err).ToNot(HaveOccurred())
node2Handle, err := NewGHWHandler(mustGatherDirAbsolutePath, node2)
Expect(err).ToNot(HaveOccurred())
DeferCleanup(node2Handle.Cleanup)

nodeHandles := []*GHWHandler{node1Handle, node2Handle}
err = EnsureNodesHaveTheSameHardware(nodeHandles, toleration.Set{})
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/jaypipes/ghw/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions vendor/github.com/jaypipes/ghw/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading