Skip to content

Commit c8ebef9

Browse files
authored
Merge pull request #2797 from k8s-infra-cherrypick-robot/cherry-pick-2796-to-release-1.9
[release-1.9] 🐛 Fixes issue with NCP versioning while using the semver package
2 parents bcc72ca + 5c5d0d8 commit c8ebef9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/util/networkutil.go

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package util
1818

1919
import (
2020
"context"
21+
"strings"
2122

2223
"github.com/blang/semver/v4"
2324
"github.com/pkg/errors"
@@ -78,6 +79,7 @@ func GetNamespaceNetSnatIP(ctx context.Context, controllerClient client.Client,
7879
}
7980

8081
// GetNCPVersion finds out the running ncp's version from its configmap.
82+
// If the version contains more than 3 segments, it will get trimmed down to 3.
8183
func GetNCPVersion(ctx context.Context, controllerClient client.Client) (string, error) {
8284
configmapObj := &corev1.ConfigMap{}
8385
namespacedName := apitypes.NamespacedName{
@@ -90,6 +92,13 @@ func GetNCPVersion(ctx context.Context, controllerClient client.Client) (string,
9092
}
9193

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

pkg/util/networkutil_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ func TestNCPSupportFW(t *testing.T) {
6262
true,
6363
false,
6464
},
65+
{
66+
"compatible version with more than 3 segments",
67+
fake.NewClientBuilder().WithScheme(scheme).WithObjects(newNCPConfigMap("3.0.1.1.1")).Build(),
68+
true,
69+
false,
70+
},
6571
{
6672
"incompatible version lower end",
6773
fake.NewClientBuilder().WithScheme(scheme).WithObjects(newNCPConfigMap("3.0.0")).Build(),
@@ -74,6 +80,12 @@ func TestNCPSupportFW(t *testing.T) {
7480
false,
7581
false,
7682
},
83+
{
84+
"incompatible version with more than 3 segments",
85+
fake.NewClientBuilder().WithScheme(scheme).WithObjects(newNCPConfigMap("3.1.0.1")).Build(),
86+
false,
87+
false,
88+
},
7789
}
7890
for _, tt := range tests {
7991
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)