Skip to content

Commit

Permalink
Fixes issue with NCP versioning while using the semver package
Browse files Browse the repository at this point in the history
- If an NCP version with more than 3 segments is found, only use the first 3

Signed-off-by: gsatchi <gab.satchi@broadcom.com>
  • Loading branch information
gab-satchi committed Mar 4, 2024
1 parent a80aacd commit e6316bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/util/networkutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package util

import (
"context"
"strings"

"github.com/blang/semver/v4"
"github.com/pkg/errors"
Expand Down Expand Up @@ -90,6 +91,13 @@ func GetNCPVersion(ctx context.Context, controllerClient client.Client) (string,
}

version := configmapObj.Data[NCPVersionKey]

// NSX doesn't stritcly follow SemVer and there are versions like 4.0.1.3
// This will cause an error if directly used in semver.Parse() and prevent the cluster from reconciling.
// Since GetNCPVersion is only used to check >= 3.0.1 and < 3.1.0, it's safe to trim the last segment
if segments := strings.Split(version, "."); len(segments) > 3 {
version = strings.Join(segments[:3], ".")
}
return version, nil
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/util/networkutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ func TestNCPSupportFW(t *testing.T) {
true,
false,
},
{
"compatible version with more than 3 segments",
fake.NewClientBuilder().WithScheme(scheme).WithObjects(newNCPConfigMap("3.0.1.1.1")).Build(),
true,
false,
},
{
"incompatible version lower end",
fake.NewClientBuilder().WithScheme(scheme).WithObjects(newNCPConfigMap("3.0.0")).Build(),
Expand All @@ -74,6 +80,12 @@ func TestNCPSupportFW(t *testing.T) {
false,
false,
},
{
"incompatible version with more than 3 segments",
fake.NewClientBuilder().WithScheme(scheme).WithObjects(newNCPConfigMap("3.1.0.1")).Build(),
false,
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit e6316bb

Please sign in to comment.