Skip to content

replace x/mod semver with local implementation - #320

Open
tariq1890 wants to merge 1 commit into
containerd:mainfrom
tariq1890:remove-x-mod-dep
Open

tariq1890 wants to merge 1 commit into
containerd:mainfrom
tariq1890:remove-x-mod-dep

Conversation

@tariq1890

@tariq1890 tariq1890 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

golang.org/x/mod is a pretty big dependency as its scope extends beyond semver. Considering that the semver parsing requirements are minimal, importing a third party module may not be all that necessary.

With this change, we decrease the CVE surface further as golang.org/x/mod is known to have CVEs. Moreover, this change shaves off one dependency from the dep-tree which is a win.

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! I like this; I think this looks like a reasonable alternative for this repo.

I found some issues, and left some suggestions; feel free to take those and amend your commit (no need to use a second commit for it, because we'd probably ask you to squash those anyway)

Comment thread pkg/version/version.go
Comment thread pkg/version/version.go
Comment thread pkg/version/version.go Outdated
Comment on lines +72 to +84
var major, minor, patch string
var rest string
if strings.Contains(s, ".") {
major, rest, _ = strings.Cut(s, ".")
} else {
major = s
}

if strings.Contains(rest, ".") {
minor, patch, _ = strings.Cut(rest, ".")
} else {
minor = rest
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor nit; I think the strings.Contains should be redundant here; strings.Cut would just be a no-op, so we can simplify;

major, rest, _ := strings.Cut(s, ".")
minor, patch, _ := strings.Cut(rest, ".")

That also makes pre-declaring the var major, minor, patch redundant.

(bad values will shuffle out later when trying to parse as an integer)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread pkg/version/version.go Outdated
minor int
patch int
pre string
build string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not a blocker, but I think at a quick glance, we don't use the build info (at least we don't compare it, and I think we discard it when printing as string)

if that's the case, we can drop this field, and just discard the information

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's totally fair.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is done!

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thx!

left a minor comment

Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com>
@tariq1890

Copy link
Copy Markdown
Contributor Author

@thaJeztah Thank you for the lightning fast reviews!

@tariq1890
tariq1890 requested a review from thaJeztah September 24, 2026 17:52
@thaJeztah

Copy link
Copy Markdown
Member

Thanks!

@klihub klihub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

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.

Copilot review overview

🟡 Changes recommended

SemVer parsing and prerelease ordering have correctness issues, and one module contains unrelated dependency upgrades.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Replaces golang.org/x/mod/semver with a local SemVer implementation.

Changes:

  • Adds local version parsing, comparison, and tests.
  • Removes x/mod metadata across modules.
  • Refreshes network-device-injector dependencies.
File Summary
plugins/​writable-cgroups/​go.sum Removes dependency checksums.
plugins/​writable-cgroups/​go.mod Removes x/mod.
plugins/​wasm/​go.sum Removes dependency checksums.
plugins/​wasm/​go.mod Removes x/mod.
plugins/​ulimit-adjuster/​go.sum Removes dependency checksums.
plugins/​ulimit-adjuster/​go.mod Removes x/mod.
plugins/​template/​go.sum Removes dependency checksums.
plugins/​template/​go.mod Removes x/mod.
plugins/​rdt/​go.sum Removes dependency checksums.
plugins/​rdt/​go.mod Removes x/mod.
plugins/​network-logger/​go.sum Removes dependency checksums.
plugins/​network-logger/​go.mod Removes x/mod.
plugins/​network-device-injector/​go.sum Refreshes dependency checksums.
plugins/​network-device-injector/​go.mod Removes x/mod and updates dependencies.
plugins/​logger/​go.sum Removes dependency checksums.
plugins/​logger/​go.mod Removes x/mod.
plugins/​hook-injector/​go.sum Removes dependency checksums.
plugins/​hook-injector/​go.mod Removes x/mod.
plugins/​differ/​go.sum Removes dependency checksums.
plugins/​differ/​go.mod Removes x/mod.
plugins/​device-injector/​go.sum Removes dependency checksums.
plugins/​device-injector/​go.mod Removes x/mod.
pkg/​version/​version.go Adds local SemVer parsing and comparison.
pkg/​version/​version_test.go Tests version comparison.
go.sum Removes x/mod checksums.
go.mod Removes the x/mod dependency.
examples/​go.sum Removes x/mod checksums.
examples/​go.mod Removes the x/mod dependency.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/version/version.go
return 1
}
}
return cmp.Compare(aVer.pre, bVer.pre)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix this.

Comment thread pkg/version/version.go
Comment on lines +82 to +85
func parseVersion(s string) (version, error) {
major, rest, _ := strings.Cut(s, ".")
minor, patch, _ := strings.Cut(rest, ".")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix this.

Comment thread pkg/version/version.go
return 1
}
}
return cmp.Compare(aVer.pre, bVer.pre)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix this.

Comment thread pkg/version/version.go
Comment on lines +82 to +85
func parseVersion(s string) (version, error) {
major, rest, _ := strings.Cut(s, ".")
minor, patch, _ := strings.Cut(rest, ".")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix this.

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.

5 participants