Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: assume invalid semver CNI has the required dump state command #2078

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cni/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import (
"github.com/Azure/azure-container-networking/log"
"github.com/Azure/azure-container-networking/platform"
semver "github.com/hashicorp/go-version"
"github.com/pkg/errors"
utilexec "k8s.io/utils/exec"
)

type client struct {
exec utilexec.Interface
}

var ErrSemVerParse = errors.New("error parsing version")

func New(exec utilexec.Interface) *client {
return &client{exec: exec}
}
Expand Down Expand Up @@ -58,5 +61,10 @@ func (c *client) GetVersion() (*semver.Version, error) {
return nil, fmt.Errorf("Unexpected Azure CNI Version formatting: %v", output)
}

return semver.NewVersion(res[3])
version, versionErr := semver.NewVersion(res[3])
if versionErr != nil {
return nil, errors.Wrap(ErrSemVerParse, versionErr.Error())
}

return version, nil
}
10 changes: 9 additions & 1 deletion cns/cnireconciler/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/Azure/azure-container-networking/cni/client"
semver "github.com/hashicorp/go-version"
"github.com/pkg/errors"
"k8s.io/utils/exec"
)

Expand All @@ -15,7 +16,9 @@ const lastCNIWithoutDumpStateVer = "1.4.6"
// IsDumpStateVer checks if the CNI executable is a version that
// has the dump state command required to initialize CNS from CNI
// state and returns the result of that test or an error. Will always
// return false when there is an error.
// return false when there is an error unless the error was caused
// by the CNI not being a semver, in which case we'll assume we can
// use the command.
func IsDumpStateVer() (bool, error) {
return isDumpStateVer(exec.New())
}
Expand All @@ -28,6 +31,11 @@ func isDumpStateVer(exec exec.Interface) (bool, error) {
cnicli := client.New(exec)
ver, err := cnicli.GetVersion()
if err != nil {
// If the error was that the CNI isn't a valid semver, assume we have the
// the dump state command
if errors.Is(err, client.ErrSemVerParse) {
return true, nil
}
return false, fmt.Errorf("failed to invoke CNI client.GetVersion(): %w", err)
}
return ver.GreaterThan(needVer), nil
Expand Down
12 changes: 12 additions & 0 deletions cns/cnireconciler/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ func TestIsDumpStateVer(t *testing.T) {
want: true,
wantErr: false,
},
{
name: "non-semver",
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.35_Win2019OverlayFix`),
want: true,
wantErr: false,
},
{
name: "non-semver hotfix ver",
exec: newCNIVersionFakeExec(`Azure CNI Version v1.4.44.4`),
want: true,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down