Skip to content

Commit

Permalink
feat(pkg/operator): sort endpoints in reconciler for better perf
Browse files Browse the repository at this point in the history
Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber committed Dec 9, 2023
1 parent 9a10fff commit 1c0c8b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pkg/operator/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package operator
import (
"context"
"fmt"
"sort"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 1c0c8b5

Please sign in to comment.