From 7d575026d767dcaae6b259ebc9c07e882448efda Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Thu, 4 Jan 2024 17:15:27 +0100 Subject: [PATCH] Handle cases of missing node name when (re)adding collector Signed-off-by: Matej Gera --- cmd/otel-allocator/allocation/per_node.go | 6 ++++++ cmd/otel-allocator/collector/collector.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/cmd/otel-allocator/allocation/per_node.go b/cmd/otel-allocator/allocation/per_node.go index ab7012e157..376036d1e8 100644 --- a/cmd/otel-allocator/allocation/per_node.go +++ b/cmd/otel-allocator/allocation/per_node.go @@ -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 diff --git a/cmd/otel-allocator/collector/collector.go b/cmd/otel-allocator/collector/collector.go index d5fdc49bea..58bbbee866 100644 --- a/cmd/otel-allocator/collector/collector.go +++ b/cmd/otel-allocator/collector/collector.go @@ -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)