From 5c7fc534b003ca459e22f2db3916bb5521485653 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Tue, 28 Mar 2023 08:48:59 -0400 Subject: [PATCH] Use contains instead of exact match for cniPlugins (#11) --- cluster/index.go | 9 ++++++++- cluster/index_test.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cluster/index.go b/cluster/index.go index c13245c..2dd3c77 100644 --- a/cluster/index.go +++ b/cluster/index.go @@ -3,6 +3,7 @@ package cluster import ( "fmt" "strconv" + "strings" ) // NewIndex builds a new empty index for PodInfo. @@ -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 diff --git a/cluster/index_test.go b/cluster/index_test.go index 4c19b16..78a11f1 100644 --- a/cluster/index_test.go +++ b/cluster/index_test.go @@ -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) + }) + } +}