Skip to content

Commit

Permalink
Merge pull request #99 from austinvazquez/fix-version-checks
Browse files Browse the repository at this point in the history
Fix plugin supported CNI versions
  • Loading branch information
sondavidb authored Jan 10, 2025
2 parents c5566df + a4df25e commit f2644ce
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cmd/tc-redirect-tap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
}
Expand Down
32 changes: 32 additions & 0 deletions internal/supported_versions.go
Original file line number Diff line number Diff line change
@@ -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
}
43 changes: 43 additions & 0 deletions internal/supported_versions_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit f2644ce

Please sign in to comment.