Skip to content

Commit

Permalink
Merge pull request #157 from kubescape/wlid
Browse files Browse the repository at this point in the history
add wlid annotation to networkneighbors
  • Loading branch information
matthyx authored Dec 6, 2023
2 parents f645867 + 4f82476 commit 1667a68
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkmanager/network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/networkmanager/network_neighbors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion pkg/networkmanager/network_neighbors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
})
}
Expand Down

0 comments on commit 1667a68

Please sign in to comment.