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)
| 221 | // tenant's HelmRelease labels, tie-break lowest shard index. Legacy "tenants" |
| 222 | // and unparseable values count as unassigned. |
| 223 | func 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 |
no test coverage detected