From 1c0c8b59423296d7ab970ba1d5612ba9a21f1b96 Mon Sep 17 00:00:00 2001 From: hainenber Date: Sat, 9 Dec 2023 20:39:34 +0700 Subject: [PATCH] feat(pkg/operator): sort endpoints in reconciler for better perf Signed-off-by: hainenber --- CHANGELOG.md | 2 ++ pkg/operator/kubelet.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e08d1682dbd1..ef2e790d3365 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,8 @@ Main (unreleased) - Fixes `loki.source.docker` a behavior that synced an incomplete list of targets to the tailer manager. (@FerdinandvHagen) +- Sort kubelet endpoint to reduce pressure on K8s's API server and watcher endpoints. (@hainenber) + ### Other changes - Bump github.com/IBM/sarama from v1.41.2 to v1.42.1 diff --git a/pkg/operator/kubelet.go b/pkg/operator/kubelet.go index c04c6887f746..9ecff4f9bc8a 100644 --- a/pkg/operator/kubelet.go +++ b/pkg/operator/kubelet.go @@ -3,6 +3,7 @@ package operator import ( "context" "fmt" + "sort" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -126,6 +127,12 @@ func getNodeAddrs(l log.Logger, nodes *core_v1.NodeList) (addrs []core_v1.Endpoi if failed { return nil, fmt.Errorf("failed to get the address from one or more nodes") } + + // Sort endpoints to reduce performance cost on endpoint watchers + sort.SliceStable(addrs, func(i, j int) bool { + return addrs[i].IP < addrs[j].IP + }) + return }