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

cni: fix plugin fingerprinting versions #16776

Merged
merged 3 commits into from
Apr 21, 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
3 changes: 3 additions & 0 deletions .changelog/16776.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
client: Fix CNI plugin version fingerprint when output includes protocol version
```
4 changes: 2 additions & 2 deletions client/fingerprint/plugins_cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func (f *PluginsCNIFingerprint) detectOnePlugin(pluginPath string, entry os.DirE
// e.g.
// /opt/cni/bin/bridge <no args>
// CNI bridge plugin v1.0.0
// (and optionally another line that contains the supported CNI protocol versions)
tokens := strings.Fields(string(output))
for i := len(tokens) - 1; i >= 0; i-- {
token := tokens[i]
for _, token := range tokens {
if _, parseErr := version.NewSemver(token); parseErr == nil {
return token, true
}
Expand Down
4 changes: 4 additions & 0 deletions client/fingerprint/plugins_cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ func TestPluginsCNIFingerprint_Fingerprint_present(t *testing.T) {
must.True(t, response.Detected)
attrCustom := f.(*PluginsCNIFingerprint).attribute("custom")
attrBridge := f.(*PluginsCNIFingerprint).attribute("bridge")
attrVlan := f.(*PluginsCNIFingerprint).attribute("vlan")
must.Eq(t, "v1.2.3", response.Attributes[attrCustom])
must.Eq(t, "v1.0.2", response.Attributes[attrBridge])
must.Eq(t, "v1.2.0", response.Attributes[attrVlan])
}

func TestPluginsCNIFingerprint_Fingerprint_multi(t *testing.T) {
Expand All @@ -49,10 +51,12 @@ func TestPluginsCNIFingerprint_Fingerprint_multi(t *testing.T) {
must.True(t, response.Detected)
attrCustom := f.(*PluginsCNIFingerprint).attribute("custom")
attrBridge := f.(*PluginsCNIFingerprint).attribute("bridge")
attrVlan := f.(*PluginsCNIFingerprint).attribute("vlan")
attrCustom2 := f.(*PluginsCNIFingerprint).attribute("custom2")
must.Eq(t, "v1.2.3", response.Attributes[attrCustom])
must.Eq(t, "v1.0.2", response.Attributes[attrBridge])
must.Eq(t, "v9.9.9", response.Attributes[attrCustom2])
must.Eq(t, "v1.2.0", response.Attributes[attrVlan])
}

func TestPluginsCNIFingerprint_Fingerprint_absent(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions client/fingerprint/test_fixtures/cni/bridge
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh

# This fixture uses the old version output, without the supported CNI protocol versions.
echo "CNI bridge plugin v1.0.2"
5 changes: 5 additions & 0 deletions client/fingerprint/test_fixtures/cni/vlan
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

# This fixture uses the new version output, including the supported CNI protocol versions.
echo "CNI vlan plugin v1.2.0"
echo "CNI protocol versions supported: 0.1.0, 0.2.0, 0.3.0, 0.3.1, 0.4.0, 1.0.0"