From 3c83f06c83f9bf41d9ecae7b84ba4e9ea7fbd1ab Mon Sep 17 00:00:00 2001 From: Ian Bishop <151477169+ianb-mp@users.noreply.github.com> Date: Tue, 20 Feb 2024 20:57:53 +1000 Subject: [PATCH] Allow underscores in versions (#32) --- pkg/drvinfo/drvinfo.go | 11 +++++++++-- pkg/drvinfo/drvinfo_test.go | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/drvinfo/drvinfo.go b/pkg/drvinfo/drvinfo.go index 5ba756b..55b0e2a 100644 --- a/pkg/drvinfo/drvinfo.go +++ b/pkg/drvinfo/drvinfo.go @@ -3,6 +3,7 @@ package drvinfo import ( "log" "os" + "strings" "github.com/hashicorp/go-version" "github.com/safchain/ethtool" @@ -69,11 +70,17 @@ func (dl *SupportedDrivers) IsDriverSupported(drv *DriverInfo) bool { if d.Name != drv.Name { continue } - supported, err := version.NewVersion(d.Version) + + // Remove underscores to keep goversion happy + // See: https://github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/issues/31 + dVersionSanitized := strings.ReplaceAll(d.Version, "_", "") + drvVersionSanitized := strings.ReplaceAll(drv.Version, "_", "") + + supported, err := version.NewVersion(dVersionSanitized) if err != nil { continue } - v, err := version.NewVersion(drv.Version) + v, err := version.NewVersion(drvVersionSanitized) if err != nil { continue } diff --git a/pkg/drvinfo/drvinfo_test.go b/pkg/drvinfo/drvinfo_test.go index ca70da3..ada7c48 100644 --- a/pkg/drvinfo/drvinfo_test.go +++ b/pkg/drvinfo/drvinfo_test.go @@ -80,6 +80,7 @@ var _ = Describe("drvinfo", func() { Entry("return true if driver is supported", getTestDrv(), true, NewSupportedDrivers(getDbFilePath())), Entry("return false if driver is not supported", &DriverInfo{Name: "ice", Version: "1.8.1"}, false, NewSupportedDrivers(getDbFilePath())), Entry("return true if driver version is greater than supported", &DriverInfo{Name: "ice", Version: "1.10.1"}, true, NewSupportedDrivers(getDbFilePath())), + Entry("return true if driver version is greater than supported and includes underscore", &DriverInfo{Name: "ice", Version: "1.10.1-x86_64"}, true, NewSupportedDrivers(getDbFilePath())), ) DescribeTable("readSupportedDrivers should", func(testDrv *DriverInfo) {