Skip to content

Bump ghw dependency#1492

Open
jmencak wants to merge 1 commit intoopenshift:mainfrom
jmencak:4.22-ghw-bump
Open

Bump ghw dependency#1492
jmencak wants to merge 1 commit intoopenshift:mainfrom
jmencak:4.22-ghw-bump

Conversation

@jmencak
Copy link
Copy Markdown
Contributor

@jmencak jmencak commented Mar 30, 2026

Upgrade ghw library and address API breaking changes. The new ghw API no
longer provides the WithSnapshot() function and SnapshotOptions
struct that were available in versions prior to v0.21.3.

Changes:

  • Update ghwhandler.go to use new snapshot.Unpack() for archive handling
  • Replace WithSnapshot() with option.WithChroot() for snapshot paths
  • Add Cleanup() method to GHWHandler for temporary directory cleanup
  • Handle both .tgz and .tar.gz archive formats explicitly

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 30, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Mar 30, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Important

Review skipped

Auto reviews are limited based on label configuration.

🚫 Excluded labels (none allowed) (1)
  • do-not-merge/work-in-progress

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5612ee11-6588-45ed-9443-4369c9fb2bb3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR adds context support to snapshot operations, upgrades the ghw dependency to v0.23.0, refactors GHWHandler to support compressed .tgz/.tar.gz archives with automatic cleanup, and introduces deferred cleanup patterns for handler lifecycle management across multiple entry points.

Changes

Cohort / File(s) Summary
Snapshot Context Propagation
cmd/gather-sysinfo/gather-sysinfo.go
Added context parameter to snapshot method calls (ExpectedCloneContent, CopyFilesInto, PackWithWriter, PackFrom). Enhanced error handling for clone content retrieval. Removed conditional debug tracing setup.
Dependency Updates
go.mod
Upgraded github.com/jaypipes/ghw from v0.20.0 to v0.23.0.
Handler Cleanup Patterns
pkg/performanceprofile/profilecreator/cmd/info.go, pkg/performanceprofile/profilecreator/cmd/root.go, pkg/performanceprofile/profilecreator/profilecreator_test.go
Added deferred cleanup invocations for handler instances with warning-level error reporting to stderr. Test cleanup strengthened via DeferCleanup and AfterEach blocks.
GHWHandler Archive Support & Refactoring
pkg/performanceprofile/profilecreator/ghwhandler.go
Refactored NewGHWHandler to detect and extract .tgz/.tar.gz archives, using resulting temp directory as chroot. Changed snapShotOptions field from pointer (\*option.Option) to value type (option.Option). Added tmpDir field and new Cleanup() method for temp directory removal. Updated option construction from ghw.WithSnapshot(...) to option.WithChroot(...).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Mar 30, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jmencak

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 30, 2026
@jmencak
Copy link
Copy Markdown
Contributor Author

jmencak commented Mar 30, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
pkg/performanceprofile/profilecreator/cmd/info.go (1)

40-52: ⚠️ Potential issue | 🟠 Major

makeClusterData errors can still leak unpacked snapshots.

