diff --git a/app/api_topologies_test.go b/app/api_topologies_test.go index 6e6945effa..54aabae555 100644 --- a/app/api_topologies_test.go +++ b/app/api_topologies_test.go @@ -83,6 +83,9 @@ func TestAPITopologyAddsKubernetes(t *testing.T) { {ContainerID: "container2"}, }, }, + Spec: api.PodSpec{ + SecurityContext: &api.PodSecurityContext{}, + }, }).GetNode("") buf := &bytes.Buffer{} encoder := codec.NewEncoder(buf, &codec.MsgpackHandle{}) diff --git a/probe/kubernetes/pod.go b/probe/kubernetes/pod.go index a5c5f9f5b4..5d79ae773b 100644 --- a/probe/kubernetes/pod.go +++ b/probe/kubernetes/pod.go @@ -64,7 +64,7 @@ func (p *pod) GetNode(probeID string) report.Node { report.ControlProbeID: probeID, } - if p.Pod.Spec.SecurityContext.HostNetwork { + if sc := p.Pod.Spec.SecurityContext; sc != nil && sc.HostNetwork { latests[IsInHostNetwork] = "true" } diff --git a/probe/kubernetes/reporter_test.go b/probe/kubernetes/reporter_test.go index 8d5117616e..5cd6180ffe 100644 --- a/probe/kubernetes/reporter_test.go +++ b/probe/kubernetes/reporter_test.go @@ -46,6 +46,9 @@ var ( }, Spec: api.PodSpec{ NodeName: nodeName, + SecurityContext: &api.PodSecurityContext{ + HostNetwork: true, + }, }, } apiPod2 = api.Pod{ @@ -65,7 +68,8 @@ var ( }, }, Spec: api.PodSpec{ - NodeName: nodeName, + NodeName: nodeName, + SecurityContext: &api.PodSecurityContext{}, }, } apiService1 = api.Service{