Skip to content

Commit

Permalink
fix: Handle minor version with '+' when determining ingress mode (arg…
Browse files Browse the repository at this point in the history
…oproj#1529)

Signed-off-by: Kiran Meduri <[email protected]>
  • Loading branch information
kiranmeduri committed Oct 27, 2021
1 parent ac155f1 commit fc642ca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion utils/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,14 @@ func DetermineIngressMode(apiVersion string, d discovery.ServerVersionInterface)
}
minor, err := strconv.Atoi(ver.Minor)
if err != nil {
return 0, err
if strings.HasSuffix(ver.Minor, "+") {
minor, err = strconv.Atoi(ver.Minor[0 : len(ver.Minor)-1])
if err != nil {
return 0, err
}
} else {
return 0, err
}
}
if major > 1 {
return IngressModeNetworking, nil
Expand Down
28 changes: 28 additions & 0 deletions utils/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ func TestDetermineIngressMode(t *testing.T) {
faKeDiscovery: newFakeDiscovery("1", "18", nil),
expectedMode: IngressModeExtensions,
},
{
name: "will return networking mode if server minor version has '+' suffix, e.g. 1.19+",
apiVersion: "",
faKeDiscovery: newFakeDiscovery("1", "19+", nil),
expectedMode: IngressModeNetworking,
},
{
name: "will return error if fails to retrieve server version",
apiVersion: "",
Expand Down Expand Up @@ -358,6 +364,28 @@ func TestDetermineIngressMode(t *testing.T) {
Err: errors.New("invalid syntax"),
},
},
{
name: "will return error if fails to parse minor version with '+' suffix, e.g. 1.wrong+",
apiVersion: "",
faKeDiscovery: newFakeDiscovery("1", "wrong+", nil),
expectedMode: 0,
expectedError: &strconv.NumError{
Func: "Atoi",
Num: "wrong",
Err: errors.New("invalid syntax"),
},
},
{
name: "will return error if fails to parse minor version with just '+'",
apiVersion: "",
faKeDiscovery: newFakeDiscovery("1", "+", nil),
expectedMode: 0,
expectedError: &strconv.NumError{
Func: "Atoi",
Num: "",
Err: errors.New("invalid syntax"),
},
},
}
for _, c := range cases {
c := c // necessary to ensure all test cases are executed when running in parallel mode
Expand Down

0 comments on commit fc642ca

Please sign in to comment.