This defer only runs after makeClusterData succeeds. In info mode, a later pool failure can discard handlers already stored for earlier pools without calling Cleanup(), so the temp dirs introduced by archive unpacking are leaked. Please add cleanup inside makeClusterData before returning any error after handlers have been appended.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/performanceprofile/profilecreator/cmd/info.go` around lines 40 - 52, The
makeClusterData function can append handlers (temp-dir resources) then return an
error without cleaning them up; modify makeClusterData so that whenever it
returns a non-nil error after any handlers have been appended to the clusterData
slice/map it iterates those already-created handlers and calls their Cleanup()
(handling/logging any cleanup errors) before returning the error, ensuring no
unpacked snapshots remain; reference the makeClusterData function and the
handler.Cleanup() method used in the deferred cleanup of clusterData in info.go.
pkg/performanceprofile/profilecreator/cmd/root.go (1)

158-168: ⚠️ Potential issue | 🟠 Major

Cleanup still misses partial makeNodesHandlers failures.

This defer is registered only after makeNodesHandlers succeeds. If one node fails after earlier archive-backed handlers were already created, those handlers' unpacked temp dirs are leaked because the helper drops the partial slice on error.

💡 Suggested fix
 func makeNodesHandlers(mustGatherDirPath, poolName string, nodes []*corev1.Node) ([]*profilecreator.GHWHandler, error) {
-	handlers := make([]*profilecreator.GHWHandler, len(nodes))
+	handlers := make([]*profilecreator.GHWHandler, 0, len(nodes))
 	sb := strings.Builder{}
-	for i, node := range nodes {
+	for _, node := range nodes {
 		handle, err := profilecreator.NewGHWHandler(mustGatherDirPath, node)
 		if err != nil {
+			for _, h := range handlers {
+				_ = h.Cleanup()
+			}
 			return nil, fmt.Errorf("failed to load node's GHW snapshot: %w", err)
 		}
-		handlers[i] = handle
+		handlers = append(handlers, handle)
 		sb.WriteString(node.Name + " ")
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/performanceprofile/profilecreator/cmd/root.go` around lines 158 - 168,
The current code registers the cleanup defer only after makeNodesHandlers
returns nil error, which leaks temp dirs when makeNodesHandlers fails after
creating some handlers; change the call site so you capture the returned
nodesHandlers slice and immediately defer iterating and calling
handler.Cleanup() on any non-nil entries before inspecting err (i.e., place the
defer right after assigning nodesHandlers, not inside the success branch), and
ensure makeNodesHandlers still returns any partially-created handlers on error
so the deferred cleanup can run (refer to makeNodesHandlers, nodesHandlers, and
handler.Cleanup).
🧹 Nitpick comments (1)
pkg/performanceprofile/profilecreator/profilecreator_test.go (1)

233-235: Add one archive-backed NewGHWHandler test.

These cleanup additions still only exercise directory-backed must-gather input. The new .tgz/.tar.gz branch and its failure cleanup in ghwhandler.go remain uncovered, so this migration can regress without a test catching it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/performanceprofile/profilecreator/profilecreator_test.go` around lines
233 - 235, Add a test that exercises the archive-backed path of NewGHWHandler by
creating a temporary .tgz (or .tar.gz) must-gather archive containing the same
test fixture files used by the directory-backed tests, call NewGHWHandler with
the archive path and the same node input, assert no error, and ensure
DeferCleanup(handle.Cleanup) is used so the failure/cleanup branch in
ghwhandler.go is executed; target the NewGHWHandler call site in
profilecreator_test.go and verify the handler can open and later Cleanup an
archive-backed must-gather to cover the .tgz/.tar.gz branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/performanceprofile/profilecreator/ghwhandler.go`:
- Around line 52-56: When snapshot.Unpack(...) returns an error the temp
directory at tmpDir is left behind; update the error path after calling
snapshot.Unpack in ghwhandler.go to remove the temp dir (e.g., call
os.RemoveAll(tmpDir)) before returning the fmt.Errorf; ensure you only attempt
cleanup when tmpDir is non-empty and preserve the original error returned by
snapshot.Unpack so the function still returns the same error payload.

---

Outside diff comments:
In `@pkg/performanceprofile/profilecreator/cmd/info.go`:
- Around line 40-52: The makeClusterData function can append handlers (temp-dir
resources) then return an error without cleaning them up; modify makeClusterData
so that whenever it returns a non-nil error after any handlers have been
appended to the clusterData slice/map it iterates those already-created handlers
and calls their Cleanup() (handling/logging any cleanup errors) before returning
the error, ensuring no unpacked snapshots remain; reference the makeClusterData
function and the handler.Cleanup() method used in the deferred cleanup of
clusterData in info.go.

In `@pkg/performanceprofile/profilecreator/cmd/root.go`:
- Around line 158-168: The current code registers the cleanup defer only after
makeNodesHandlers returns nil error, which leaks temp dirs when
makeNodesHandlers fails after creating some handlers; change the call site so
you capture the returned nodesHandlers slice and immediately defer iterating and
calling handler.Cleanup() on any non-nil entries before inspecting err (i.e.,
place the defer right after assigning nodesHandlers, not inside the success
branch), and ensure makeNodesHandlers still returns any partially-created
handlers on error so the deferred cleanup can run (refer to makeNodesHandlers,
nodesHandlers, and handler.Cleanup).

---

