Skip to content

Commit

Permalink
cni: fix plugin fingerprinting versions (#16776) (#16952)
Browse files Browse the repository at this point in the history
CNI plugins v1.2.0 and above output a second line, containing supported protocol versions.

Co-authored-by: Etienne Bruines <etienne@bruines.com>
  • Loading branch information
hc-github-team-nomad-core and EtienneBruines committed Apr 21, 2023
1 parent b1a67eb commit 93d1744
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
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 @@ -101,9 +101,9 @@ func (f *PluginsCNIFingerprint) detectOne(cniPath string, entry os.DirEntry) (st
// 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
2 changes: 2 additions & 0 deletions client/fingerprint/plugins_cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,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_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"

0 comments on commit 93d1744

Please sign in to comment.