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) (argoproj#1612)

Signed-off-by: Kiran Meduri <[email protected]>
  • Loading branch information
kiranmeduri authored and danielm-codefresh committed Mar 9, 2022
1 parent dbdaf07 commit cc7a3c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions utils/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ func DetermineIngressMode(apiVersion string, d discovery.ServerVersionInterface)
if err != nil {
return 0, err
}
minor, err := strconv.Atoi(ver.Minor)
verMinor := ver.Minor
if strings.HasSuffix(ver.Minor, "+") {
verMinor = ver.Minor[0 : len(ver.Minor)-1]
}
minor, err := strconv.Atoi(verMinor)
if err != nil {
return 0, err
}
Expand All @@ -286,5 +290,4 @@ func DetermineIngressMode(apiVersion string, d discovery.ServerVersionInterface)
return IngressModeNetworking, nil
}
return IngressModeExtensions, nil

}
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 cc7a3c4

Please sign in to comment.