MCPcopy Create free account
hub / github.com/cozystack/cozystack / majorityShard

Function majorityShard

internal/fluxshardoperator/controller.go:223–240  ·  view source on GitHub ↗

majorityShard returns the most common canonical shard value among the tenant's HelmRelease labels, tie-break lowest shard index. Legacy "tenants" and unparseable values count as unassigned.

(hrs []*metav1.PartialObjectMetadata)

Source from the content-addressed store, hash-verified

221// tenant's HelmRelease labels, tie-break lowest shard index. Legacy "tenants"
222// and unparseable values count as unassigned.
223func majorityShard(hrs []*metav1.PartialObjectMetadata) string {
224 counts := map[int]int{}
225 for _, hr := range hrs {
226 if idx, ok := ParseShardIndex(hr.GetLabels()[ShardKeyLabel]); ok {
227 counts[idx]++
228 }
229 }
230 best, bestCount := -1, 0
231 for idx, c := range counts {
232 if c > bestCount || (c == bestCount && best >= 0 && idx < best) {
233 best, bestCount = idx, c
234 }
235 }
236 if best < 0 {
237 return ""
238 }
239 return ShardName(best)
240}
241
242// observeShards reports which shard Deployments currently have a ready
243// replica, and how many shards are provisioned (the auto-sizing hysteresis

Callers 1

gatherMethod · 0.85

Calls 2

ParseShardIndexFunction · 0.85
ShardNameFunction · 0.85

Tested by

no test coverage detected