From a4df25e5e6a2ba5dd36bd22d191983b53155bc19 Mon Sep 17 00:00:00 2001 From: Austin Vazquez Date: Fri, 29 Nov 2024 19:35:41 +0000 Subject: [PATCH] Fix plugin supported CNI versions Before this change, plugin version 1.0.0 was not being reported as supported after version 1.1.0 became the current version. Signed-off-by: Austin Vazquez --- cmd/tc-redirect-tap/main.go | 3 +- internal/supported_versions.go | 32 +++++++++++++++++++++ internal/supported_versions_test.go | 43 +++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 internal/supported_versions.go create mode 100644 internal/supported_versions_test.go diff --git a/cmd/tc-redirect-tap/main.go b/cmd/tc-redirect-tap/main.go index 5f816bc..d65c1c9 100644 --- a/cmd/tc-redirect-tap/main.go +++ b/cmd/tc-redirect-tap/main.go @@ -40,8 +40,7 @@ func main() { Check: check, Del: del, }, - // support CNI versions that support plugin chaining - version.PluginSupports("0.3.0", "0.3.1", "0.4.0", version.Current()), + version.PluginSupports(internal.SupportedVersions()...), buildversion.BuildString("tc-redirect-tap"), ) } diff --git a/internal/supported_versions.go b/internal/supported_versions.go new file mode 100644 index 0000000..01a4a2c --- /dev/null +++ b/internal/supported_versions.go @@ -0,0 +1,32 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package internal + +import ( + "github.com/containernetworking/cni/pkg/version" +) + +func SupportedVersions() []string { + // support CNI versions that support plugin chaining + supported := []string{} + unsupported := map[string]bool{"0.1.0": true, "0.2.0": true} + + for _, v := range version.All.SupportedVersions() { + if _, ok := unsupported[v]; !ok { + supported = append(supported, v) + } + } + + return supported +} diff --git a/internal/supported_versions_test.go b/internal/supported_versions_test.go new file mode 100644 index 0000000..e221f65 --- /dev/null +++ b/internal/supported_versions_test.go @@ -0,0 +1,43 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package internal + +import ( + "testing" +) + +func TestSupportedVersions(t *testing.T) { + supportedVersions := SupportedVersions() + + contains := func(arr []string, find string) bool { + for _, i := range arr { + if i == find { + return true + } + } + return false + } + + for _, v := range []string{"0.1.0", "0.2.0"} { + if contains(supportedVersions, v) { + t.Errorf("expected %s to not be a supported version", v) + } + } + + for _, v := range []string{"0.3.0", "0.3.1", "0.4.0", "1.0.0", "1.1.0"} { + if !contains(supportedVersions, v) { + t.Errorf("expected %s to be a supported version", v) + } + } +}