Skip to content

remove direct dependency on github.com/spf13/cobra - #3280

Open
thaJeztah wants to merge 2 commits into
moby:masterfrom
thaJeztah:remove_cobra
Open

remove direct dependency on github.com/spf13/cobra#3280
thaJeztah wants to merge 2 commits into
moby:masterfrom
thaJeztah:remove_cobra

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

The main swarmkit module only used Cobra for the cmd/swarm-bench: test-utility, which could easily be rewritten with stdlib only. The remaining use was in the version/ package, which was only used by the swarmd module, so moving it there.

- Description for the changelog

Copilot AI left a comment

Copy link
Copy Markdown

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 removes the main github.com/moby/swarmkit/v2 module’s direct dependency on github.com/spf13/cobra (and related transitive deps) by rewriting the cmd/swarm-bench utility to use the Go standard library flag package, and by relocating the version package into the swarmd/ module where it is actually consumed.

Changes:

  • Dropped Cobra (and transitive pflag/mousetrap) from the root module’s go.mod, go.sum, and vendored module list.
  • Rewrote cmd/swarm-bench CLI parsing using flag instead of Cobra.
  • Introduced swarmd/version (including a Cobra version subcommand) and updated swarmd binaries to import it; adjusted build ldflags to target the moved version package.

Reviewed changes

Copilot reviewed 5 out of 81 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vendor/modules.txt Removes vendored module entries for Cobra/pflag/mousetrap in the root module.
vendor/github.com/spf13/pflag/uint8.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/uint64.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/uint32.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/uint16.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/uint.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/uint_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/string.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/string_to_string.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/string_to_int64.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/string_to_int.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/string_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/string_array.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/README.md Removes vendored pflag docs.
vendor/github.com/spf13/pflag/LICENSE Removes vendored pflag license.
vendor/github.com/spf13/pflag/ipnet.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/ipnet_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/ipmask.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/ip.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/ip_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/int8.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/int64.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/int64_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/int32.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/int32_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/int16.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/int.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/int_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/golangflag.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/float64.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/float64_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/float32.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/float32_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/duration.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/duration_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/count.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/bytes.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/bool.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/bool_slice.go Removes vendored pflag code.
vendor/github.com/spf13/pflag/.travis.yml Removes vendored pflag CI config.
vendor/github.com/spf13/pflag/.golangci.yaml Removes vendored pflag linter config.
vendor/github.com/spf13/pflag/.gitignore Removes vendored pflag ignore file.
vendor/github.com/spf13/pflag/.editorconfig Removes vendored pflag editor config.
vendor/github.com/spf13/cobra/zsh_completions.go Removes vendored Cobra code.
vendor/github.com/spf13/cobra/shell_completions.go Removes vendored Cobra code.
vendor/github.com/spf13/cobra/README.md Removes vendored Cobra docs.
vendor/github.com/spf13/cobra/Makefile Removes vendored Cobra build file.
vendor/github.com/spf13/cobra/MAINTAINERS Removes vendored Cobra maintainers file.
vendor/github.com/spf13/cobra/LICENSE.txt Removes vendored Cobra license.
vendor/github.com/spf13/cobra/flag_groups.go Removes vendored Cobra code.
vendor/github.com/spf13/cobra/fish_completions.go Removes vendored Cobra code.
vendor/github.com/spf13/cobra/CONTRIBUTING.md Removes vendored Cobra contributing guide.
vendor/github.com/spf13/cobra/CONDUCT.md Removes vendored Cobra conduct doc.
vendor/github.com/spf13/cobra/command_win.go Removes vendored Cobra code.
vendor/github.com/spf13/cobra/command_notwin.go Removes vendored Cobra code.
vendor/github.com/spf13/cobra/cobra.go Removes vendored Cobra code.
vendor/github.com/spf13/cobra/args.go Removes vendored Cobra code.
vendor/github.com/spf13/cobra/active_help.go Removes vendored Cobra code.
vendor/github.com/spf13/cobra/.mailmap Removes vendored Cobra metadata.
vendor/github.com/spf13/cobra/.golangci.yml Removes vendored Cobra linter config.
vendor/github.com/spf13/cobra/.gitignore Removes vendored Cobra ignore file.
vendor/github.com/inconshreveable/mousetrap/trap_windows.go Removes vendored mousetrap code.
vendor/github.com/inconshreveable/mousetrap/trap_others.go Removes vendored mousetrap code.
vendor/github.com/inconshreveable/mousetrap/README.md Removes vendored mousetrap docs.
vendor/github.com/inconshreveable/mousetrap/LICENSE Removes vendored mousetrap license.
swarmd/version/version.sh Adds generator script for swarmd/version/version.go.
swarmd/version/version.go Adds version constants in swarmd module.
swarmd/version/print.go Adds version printing helpers in swarmd module.
swarmd/version/cmd.go Adds Cobra version subcommand in swarmd module.
swarmd/cmd/swarmd/main.go Switches imports to use swarmd/version instead of root version.
swarmd/cmd/swarmctl/main.go Switches imports to use swarmd/version instead of root version.
go.mod Removes root-module dependency on Cobra/pflag/mousetrap.
go.sum Removes root-module checksums for Cobra/pflag/mousetrap (and related indirects).
direct.mk Updates ldflags target package lookup to the moved swarmd/version package.
cmd/swarm-bench/main.go Replaces Cobra CLI parsing with stdlib flag parsing.

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

