Skip to content

refactor: update initiator.go#265

Merged
derekbit merged 4 commits into
longhorn:mainfrom
derekbit:engine-separation
Mar 16, 2026
Merged

refactor: update initiator.go#265
derekbit merged 4 commits into
longhorn:mainfrom
derekbit:engine-separation

Conversation

@derekbit
Copy link
Copy Markdown
Member

@derekbit derekbit commented Mar 3, 2026

Which issue(s) this PR fixes:

Issue longhorn/longhorn#7124

What this PR does / why we need it:

  1. Update log messages
  2. Reimplement the retry logics using avast/retry-go

Special notes for your reviewer:

Additional documentation or context

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 14.35897% with 167 lines in your changes missing coverage. Please review.
✅ Project coverage is 2.73%. Comparing base (fdb3e3d) to head (1f212a7).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pkg/initiator/initiator.go 15.13% 156 Missing and 1 partial ⚠️
pkg/spdk/client/advanced.go 0.00% 10 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main    #265      +/-   ##
========================================
+ Coverage   0.00%   2.73%   +2.73%     
========================================
  Files         38      38              
  Lines       4919    5017      +98     
========================================
+ Hits           0     137     +137     
+ Misses      4919    4870      -49     
- Partials       0      10      +10     
Flag Coverage Δ
unittests 2.73% <14.35%> (+2.73%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors initiator retry behavior to use github.com/avast/retry-go/v4, updates related log messages, and adds test coverage around initiator validation and a few helper behaviors.

Changes:

  • Add and vendor github.com/avast/retry-go/v4 and update go.mod/go.sum accordingly.
  • Refactor NVMe/TCP retry loops (connect, disconnect wait, device-info loading, device creation validation) to use retry-go with fixed delays and retry logging.
  • Add/expand initiator unit tests and add additional SPDK client log messages.

Reviewed changes

Copilot reviewed 4 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
.gitignore Ignore Dockerfile.dapper[0-9]*.
go.mod Add github.com/avast/retry-go/v4 v4.7.0.
go.sum Add checksums for retry-go and update other sums.
pkg/initiator/initiator.go Replace manual retry loops with retry-go; update NVMe/TCP log messages; adjust ublk startup flow and disk creation validation.
pkg/initiator/initiator_test.go Add unit tests for initiator validation and selected helper behaviors.
pkg/spdk/client/advanced.go Add Info-level logs around expose/unexpose steps.
vendor/modules.txt Record new vendored module entry.
vendor/github.com/avast/retry-go/v4/retry.go Vendored retry-go implementation.
vendor/github.com/avast/retry-go/v4/options.go Vendored retry-go options/config implementation.
vendor/github.com/avast/retry-go/v4/README.md Vendored upstream documentation.
vendor/github.com/avast/retry-go/v4/LICENSE Vendored upstream license.
vendor/github.com/avast/retry-go/v4/VERSION Vendored upstream version marker.
vendor/github.com/avast/retry-go/v4/Makefile Vendored upstream build tooling.
vendor/github.com/avast/retry-go/v4/.gitignore Vendored upstream ignore file.
vendor/github.com/avast/retry-go/v4/.godocdown.tmpl Vendored upstream doc template.
vendor/github.com/avast/retry-go/v4/generic.txt Vendored upstream benchmark output.
vendor/github.com/avast/retry-go/v4/current.txt Vendored upstream benchmark output.
Comments suppressed due to low confidence (1)

pkg/initiator/initiator.go:506

  • StartUblkInitiator no longer initializes the ublk target (previously done via UblkCreateTarget). If the SPDK ublk target hasn't already been created elsewhere, subsequent UblkGetDisks / UblkStartDisk calls can fail. Consider ensuring the target exists here (create-once semantics, ignoring an "already exists" response if applicable) to preserve prior behavior.
	ublkDeviceList, err := spdkClient.UblkGetDisks(0)
	if err != nil {
		return false, err
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/initiator/initiator.go
Comment thread pkg/initiator/initiator.go
Comment thread pkg/initiator/initiator.go
Comment thread pkg/initiator/initiator.go
@derekbit derekbit force-pushed the engine-separation branch 2 times, most recently from 713508b to 97f2c8c Compare March 4, 2026 04:41
@derekbit derekbit requested a review from Copilot March 4, 2026 04:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 17 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread pkg/initiator/initiator.go
Comment thread pkg/initiator/initiator.go
Comment thread pkg/initiator/initiator.go Outdated
Comment thread pkg/initiator/initiator.go
shuo-wu
shuo-wu previously approved these changes Mar 5, 2026
Copy link
Copy Markdown
Contributor

@shuo-wu shuo-wu left a comment

Choose a reason for hiding this comment

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

In general LGTM

Comment thread pkg/initiator/initiator.go Outdated
derekbit added 3 commits March 7, 2026 13:41
Signed-off-by: Derek Su <derek.su@suse.com>
Longhorn 7124

Signed-off-by: Derek Su <derek.su@suse.com>
1. Update log messages
2. Reimplement the retry logics using avast/retry-go

Longhorn 7124

Signed-off-by: Derek Su <derek.su@suse.com>
@derekbit derekbit force-pushed the engine-separation branch from 97f2c8c to ad0f7da Compare March 7, 2026 13:42
Persist the discovered SubsystemNQN immediately after a successful
discover-and-connect operation.

This keeps initiator state aligned with the actual connected NVMe/TCP
target even when controllerName validation fails afterwards.

Without this update, reload/load/cleanup paths may use a stale
SubsystemNQN and fail to locate or disconnect the correct NVMe device.

Longhorn 7124

Signed-off-by: Derek Su <derek.su@suse.com>
Copy link
Copy Markdown
Contributor

@shuo-wu shuo-wu left a comment

Choose a reason for hiding this comment

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

LGTM

@derekbit derekbit merged commit fc65c71 into longhorn:main Mar 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants