cni: fix plugin fingerprinting versions (#16776)

CNI plugins v1.2.0 and above output a second line, containing supported protocol versions.
This commit is contained in:
Etienne Bruines 2023-04-21 03:44:39 +02:00 committed by GitHub
parent a1ba068e1f
commit 1e3531b978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 2 deletions

3
.changelog/16776.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
client: Fix CNI plugin version fingerprint when output includes protocol version
```

View File

@ -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
}

View File

@ -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) {
@ -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) {

View File

@ -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"

View File

@ -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"