Comment thread cmd/swarm-bench/main.go
Comment thread direct.mk
Comment on lines -20 to 21
VERSIONPKG := $(shell go list ./version)
VERSIONPKG := $(shell go -C ./swarmd list ./version)
GO_LDFLAGS=-ldflags "-X $(VERSIONPKG).Version=$(VERSION)"

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.

Kept this for now, but probably could be swapped for go module version / vcs info.

It's a very basic test-utility; stdlib should do for this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The version package was only used by the swarmd CLI, and not as part
of the swarmkit library module; move it to the swarmd module, so that
we can drop the Cobra module as dependency.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Copilot AI left a comment

Copy link
Copy Markdown

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 5 out of 81 changed files in this pull request and generated no new comments.

Suppressed comments (1)

direct.mk:20

  • VERSIONPKG now points at the swarmd module’s version package, but this Makefile still has a release-generation rule for version/version.go (which no longer exists after moving version under swarmd/). Updating that rule prevents a broken/stale target.
VERSIONPKG := $(shell go -C ./swarmd list ./version)

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.70%. Comparing base (6e9e7b8) to head (7bbebfa).
⚠️ Report is 60 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3280      +/-   ##
==========================================
- Coverage   14.73%   14.70%   -0.03%     
==========================================
  Files         200      198       -2     
  Lines       93077    93007      -70     
==========================================
- Hits        13712    13681      -31     
+ Misses      78019    77983      -36     
+ Partials     1346     1343       -3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thaJeztah
thaJeztah marked this pull request as ready for review August 1, 2026 18:25
Comment thread cmd/swarm-bench/main.go
Comment on lines -50 to -55
func init() {
mainCmd.Flags().Int64P("count", "c", 0, "Number of tasks to start for the benchmarking session")
mainCmd.Flags().StringP("manager", "m", "localhost:4242", "Specify the manager address")
mainCmd.Flags().IntP("port", "p", 2222, "Port used by the benchmark for listening")
mainCmd.Flags().StringP("ip", "i", "127.0.0.1", "IP of the benchmarking tool. Tasks will phone home to this address")
}

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.

Looks like this was broken on master;

go build ./cmd/swarm-bench

./swarm-bench -c 3
Error: trying to get uint64 value of flag of type int64
Usage:
  ./swarm-bench [flags]

Flags:
  -c, --count int        Number of tasks to start for the benchmarking session
  -h, --help             help for ./swarm-bench
  -i, --ip string        IP of the benchmarking tool. Tasks will phone home to this address (default "127.0.0.1")
  -m, --manager string   Specify the manager address (default "localhost:4242")
  -p, --port int         Port used by the benchmark for listening (default 2222)

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.

So wondering if we should just remove the binary altogether (instead of also doing the rewrite from #3281)

any thoughts @corhere ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How much fuss would it take to move it into a dedicated module, e.g. github.com/moby/swarmkit/contrib/swarm-bench? You already did the work to port it over to stdlib; might as well keep it around in case someone finds it useful.

@corhere
corhere requested a review from dperny August 4, 2026 14:34

@corhere corhere left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It appears that the the github.com/swarmkit/v2/version package is intended for importers to introspect the Swarmkit version, which is (in theory) stamped into tagged releases of the module. Only the cmd.go and print.go files should be moved into swarmd.

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.

4 participants