Nitpick comments:
In `@pkg/performanceprofile/profilecreator/profilecreator_test.go`:
- Around line 233-235: Add a test that exercises the archive-backed path of
NewGHWHandler by creating a temporary .tgz (or .tar.gz) must-gather archive
containing the same test fixture files used by the directory-backed tests, call
NewGHWHandler with the archive path and the same node input, assert no error,
and ensure DeferCleanup(handle.Cleanup) is used so the failure/cleanup branch in
ghwhandler.go is executed; target the NewGHWHandler call site in
profilecreator_test.go and verify the handler can open and later Cleanup an
archive-backed must-gather to cover the .tgz/.tar.gz branch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 11279e30-b141-438b-9f4d-8e2265abcdbd

📥 Commits

Reviewing files that changed from the base of the PR and between 1d3e91f and 9f1b186.

⛔ Files ignored due to path filters (79)
  • go.sum is excluded by !**/*.sum
  • vendor/github.com/jaypipes/ghw/.gitignore is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/Makefile is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/README.md is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/SNAPSHOT.md is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/alias.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/host.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/internal/config/context.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/internal/config/log.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/internal/log/log.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/accelerator/accelerator.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/accelerator/accelerator_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/accelerator/accelerator_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/accelerator/accelerator_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/baseboard/baseboard.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/baseboard/baseboard_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/baseboard/baseboard_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/baseboard/baseboard_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/bios/bios.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/bios/bios_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/bios/bios_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/bios/bios_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/block/block.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/block/block_darwin.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/block/block_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/block/block_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/block/block_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/chassis/chassis.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/chassis/chassis_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/chassis/chassis_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/chassis/chassis_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/context/context.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/cpu/cpu.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/cpu/cpu_darwin.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/cpu/cpu_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/cpu/cpu_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/cpu/cpu_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/gpu/gpu.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/gpu/gpu_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/gpu/gpu_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/gpu/gpu_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/linuxdmi/dmi_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/linuxpath/path_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/marshal/marshal.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/memory/memory.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/memory/memory_cache_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/memory/memory_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/memory/memory_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/memory/memory_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/net/net.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/net/net_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/net/net_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/net/net_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/option/option.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/pci/pci.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/pci/pci_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/pci/pci_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/product/product.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/product/product_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/product/product_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/product/product_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/snapshot/clonetree.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/snapshot/clonetree_block_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/snapshot/clonetree_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/snapshot/clonetree_pci_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/snapshot/clonetree_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/snapshot/clonetree_usb_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/snapshot/pack.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/snapshot/trace.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/snapshot/unpack.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/topology/topology.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/topology/topology_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/topology/topology_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/topology/topology_windows.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/usb/usb.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/usb/usb_linux.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/usb/usb_stub.go is excluded by !vendor/**, !**/vendor/**
  • vendor/github.com/jaypipes/ghw/pkg/util/util.go is excluded by !vendor/**, !**/vendor/**
  • vendor/modules.txt is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (6)
  • cmd/gather-sysinfo/gather-sysinfo.go
  • go.mod
  • pkg/performanceprofile/profilecreator/cmd/info.go
  • pkg/performanceprofile/profilecreator/cmd/root.go
  • pkg/performanceprofile/profilecreator/ghwhandler.go
  • pkg/performanceprofile/profilecreator/profilecreator_test.go

Upgrade ghw library and address API breaking changes. The new ghw API no longer
provides the WithSnapshot() function and SnapshotOptions struct that were
available in versions prior to v0.21.3.

Changes:
  * Update ghwhandler.go to use new snapshot.Unpack() for archive handling
  * Replace WithSnapshot() with option.WithChroot() for snapshot paths
  * Add Cleanup() method to GHWHandler for temporary directory cleanup
  * Handle both .tgz and .tar.gz archive formats explicitly
@jmencak
Copy link
Copy Markdown
Contributor Author

jmencak commented Mar 31, 2026

/retest

@jmencak jmencak marked this pull request as ready for review March 31, 2026 11:52
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 31, 2026
@openshift-ci openshift-ci bot requested review from MarSik and yanirq March 31, 2026 11:54
@jmencak
Copy link
Copy Markdown
Contributor Author

jmencak commented Mar 31, 2026

/retest

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Mar 31, 2026

@jmencak: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant