From 18d618026cb48b53ecb77a445cb9d15b02647707 Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Wed, 6 Dec 2023 08:27:16 +0100 Subject: [PATCH 1/2] use released inspektor version Signed-off-by: Matthias Bertschy --- go.mod | 4 +--- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 7999d1a8..902de341 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb github.com/google/uuid v1.4.0 github.com/goradd/maps v0.1.5 - github.com/inspektor-gadget/inspektor-gadget v0.23.0 + github.com/inspektor-gadget/inspektor-gadget v0.23.1 github.com/kinbiko/jsonassert v1.1.1 github.com/kubescape/backend v0.0.16 github.com/kubescape/go-logger v0.0.22 @@ -178,6 +178,4 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) -replace github.com/inspektor-gadget/inspektor-gadget => github.com/matthyx/inspektor-gadget v0.0.0-20231205083843-79c7eeb32c4f - replace github.com/vishvananda/netns => github.com/inspektor-gadget/netns v0.0.5-0.20230524185006-155d84c555d6 diff --git a/go.sum b/go.sum index 8e626568..5de34ac8 100644 --- a/go.sum +++ b/go.sum @@ -283,6 +283,8 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inspektor-gadget/inspektor-gadget v0.23.1 h1:lAo+6I79E7qYVkeoi1IhDviLjG9IbFK75JVIM0RfFBw= +github.com/inspektor-gadget/inspektor-gadget v0.23.1/go.mod h1:ciFeohyRWA1ZFnv2SdDVUAg3KclJsa1ZGiXqhL2rC5g= github.com/inspektor-gadget/netns v0.0.5-0.20230524185006-155d84c555d6 h1:fQqkJ+WkYfzy6BoUh32fr9uYrXfOGtsfw0skMQkfOic= github.com/inspektor-gadget/netns v0.0.5-0.20230524185006-155d84c555d6/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= @@ -325,8 +327,6 @@ github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3v github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/matthyx/inspektor-gadget v0.0.0-20231205083843-79c7eeb32c4f h1:FL8uxq1zH13tUmjmBoaZOAlNrskB6u5RWhJ46ap7x1A= -github.com/matthyx/inspektor-gadget v0.0.0-20231205083843-79c7eeb32c4f/go.mod h1:ciFeohyRWA1ZFnv2SdDVUAg3KclJsa1ZGiXqhL2rC5g= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= From 4f824763bee8a7b0beaf763e4cef7e7a3ec41faf Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Wed, 6 Dec 2023 08:27:41 +0100 Subject: [PATCH 2/2] add wlid annotation to networkneighbors Signed-off-by: Matthias Bertschy --- pkg/networkmanager/network_manager.go | 4 ++-- pkg/networkmanager/network_neighbors.go | 3 ++- pkg/networkmanager/network_neighbors_test.go | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/networkmanager/network_manager.go b/pkg/networkmanager/network_manager.go index ead2a65a..4eca94ba 100644 --- a/pkg/networkmanager/network_manager.go +++ b/pkg/networkmanager/network_manager.go @@ -182,7 +182,7 @@ func (am *NetworkManager) handleContainerStarted(ctx context.Context, container logger.L().Warning("NetworkManager - failed to get network neighbor", helpers.String("reason", err.Error()), helpers.String("container ID", container.Runtime.ContainerID), helpers.String("k8s workload", k8sContainerID)) } else { // network neighbor not found, create new one - newNetworkNeighbors := generateNetworkNeighborsCRD(parentWL, selector) + newNetworkNeighbors := generateNetworkNeighborsCRD(parentWL, selector, am.clusterName) if err = am.storageClient.CreateNetworkNeighbors(newNetworkNeighbors, parentWL.GetNamespace()); err != nil { logger.L().Warning("NetworkManager - failed to create network neighbor", helpers.String("reason", err.Error()), helpers.String("container ID", container.Runtime.ContainerID), helpers.String("k8s workload", k8sContainerID)) @@ -338,7 +338,7 @@ func (am *NetworkManager) handleNetworkEvents(ctx context.Context, container *co logger.L().Warning("NetworkManager - failed to get selector", helpers.String("reason", err.Error()), helpers.String("container ID", container.Runtime.ContainerID), helpers.String("parent wlid", parentWlid)) return } - newNetworkNeighbors := generateNetworkNeighborsCRD(parentWL, selector) + newNetworkNeighbors := generateNetworkNeighborsCRD(parentWL, selector, am.clusterName) // update spec and annotations networkNeighborsSpec.LabelSelector = *selector diff --git a/pkg/networkmanager/network_neighbors.go b/pkg/networkmanager/network_neighbors.go index 676c28f7..787c27ed 100644 --- a/pkg/networkmanager/network_neighbors.go +++ b/pkg/networkmanager/network_neighbors.go @@ -17,7 +17,7 @@ const ( incompleteStatus = "incomplete" ) -func generateNetworkNeighborsCRD(parentWorkload k8sinterface.IWorkload, parentWorkloadSelector *metav1.LabelSelector) *v1beta1.NetworkNeighbors { +func generateNetworkNeighborsCRD(parentWorkload k8sinterface.IWorkload, parentWorkloadSelector *metav1.LabelSelector, clusterName string) *v1beta1.NetworkNeighbors { if parentWorkloadSelector.MatchLabels == nil && parentWorkloadSelector.MatchExpressions == nil { parentWorkloadSelector.MatchLabels = parentWorkload.GetLabels() } @@ -29,6 +29,7 @@ func generateNetworkNeighborsCRD(parentWorkload k8sinterface.IWorkload, parentWo }, ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ + instanceidhandler.WlidMetadataKey: parentWorkload.GenerateWlid(clusterName), instanceidhandler.StatusMetadataKey: incompleteStatus, }, Name: generateNetworkNeighborsNameFromWorkload(parentWorkload), diff --git a/pkg/networkmanager/network_neighbors_test.go b/pkg/networkmanager/network_neighbors_test.go index dc5b5639..36f8bdfd 100644 --- a/pkg/networkmanager/network_neighbors_test.go +++ b/pkg/networkmanager/network_neighbors_test.go @@ -44,6 +44,7 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) { }, ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ + instanceidhandlerV1.WlidMetadataKey: "wlid://cluster-minikube/namespace-default/deployment-nginx-deployment", instanceidhandlerV1.StatusMetadataKey: "incomplete", }, Name: "deployment-nginx-deployment", @@ -79,6 +80,7 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) { }, ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ + instanceidhandlerV1.WlidMetadataKey: "wlid://cluster-minikube/namespace-kube-system/daemonset-fluentd-elasticsearch", instanceidhandlerV1.StatusMetadataKey: "incomplete", }, Name: "daemonset-fluentd-elasticsearch", @@ -114,6 +116,7 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) { }, ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ + instanceidhandlerV1.WlidMetadataKey: "wlid://cluster-minikube/namespace-default/pod-nginx-deployment-fcc867f7-dgjrg", instanceidhandlerV1.StatusMetadataKey: "incomplete", }, Name: "pod-nginx-deployment-fcc867f7-dgjrg", @@ -146,7 +149,7 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) { selector, err := wl.GetSelector() assert.Nil(t, err) - actualNetworkNeighbors := generateNetworkNeighborsCRD(wl, selector) + actualNetworkNeighbors := generateNetworkNeighborsCRD(wl, selector, "minikube") assert.Equal(t, test.expectedNetworkNeighbors, actualNetworkNeighbors) }) }