Skip to content

Commit

Permalink
Use contains instead of exact match for cniPlugins (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfisher authored Mar 28, 2023
1 parent 85e6a99 commit 5c7fc53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cluster/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
import (
"fmt"
"strconv"
"strings"
)

// NewIndex builds a new empty index for PodInfo.
Expand Down Expand Up @@ -181,7 +182,13 @@ func IsCNIPlugin(n string) bool {
"sdn": true,
}

return m[n]
for k := range m {
if strings.Contains(n, k) {
return true
}
}

return false
}

type Counter map[string]int
Expand Down
16 changes: 16 additions & 0 deletions cluster/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,19 @@ func Test_Count_Pod_Status(t *testing.T) {
}
gunit.Number(t, index.PodStatus[""]).EqualTo(4)
}

func Test_IsCNIPlugin(t *testing.T) {
td := map[string]struct {
expected bool
}{
"instana-agent": {false},
"kube-flannel-ds-kdwch": {true},
"aws-node": {true},
}

for n, tc := range td {
t.Run(n, func(t *testing.T) {
gunit.Struct(t, cluster.IsCNIPlugin(n)).EqualTo(tc.expected)
})
}
}

0 comments on commit 5c7fc53

Please sign in to comment.