Skip to content

Commit 95338ef

Browse files
weyrickleoparente
and
leoparente
authored
fix pktvisor-cli version warning (#220)
Co-authored-by: leoparente <[email protected]>
1 parent a6002ce commit 95338ef

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

Diff for: golang/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module pktvisor
33
go 1.15
44

55
require (
6+
github.com/hashicorp/go-version v1.3.0
67
github.com/jroimartin/gocui v0.5.0
78
github.com/mitchellh/mapstructure v1.4.2
89
github.com/pkg/errors v0.9.1

Diff for: golang/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
2+
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
13
github.com/jroimartin/gocui v0.5.0 h1:DCZc97zY9dMnHXJSJLLmx9VqiEnAj0yh0eTNpuEtG/4=
24
github.com/jroimartin/gocui v0.5.0/go.mod h1:l7Hz8DoYoL6NoYnlnaX6XCNR62G7J5FfSW5jEogzaxE=
35
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=

Diff for: golang/pkg/client/client.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package client
77
import (
88
"encoding/json"
99
"fmt"
10+
"github.com/hashicorp/go-version"
1011
"github.com/mitchellh/mapstructure"
1112
"github.com/pkg/errors"
1213
"io/ioutil"
@@ -16,10 +17,6 @@ import (
1617
"time"
1718
)
1819

19-
const (
20-
wantServerVersion = "3.3"
21-
)
22-
2320
type Client interface {
2421
GetStats() (*StatSnapshot, error)
2522
GetServerVersion() string
@@ -55,8 +52,17 @@ func (c *client) GetServerVersion() string {
5552
return "unknown"
5653
}
5754
c.serverVersion = appMetrics.App.Version
58-
if c.serverVersion[0:3] != wantServerVersion {
59-
log.Println(fmt.Sprintf("WARNING: this version of pktvisor-cli was written for pktvisord %s.x", wantServerVersion))
55+
serverVersion, err := version.NewVersion(c.serverVersion)
56+
if err == nil {
57+
clientVersion, err := version.NewVersion(VisorVersionNum)
58+
if err == nil {
59+
cMajor := clientVersion.Segments()[0]
60+
sMajor := serverVersion.Segments()[0]
61+
if sMajor != cMajor {
62+
log.Println(fmt.Sprintf("WARNING: this version of pktvisor-cli was written for a different major pktvisord version (server:%d, client:%d)", cMajor, sMajor))
63+
time.Sleep(3 * time.Second)
64+
}
65+
}
6066
}
6167
return c.serverVersion
6268
}

0 commit comments

Comments
 (0)