Skip to content

Commit

Permalink
Allow underscores in versions (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb-mp authored Feb 20, 2024
1 parent dcf7ed6 commit 3c83f06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/drvinfo/drvinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package drvinfo
import (
"log"
"os"
"strings"

"github.com/hashicorp/go-version"
"github.com/safchain/ethtool"
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/drvinfo/drvinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3c83f06

Please sign in to comment.