Skip to content

Commit

Permalink
bugfix discoverer nil map reference (#745)
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
  • Loading branch information
Yusuke Kato committed Oct 6, 2020
1 parent 133f0ab commit ac37341
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/discoverer/k8s/service/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,12 @@ func (d *discoverer) Start(ctx context.Context) (<-chan error, error) {
})
podsByNode[nodeName][namespace][appName] = p
nn, ok := nodeByName[nodeName]
if !ok {
if !ok || nn == nil {
nodeByName[nodeName] = new(payload.Info_Node)
nn, ok = nodeByName[nodeName]
if !ok {
continue
}
}
if nn.Pods == nil {
nodeByName[nodeName].Pods = new(payload.Info_Pods)
Expand All @@ -315,6 +319,8 @@ func (d *discoverer) Start(ctx context.Context) (<-chan error, error) {
nodeByName[nodeName].Pods.Pods = p
}
}
d.nodeByName.Store(nodeByName)
d.podsByNode.Store(podsByNode)
return nil
}))
wg.Add(1)
Expand All @@ -328,6 +334,7 @@ func (d *discoverer) Start(ctx context.Context) (<-chan error, error) {
podsByNamespace[namespace][appName] = p
}
}
d.podsByNamespace.Store(podsByNamespace)
return nil
}))
wg.Add(1)
Expand All @@ -339,14 +346,10 @@ func (d *discoverer) Start(ctx context.Context) (<-chan error, error) {
})
podsByName[appName] = p
}
d.podsByName.Store(podsByName)
return nil
}))
wg.Wait()

d.podsByNode.Store(podsByNode)
d.podsByNamespace.Store(podsByNamespace)
d.podsByName.Store(podsByName)
d.nodeByName.Store(nodeByName)
case err = <-dech:
if err != nil {
ech <- err
Expand Down

0 comments on commit ac37341

Please sign in to comment.