csi: Update version comparison model

If our supported version is still at 0.X.X, then check
also the minor number. If our supported version is >= 1.X.X
then check only the major number.

Closes #58813
pull/6/head
Luis Pabón 2018-01-26 07:26:57 -05:00
parent 7de1a8e0f5
commit 4abcb12296
2 changed files with 14 additions and 3 deletions

View File

@ -118,9 +118,15 @@ func (c *csiDriverClient) AssertSupportedVersion(ctx grpctx.Context, ver *csipb.
vers := rsp.GetSupportedVersions()
glog.V(4).Info(log("driver reports %d versions supported: %s", len(vers), versToStr(vers)))
// If our supported version is still at 0.X.X, then check
// also the minor number. If our supported version is >= 1.X.X
// then check only the major number.
for _, v := range vers {
//TODO (vladimirvivien) use more lenient/heuristic for exact or match of ranges etc
if verToStr(v) == verToStr(ver) {
if ver.GetMajor() == uint32(0) &&
(ver.GetMajor() == v.GetMajor() && ver.GetMinor() == v.GetMinor()) {
supported = true
break
} else if ver.GetMajor() != uint32(0) && ver.GetMajor() == v.GetMajor() {
supported = true
break
}

View File

@ -46,8 +46,13 @@ func TestClientAssertSupportedVersion(t *testing.T) {
mustFail bool
err error
}{
{testName: "supported version", ver: &csipb.Version{Major: 0, Minor: 0, Patch: 0}},
{testName: "supported version", ver: &csipb.Version{Major: 0, Minor: 1, Patch: 0}},
{testName: "unsupported version", ver: &csipb.Version{Major: 0, Minor: 0, Patch: 0}, mustFail: true},
{testName: "supported version", ver: &csipb.Version{Major: 0, Minor: 1, Patch: 10}},
{testName: "supported version", ver: &csipb.Version{Major: 1, Minor: 1, Patch: 0}},
{testName: "supported version", ver: &csipb.Version{Major: 1, Minor: 0, Patch: 10}},
{testName: "unsupported version", ver: &csipb.Version{Major: 10, Minor: 0, Patch: 0}, mustFail: true},
{testName: "unsupported version", ver: &csipb.Version{Major: 0, Minor: 10, Patch: 0}, mustFail: true},
{testName: "grpc error", ver: &csipb.Version{Major: 0, Minor: 1, Patch: 0}, mustFail: true, err: errors.New("grpc error")},
}