diff --git a/CHANGELOG.md b/CHANGELOG.md index e2d7b39c0767..43636a26ed2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ Main (unreleased) - Add an option to the windows static mode installer for expanding environment vars in the yaml config. (@erikbaranowski) +- Sort kubelet endpoint to reduce pressure on K8s's API server and watcher endpoints. (@hainenber) + ### Bugfixes - Fix an issue in `remote.s3` where the exported content of an object would be an empty string if `remote.s3` failed to fully retrieve 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 }