Skip to content

Commit

Permalink
Handle cases of missing node name when (re)adding collector
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Gera <[email protected]>
  • Loading branch information
matej-g committed Jan 5, 2024
1 parent a5ede06 commit 7d57502
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/otel-allocator/allocation/per_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ func (allocator *perNodeAllocator) handleCollectors(diff diff.Changes[*Collector
for _, i := range diff.Additions() {
allocator.collectors[i.NodeName] = NewCollector(i.Name, i.NodeName)
}

// For a case where a collector is removed and added back, we need
// to re-allocate any already existing targets.
for _, item := range allocator.targetItems {
allocator.addTargetToTargetItems(item)
}
}

// SetTargets accepts a list of targets that will be used to make
Expand Down
5 changes: 5 additions & 0 deletions cmd/otel-allocator/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func runWatch(ctx context.Context, k *Client, c <-chan watch.Event, collectorMap
return ""
}

if pod.Spec.NodeName == "" {
k.log.Info("Node name is missing from the spec. Restarting watch routine")
return ""
}

switch event.Type { //nolint:exhaustive
case watch.Added:
collectorMap[pod.Name] = allocation.NewCollector(pod.Name, pod.Spec.NodeName)
Expand Down

0 comments on commit 7d57502

Please sign in to comment.