Skip to content

Commit

Permalink
fix: inaccurate comparison of kbcli and kubeblock version (#3969)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengluodb authored Jun 27, 2023
1 parent c8b8a17 commit b82d0bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"runtime"

gv "github.com/hashicorp/go-version"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
Expand Down Expand Up @@ -72,7 +73,18 @@ func (o *versionOptions) Run(f cmdutil.Factory) {
fmt.Printf(" Platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
}

if v.KubeBlocks != "" && v.Cli != v.KubeBlocks {
kbVersion, err := gv.NewVersion(v.KubeBlocks)
if err != nil {
klog.V(1).Infof("failed to parse KubeBlocks version: %v", err)
return
}
cliVersion, err := gv.NewVersion(v.Cli)
if err != nil {
klog.V(1).Infof("failed to parse kbcli version: %v", err)
return
}

if !kbVersion.Equal(cliVersion) {
fmt.Printf("WARNING: version difference between kbcli (%s) and kubeblocks (%s) \n", v.Cli, v.KubeBlocks)
}
}
19 changes: 19 additions & 0 deletions cmd/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

gv "github.com/hashicorp/go-version"
"k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
)
Expand All @@ -39,4 +40,22 @@ var _ = Describe("version", func() {
o := &versionOptions{}
o.Run(tf)
})

It("version comparison", func() {
kbVersion, _ := gv.NewVersion("0.6.0-alpha.23")
cliVersion, _ := gv.NewVersion("v0.6.0-alpha.23")
Expect(kbVersion.Equal(cliVersion)).Should(BeTrue())

kbVersion, _ = gv.NewVersion("0.6.0-alpha.23")
cliVersion, _ = gv.NewVersion("v0.6.23")
Expect(kbVersion.Equal(cliVersion)).Should(BeFalse())

kbVersion, _ = gv.NewVersion("0.6.0-alpha.23")
cliVersion, _ = gv.NewVersion("0.6.0-beta.23")
Expect(kbVersion.Equal(cliVersion)).Should(BeFalse())

kbVersion, _ = gv.NewVersion("0.6.3")
cliVersion, _ = gv.NewVersion("v0.6.3")
Expect(kbVersion.Equal(cliVersion)).Should(BeTrue())
})
})

0 comments on commit b82d0bc

Please sign in to comment.