Skip to content

Commit cc251ca

Browse files
authored
fix: assume invalid semver CNI has the required dump state command (#2078)
1 parent ce0e06c commit cc251ca

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

cni/client/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import (
1111
"github.com/Azure/azure-container-networking/log"
1212
"github.com/Azure/azure-container-networking/platform"
1313
semver "github.com/hashicorp/go-version"
14+
"github.com/pkg/errors"
1415
utilexec "k8s.io/utils/exec"
1516
)
1617

1718
type client struct {
1819
exec utilexec.Interface
1920
}
2021

22+
var ErrSemVerParse = errors.New("error parsing version")
23+
2124
func New(exec utilexec.Interface) *client {
2225
return &client{exec: exec}
2326
}
@@ -58,5 +61,10 @@ func (c *client) GetVersion() (*semver.Version, error) {
5861
return nil, fmt.Errorf("Unexpected Azure CNI Version formatting: %v", output)
5962
}
6063

61-
return semver.NewVersion(res[3])
64+
version, versionErr := semver.NewVersion(res[3])
65+
if versionErr != nil {
66+
return nil, errors.Wrap(ErrSemVerParse, versionErr.Error())
67+
}
68+
69+
return version, nil
6270
}

cns/cnireconciler/version.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/Azure/azure-container-networking/cni/client"
77
semver "github.com/hashicorp/go-version"
8+
"github.com/pkg/errors"
89
"k8s.io/utils/exec"
910
)
1011

@@ -15,7 +16,9 @@ const lastCNIWithoutDumpStateVer = "1.4.6"
1516
// IsDumpStateVer checks if the CNI executable is a version that
1617
// has the dump state command required to initialize CNS from CNI
1718
// state and returns the result of that test or an error. Will always
18-
// return false when there is an error.
19+
// return false when there is an error unless the error was caused
20+
// by the CNI not being a semver, in which case we'll assume we can
21+
// use the command.
1922
func IsDumpStateVer() (bool, error) {
2023
return isDumpStateVer(exec.New())
2124
}
@@ -28,6 +31,11 @@ func isDumpStateVer(exec exec.Interface) (bool, error) {
2831
cnicli := client.New(exec)
2932
ver, err := cnicli.GetVersion()
3033
if err != nil {
34+
// If the error was that the CNI isn't a valid semver, assume we have the
35+
// the dump state command
36+
if errors.Is(err, client.ErrSemVerParse) {
37+
return true, nil
38+
}
3139
return false, fmt.Errorf("failed to invoke CNI client.GetVersion(): %w", err)
3240
}
3341
return ver.GreaterThan(needVer), nil

cns/cnireconciler/version_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ func TestIsDumpStateVer(t *testing.T) {
4848
want: true,
4949
wantErr: false,
5050
},
51+
{
52+
name: "non-semver",
53+
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.35_Win2019OverlayFix`),
54+
want: true,
55+
wantErr: false,
56+
},
57+
{
58+
name: "non-semver hotfix ver",
59+
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.44.4`),
60+
want: true,
61+
wantErr: false,
62+
},
5163
}
5264
for _, tt := range tests {
5365
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)