From 9444d162b40b6335064867f1e81732f5c411e42b Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Wed, 29 Nov 2023 16:20:59 +0100 Subject: [PATCH] keep group/version together in apiVersion label Signed-off-by: Matthias Bertschy --- go.mod | 2 +- go.sum | 4 ++-- pkg/networkmanager/network_neighbors.go | 12 +----------- pkg/networkmanager/network_neighbors_test.go | 14 ++++---------- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 8d529796..c9b0e5cb 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/kinbiko/jsonassert v1.1.1 github.com/kubescape/backend v0.0.13 github.com/kubescape/go-logger v0.0.21 - github.com/kubescape/k8s-interface v0.0.149 + github.com/kubescape/k8s-interface v0.0.150 github.com/kubescape/storage v0.0.38 github.com/panjf2000/ants/v2 v2.8.1 github.com/spf13/viper v1.17.0 diff --git a/go.sum b/go.sum index 6901f5fc..732cacf2 100644 --- a/go.sum +++ b/go.sum @@ -314,8 +314,8 @@ github.com/kubescape/backend v0.0.13 h1:N+fH8giGGqvy3ff2li2AwG5guVduhdiPWyvZaZxr github.com/kubescape/backend v0.0.13/go.mod h1:ug9NFmmxT4DcQx3sgdLRzlLPWMKGHE/fpbcYUm5G5Qo= github.com/kubescape/go-logger v0.0.21 h1:4ZRIEw3UGUH6BG/cH3yiqFipzQSfGAoCrxlsZuk37ys= github.com/kubescape/go-logger v0.0.21/go.mod h1:x3HBpZo3cMT/WIdy18BxvVVd5D0e/PWFVk/HiwBNu3g= -github.com/kubescape/k8s-interface v0.0.149 h1:wBgiajoviNA80y+sJFMkntwIVJ6gPZOuorT6gjqWHVM= -github.com/kubescape/k8s-interface v0.0.149/go.mod h1:5sz+5Cjvo98lTbTVDiDA4MmlXxeHSVMW/wR0V3hV4K8= +github.com/kubescape/k8s-interface v0.0.150 h1:6lLRuqUVirpOnobZUz+I1g1RnW4fk88zOO26492Pn9E= +github.com/kubescape/k8s-interface v0.0.150/go.mod h1:5sz+5Cjvo98lTbTVDiDA4MmlXxeHSVMW/wR0V3hV4K8= github.com/kubescape/storage v0.0.38 h1:LR+QTqjeYw4kM1repIltDLDQGqHgKmG196lQyHP+xUw= github.com/kubescape/storage v0.0.38/go.mod h1:ObCIVOnVyWwRwU0iuKTzOnrJQScqPgkw0FgvSINwosY= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0= diff --git a/pkg/networkmanager/network_neighbors.go b/pkg/networkmanager/network_neighbors.go index 676c28f7..32b01f0e 100644 --- a/pkg/networkmanager/network_neighbors.go +++ b/pkg/networkmanager/network_neighbors.go @@ -53,18 +53,8 @@ func generateNetworkNeighborsNameFromWlid(parentWlid string) string { } func generateNetworkNeighborsLabels(workload k8sinterface.IWorkload) map[string]string { - var apiVersion, apiGroup string - apiVersionSplitted := strings.Split(workload.GetApiVersion(), "/") - if len(apiVersionSplitted) == 2 { - apiGroup = apiVersionSplitted[0] - apiVersion = apiVersionSplitted[1] - } else if len(apiVersionSplitted) == 1 { - apiVersion = apiVersionSplitted[0] - } - return map[string]string{ - instanceidhandlerV1.ApiGroupMetadataKey: apiGroup, - instanceidhandlerV1.ApiVersionMetadataKey: apiVersion, + instanceidhandlerV1.ApiVersionMetadataKey: workload.GetApiVersion(), instanceidhandlerV1.NamespaceMetadataKey: workload.GetNamespace(), instanceidhandlerV1.KindMetadataKey: strings.ToLower(workload.GetKind()), instanceidhandlerV1.NameMetadataKey: workload.GetName(), diff --git a/pkg/networkmanager/network_neighbors_test.go b/pkg/networkmanager/network_neighbors_test.go index 2aa6f857..858bbf3d 100644 --- a/pkg/networkmanager/network_neighbors_test.go +++ b/pkg/networkmanager/network_neighbors_test.go @@ -46,8 +46,7 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) { Name: "deployment-nginx-deployment", Namespace: "default", Labels: map[string]string{ - "kubescape.io/workload-api-group": "apps", - "kubescape.io/workload-api-version": "v1", + "kubescape.io/workload-api-version": "apps/v1", "kubescape.io/workload-namespace": "default", "kubescape.io/workload-kind": "deployment", "kubescape.io/workload-name": "nginx-deployment", @@ -81,8 +80,7 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) { Name: "daemonset-fluentd-elasticsearch", Namespace: "kube-system", Labels: map[string]string{ - "kubescape.io/workload-api-group": "apps", - "kubescape.io/workload-api-version": "v1", + "kubescape.io/workload-api-version": "apps/v1", "kubescape.io/workload-namespace": "kube-system", "kubescape.io/workload-kind": "daemonset", "kubescape.io/workload-name": "fluentd-elasticsearch", @@ -116,7 +114,6 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) { Name: "pod-nginx-deployment-fcc867f7-dgjrg", Namespace: "default", Labels: map[string]string{ - "kubescape.io/workload-api-group": "", "kubescape.io/workload-api-version": "v1", "kubescape.io/workload-namespace": "default", "kubescape.io/workload-kind": "pod", @@ -228,8 +225,7 @@ func TestGenerateNetworkNeighborsLabels(t *testing.T) { name: "deployment", workload: deploymentJson, expectedLabels: map[string]string{ - "kubescape.io/workload-api-group": "apps", - "kubescape.io/workload-api-version": "v1", + "kubescape.io/workload-api-version": "apps/v1", "kubescape.io/workload-namespace": "default", "kubescape.io/workload-kind": "deployment", "kubescape.io/workload-name": "nginx-deployment", @@ -241,8 +237,7 @@ func TestGenerateNetworkNeighborsLabels(t *testing.T) { name: "daemonset", workload: daemonsetJson, expectedLabels: map[string]string{ - "kubescape.io/workload-api-group": "apps", - "kubescape.io/workload-api-version": "v1", + "kubescape.io/workload-api-version": "apps/v1", "kubescape.io/workload-namespace": "kube-system", "kubescape.io/workload-kind": "daemonset", "kubescape.io/workload-name": "fluentd-elasticsearch", @@ -254,7 +249,6 @@ func TestGenerateNetworkNeighborsLabels(t *testing.T) { name: "pod", workload: podJson, expectedLabels: map[string]string{ - "kubescape.io/workload-api-group": "", "kubescape.io/workload-api-version": "v1", "kubescape.io/workload-namespace": "default", "kubescape.io/workload-kind": "pod",