-
Notifications
You must be signed in to change notification settings - Fork 14
/
generator.go
763 lines (653 loc) · 19.1 KB
/
generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
package sabakan
import (
"errors"
"sort"
"strconv"
"strings"
"time"
"github.com/cybozu-go/cke"
"github.com/cybozu-go/cke/op"
"github.com/cybozu-go/log"
corev1 "k8s.io/api/core/v1"
)
var (
errNotAvailable = errors.New("no healthy machine is available")
errMissingMachine = errors.New("failed to apply new template due to missing machines")
errTooManyNonExistent = errors.New("too many non-existent control plane nodes")
// DefaultWaitRetiredSeconds before removing retired nodes from the cluster.
DefaultWaitRetiredSeconds = 300.0
)
// MachineToNode converts sabakan.Machine to cke.Node.
// Add taints, labels, and annotations according to the rules:
// - https://github.com/cybozu-go/cke/blob/main/docs/sabakan-integration.md#taint-nodes
// - https://github.com/cybozu-go/cke/blob/main/docs/sabakan-integration.md#node-labels
// - https://github.com/cybozu-go/cke/blob/main/docs/sabakan-integration.md#node-annotations
func MachineToNode(m *Machine, tmpl *cke.Node) *cke.Node {
n := &cke.Node{
Address: m.Spec.IPv4[0],
User: tmpl.User,
ControlPlane: tmpl.ControlPlane,
Annotations: make(map[string]string),
Labels: make(map[string]string),
}
for k, v := range tmpl.Annotations {
n.Annotations[k] = v
}
n.Annotations["cke.cybozu.com/serial"] = m.Spec.Serial
n.Annotations["cke.cybozu.com/register-date"] = m.Spec.RegisterDate.Format(time.RFC3339)
n.Annotations["cke.cybozu.com/retire-date"] = m.Spec.RetireDate.Format(time.RFC3339)
for _, label := range m.Spec.Labels {
n.Labels["sabakan.cke.cybozu.com/"+label.Name] = label.Value
}
for k, v := range tmpl.Labels {
n.Labels[k] = v
}
n.Labels["cke.cybozu.com/rack"] = strconv.Itoa(m.Spec.Rack)
n.Labels["cke.cybozu.com/index-in-rack"] = strconv.Itoa(m.Spec.IndexInRack)
n.Labels["cke.cybozu.com/role"] = m.Spec.Role
n.Labels["cke.cybozu.com/retire-month"] = m.Spec.RetireDate.Format("2006-01")
n.Labels["cke.cybozu.com/register-month"] = m.Spec.RegisterDate.Format("2006-01")
n.Labels["node-role.kubernetes.io/"+m.Spec.Role] = "true"
if n.ControlPlane {
n.Labels["node-role.kubernetes.io/master"] = "true"
n.Labels["node-role.kubernetes.io/control-plane"] = "true"
}
n.Labels["topology.kubernetes.io/zone"] = "rack" + strconv.Itoa(m.Spec.Rack)
n.Taints = append(n.Taints, tmpl.Taints...)
switch m.Status.State {
case StateRetiring:
n.Taints = append(n.Taints, corev1.Taint{
Key: "cke.cybozu.com/state",
Value: "retiring",
Effect: corev1.TaintEffectNoExecute,
})
case StateRetired:
n.Taints = append(n.Taints, corev1.Taint{
Key: "cke.cybozu.com/state",
Value: "retired",
Effect: corev1.TaintEffectNoExecute,
})
}
return n
}
type nodeTemplate struct {
*cke.Node
Role string
Weight float64
}
// Generator generates cluster configuration.
type Generator struct {
template *cke.Cluster
constraints *cke.Constraints
timestamp time.Time
waitSeconds float64
machineMap map[string]*Machine
k8sNodeMap map[string]*corev1.Node
cpTmpl nodeTemplate
workerTmpls []nodeTemplate
// intermediate data
nextUnused []*Machine
nextControlPlanes []*Machine
nextWorkers []*Machine
countWorkerByRole map[string]int
}
// NewGenerator creates a new Generator.
// template must have been validated with ValidateTemplate().
func NewGenerator(template *cke.Cluster, cstr *cke.Constraints, machines []Machine, clusterStatus *cke.ClusterStatus, currentTime time.Time) *Generator {
g := &Generator{
template: template,
constraints: cstr,
timestamp: currentTime,
waitSeconds: DefaultWaitRetiredSeconds,
machineMap: make(map[string]*Machine),
k8sNodeMap: make(map[string]*corev1.Node),
}
g.clearIntermediateData()
for _, m := range machines {
if len(m.Spec.IPv4) == 0 {
log.Warn("ignore machine w/o IPv4 address", map[string]interface{}{
"serial": m.Spec.Serial,
})
continue
}
m := m
g.machineMap[m.Spec.IPv4[0]] = &m
}
if clusterStatus != nil {
for _, m := range machines {
for _, n := range clusterStatus.Kubernetes.Nodes {
// m.Spec.IPv4[0] is used for the corresponding cke.Node's Address.
// cke.Node.Hostname is set to empty, so cke.Node.Nodename() is equal to the corresponding Machine's Spec.IPv4[0].
// We invoke kubelet with "--hostname-override=cke.Node.Nodename()", so corev1.Node.Name is equal to the corresponding Machine's Spec.IPv4[0].
if n.Name == m.Spec.IPv4[0] {
n := n
g.k8sNodeMap[m.Spec.IPv4[0]] = &n
}
}
}
}
for _, n := range template.Nodes {
weight := 1.0
if val, ok := n.Labels[CKELabelWeight]; ok {
weight, _ = strconv.ParseFloat(val, 64)
}
tmpl := nodeTemplate{
Node: n,
Role: n.Labels[CKELabelRole],
Weight: weight,
}
if n.ControlPlane {
g.cpTmpl = tmpl
} else {
g.workerTmpls = append(g.workerTmpls, tmpl)
}
}
return g
}
func (g *Generator) clearIntermediateData() {
g.nextControlPlanes = nil
g.nextUnused = nil
g.nextWorkers = nil
g.countWorkerByRole = make(map[string]int)
}
func (g *Generator) chooseWorkerTmpl() nodeTemplate {
count := g.countWorkerByRole
least := float64(count[g.workerTmpls[0].Role]) / g.workerTmpls[0].Weight
leastIndex := 0
for i, tmpl := range g.workerTmpls {
w := float64(count[tmpl.Role]) / tmpl.Weight
if w < least {
least = w
leastIndex = i
}
}
return g.workerTmpls[leastIndex]
}
func (g *Generator) getWorkerTmpl(role string) nodeTemplate {
if len(g.workerTmpls) == 1 {
return g.workerTmpls[0]
}
for _, tmpl := range g.workerTmpls {
if tmpl.Role == role {
return tmpl
}
}
panic("BUG: instantiating for invalid role: " + role)
}
// SetWaitSeconds set seconds before removing retired nodes from the cluster.
func (g *Generator) SetWaitSeconds(secs float64) {
g.waitSeconds = secs
}
// removeMachine removes the specified machine from machines slice.
// If m is nil or if m is not found in machines, this causes panic.
func removeMachine(machines []*Machine, m *Machine) []*Machine {
for i, mm := range machines {
if m == mm {
return append(machines[:i], machines[i+1:]...)
}
}
panic("BUG: illegal machines operation")
}
// selectWorker selects a healthy machine from given machines slice.
// If there is no such machine, this returns nil.
func (g *Generator) selectWorker(machines []*Machine) *Machine {
workerTmpl := g.chooseWorkerTmpl()
candidates := filterHealthyMachinesByRole(machines, workerTmpl.Role)
if len(candidates) == 0 {
return nil
}
countByRack := g.countMachinesByRack(false, workerTmpl.Role)
sort.Slice(candidates, func(i, j int) bool {
si := scoreMachine(candidates[i], countByRack, g.timestamp)
sj := scoreMachine(candidates[j], countByRack, g.timestamp)
// higher first
return si > sj
})
return candidates[0]
}
// selectControlPlane selects a healthy control plane from given machines slice.
// If there is no such machine, this returns nil.
func (g *Generator) selectControlPlane(machines []*Machine) *Machine {
candidates := filterHealthyMachinesByRole(machines, g.cpTmpl.Role)
candidates = g.filterTaintedMachines(candidates)
if len(candidates) == 0 {
return nil
}
countByRack := g.countMachinesByRack(true, "")
sort.Slice(candidates, func(i, j int) bool {
si := scoreMachine(candidates[i], countByRack, g.timestamp)
sj := scoreMachine(candidates[j], countByRack, g.timestamp)
// higher first
return si > sj
})
return candidates[0]
}
// deselectControlPlane selects the lowest scored control plane.
func (g *Generator) deselectControlPlane() *Machine {
countByRack := g.countMachinesByRack(true, "")
sort.Slice(g.nextControlPlanes, func(i, j int) bool {
si := scoreMachineWithHealthStatus(g.nextControlPlanes[i], countByRack, g.timestamp)
sj := scoreMachineWithHealthStatus(g.nextControlPlanes[j], countByRack, g.timestamp)
// lower first
return si < sj
})
return g.nextControlPlanes[0]
}
// fill allocates new machines and/or promotes excessive workers to control plane
// to satisfy given constraints, then generate cluster configuration.
func (g *Generator) fill(op *updateOp) (*cke.Cluster, error) {
for i := len(g.nextControlPlanes); i < g.constraints.ControlPlaneCount; i++ {
m := g.selectControlPlane(g.nextUnused)
if m != nil {
op.addControlPlane(m)
g.nextControlPlanes = append(g.nextControlPlanes, m)
g.nextUnused = removeMachine(g.nextUnused, m)
continue
}
// If no unused machines available, steal a redundant worker and promote it as a control plane.
if len(g.nextWorkers) > g.constraints.MinimumWorkers {
promote := g.selectControlPlane(g.nextWorkers)
if promote != nil {
op.promoteWorker(promote)
g.nextControlPlanes = append(g.nextControlPlanes, promote)
g.removeNextWorker(promote)
continue
}
}
return nil, errNotAvailable
}
for i := len(g.nextWorkers); i < g.constraints.MinimumWorkers; i++ {
m := g.selectWorker(g.nextUnused)
if m == nil {
return nil, errNotAvailable
}
op.addWorker(m)
g.appendNextWorker(m)
g.nextUnused = removeMachine(g.nextUnused, m)
}
err := log.Info("sabakan: generated cluster", map[string]interface{}{
"op": op.name,
"changes": op.changes,
})
if err != nil {
panic(err)
}
nodes := make([]*cke.Node, 0, len(g.nextControlPlanes)+len(g.nextWorkers))
for _, m := range g.nextControlPlanes {
nodes = append(nodes, MachineToNode(m, g.cpTmpl.Node))
}
for _, m := range g.nextWorkers {
nodes = append(nodes, MachineToNode(m, g.getWorkerTmpl(m.Spec.Role).Node))
}
c := *g.template
c.Nodes = nodes
if err := c.Validate(false); err != nil {
return nil, err
}
return &c, nil
}
// Generate generates a new *Cluster that satisfies constraints.
func (g *Generator) Generate() (*cke.Cluster, error) {
g.clearIntermediateData()
op := &updateOp{
name: "new",
}
op.record("generate new cluster")
g.nextUnused = g.getUnusedMachines(nil)
return g.fill(op)
}
// Regenerate regenerates *Cluster using the same set of nodes in the current configuration.
// This method should be used only when the template is updated and no other changes happen.
func (g *Generator) Regenerate(current *cke.Cluster) (*cke.Cluster, error) {
g.clearIntermediateData()
op := &updateOp{
name: "regenerate",
}
nextCPs, nonExistentCPs := g.nodesToMachines(cke.ControlPlanes(current.Nodes))
if nonExistentCPs != nil {
return nil, errMissingMachine
}
g.nextControlPlanes = nextCPs
nextWorkers, nonExistentWorkers := g.nodesToMachines(cke.Workers(current.Nodes))
if nonExistentWorkers != nil {
return nil, errMissingMachine
}
for _, m := range nextWorkers {
g.appendNextWorker(m)
}
g.nextUnused = g.getUnusedMachines(current.Nodes)
op.record("regenerate with new template")
return g.fill(op)
}
// Update updates the current configuration when necessary.
// If the generator decides no updates are necessary, it returns (nil, nil).
func (g *Generator) Update(current *cke.Cluster) (*cke.Cluster, error) {
g.clearIntermediateData()
currentCPs := cke.ControlPlanes(current.Nodes)
currentWorkers := cke.Workers(current.Nodes)
op, err := g.removeNonExistentNode(currentCPs, currentWorkers)
if err != nil {
return nil, err
}
if op != nil {
return g.fill(op)
}
op, err = g.increaseControlPlane()
if err != nil {
return nil, err
}
if op != nil {
return g.fill(op)
}
op, err = g.decreaseControlPlane()
if err != nil {
return nil, err
}
if op != nil {
return g.fill(op)
}
op, err = g.replaceControlPlane()
if err != nil {
return nil, err
}
if op != nil {
return g.fill(op)
}
op, err = g.increaseWorker()
if err != nil {
return nil, err
}
if op != nil {
return g.fill(op)
}
op, err = g.decreaseWorker()
if err != nil {
return nil, err
}
if op != nil {
return g.fill(op)
}
op, err = g.taintNodes(currentCPs, currentWorkers)
if err != nil {
return nil, err
}
if op != nil {
return g.fill(op)
}
return nil, nil
}
func (g *Generator) removeNonExistentNode(currentCPs, currentWorkers []*cke.Node) (*updateOp, error) {
op := &updateOp{
name: "remove non-existent node",
}
nextCPs, nonExistentCPs := g.nodesToMachines(currentCPs)
if len(nextCPs)*2 <= len(currentCPs) {
// Replacing more than half of control plane nodes would destroy
// etcd cluster. We cannot do anything in this case.
return nil, errTooManyNonExistent
}
for _, n := range nonExistentCPs {
op.record("remove non-existent control plane: " + n.Address)
}
g.nextControlPlanes = nextCPs
nextWorkers, nonExistentWorkers := g.nodesToMachines(currentWorkers)
for _, n := range nonExistentWorkers {
op.record("remove non-existent worker: " + n.Address)
}
for _, m := range nextWorkers {
g.appendNextWorker(m)
}
g.nextUnused = g.getUnusedMachines(append(currentCPs, currentWorkers...))
if len(op.changes) == 0 {
// nothing to do
return nil, nil
}
return op, nil
}
func (g *Generator) increaseControlPlane() (*updateOp, error) {
if len(g.nextControlPlanes) >= g.constraints.ControlPlaneCount {
return nil, nil
}
op := &updateOp{
name: "increase control plane",
}
return op, nil
}
func (g *Generator) decreaseControlPlane() (*updateOp, error) {
if len(g.nextControlPlanes) <= g.constraints.ControlPlaneCount {
return nil, nil
}
op := &updateOp{
name: "decrease control plane",
}
for len(g.nextControlPlanes) > g.constraints.ControlPlaneCount {
m := g.deselectControlPlane()
g.nextControlPlanes = removeMachine(g.nextControlPlanes, m)
if g.constraints.MaximumWorkers == 0 || len(g.nextWorkers) < g.constraints.MaximumWorkers {
op.demoteControlPlane(m)
g.appendNextWorker(m)
continue
}
op.record("remove excessive control plane: " + m.Spec.IPv4[0])
g.nextUnused = append(g.nextUnused, m)
}
return op, nil
}
func (g *Generator) replaceControlPlane() (*updateOp, error) {
// If there is only one control plane, this algorithm cannot be chosen.
if len(g.nextControlPlanes) < 2 {
return nil, nil
}
var demote *Machine
for _, m := range g.nextControlPlanes {
state := m.Status.State
if !(state == StateHealthy || state == StateUpdating || state == StateUninitialized) ||
g.isTaintedInCluster(m) {
demote = m
break
}
}
if demote == nil {
return nil, nil
}
op := &updateOp{
name: "replace control plane",
}
g.nextControlPlanes = removeMachine(g.nextControlPlanes, demote)
if g.constraints.MaximumWorkers == 0 || len(g.nextWorkers) < g.constraints.MaximumWorkers {
op.demoteControlPlane(demote)
g.appendNextWorker(demote)
return op, nil
}
promote := g.selectControlPlane(g.nextWorkers)
if promote == nil {
op.record("remove bad control plane: " + demote.Spec.IPv4[0])
return op, nil
}
op.promoteWorker(promote)
g.nextControlPlanes = append(g.nextControlPlanes, promote)
g.removeNextWorker(promote)
g.appendNextWorker(demote)
return op, nil
}
func (g *Generator) increaseWorker() (*updateOp, error) {
var healthyWorkers int
for _, m := range g.nextWorkers {
if m.Status.State == StateHealthy {
healthyWorkers++
}
}
if healthyWorkers >= g.constraints.MinimumWorkers {
return nil, nil
}
op := &updateOp{
name: "increase worker",
}
for i := healthyWorkers; i < g.constraints.MinimumWorkers; i++ {
if g.constraints.MaximumWorkers != 0 && len(g.nextWorkers) >= g.constraints.MaximumWorkers {
break
}
m := g.selectWorker(g.nextUnused)
if m == nil {
break
}
op.addWorker(m)
g.appendNextWorker(m)
g.nextUnused = removeMachine(g.nextUnused, m)
}
if len(op.changes) == 0 {
return nil, nil
}
return op, nil
}
func (g *Generator) decreaseWorker() (*updateOp, error) {
var retired *Machine
for _, m := range g.nextWorkers {
if m.Status.State == StateRetired && m.Status.Duration > g.waitSeconds {
retired = m
break
}
}
if retired == nil {
return nil, nil
}
op := &updateOp{
name: "decrease worker",
}
healthyUnused := g.selectWorker(g.nextUnused)
if healthyUnused == nil && len(g.nextWorkers)-1 < g.constraints.MinimumWorkers {
// in this condition, CKE cannot decrease worker because `minimum-workers` will not be filled.
return nil, nil
}
op.record("remove retired worker: " + retired.Spec.IPv4[0])
g.removeNextWorker(retired)
return op, nil
}
func (g *Generator) nodesToMachines(nodes []*cke.Node) ([]*Machine, []*cke.Node) {
var machines []*Machine
var nonExistent []*cke.Node
for _, n := range nodes {
if m := g.machineMap[n.Address]; m == nil {
nonExistent = append(nonExistent, n)
continue
}
machines = append(machines, g.machineMap[n.Address])
}
return machines, nonExistent
}
func (g *Generator) getUnusedMachines(usedNodes []*cke.Node) []*Machine {
nodeMap := make(map[string]*cke.Node)
for _, n := range usedNodes {
nodeMap[n.Address] = n
}
var unused []*Machine
for a, m := range g.machineMap {
if _, ok := nodeMap[a]; !ok && m.Status.State == StateHealthy {
unused = append(unused, m)
}
}
return unused
}
func (g *Generator) isTaintedInCluster(m *Machine) bool {
n, ok := g.k8sNodeMap[m.Spec.IPv4[0]]
if !ok {
// We can return false even if the Kubernetes Node's taints are unknown.
// This is because the conditions on the taints are not mandatory.
return false
}
OUTER:
for _, t := range n.Spec.Taints {
if strings.HasPrefix(t.Key, "node.kubernetes.io/") || t.Key == "cke.cybozu.com/state" || t.Key == op.CKETaintMaster {
continue
}
for _, toleration := range g.template.CPTolerations {
if t.Key == toleration {
continue OUTER
}
}
return true
}
return false
}
func (g *Generator) filterTaintedMachines(ms []*Machine) []*Machine {
var filtered []*Machine
for _, m := range ms {
if !g.isTaintedInCluster(m) {
filtered = append(filtered, m)
}
}
return filtered
}
func hasValidTaint(n *cke.Node, m *Machine) bool {
var ckeTaint corev1.Taint
for _, taint := range n.Taints {
if taint.Key == "cke.cybozu.com/state" {
ckeTaint = taint
break
}
}
switch m.Status.State {
case StateRetiring:
if ckeTaint.Value != "retiring" || ckeTaint.Effect != corev1.TaintEffectNoExecute {
return false
}
case StateRetired:
if ckeTaint.Value != "retired" || ckeTaint.Effect != corev1.TaintEffectNoExecute {
return false
}
default:
if ckeTaint.Key != "" {
return false
}
}
return true
}
func (g *Generator) taintNodes(currentCPs, currentWorkers []*cke.Node) (*updateOp, error) {
op := &updateOp{
name: "taint nodes",
}
for _, n := range currentCPs {
m := g.machineMap[n.Address]
if m == nil {
panic("BUG: " + n.Address + " does not exist")
}
if !hasValidTaint(n, m) {
op.record("change taint of " + n.Address)
}
}
for _, n := range currentWorkers {
m := g.machineMap[n.Address]
if m == nil {
panic("BUG: " + n.Address + " does not exist")
}
if !hasValidTaint(n, m) {
op.record("change taint of " + n.Address)
}
}
if len(op.changes) == 0 {
return nil, nil
}
return op, nil
}
func (g *Generator) countMachinesByRack(cp bool, role string) map[int]int {
machines := g.nextControlPlanes
if !cp {
machines = g.nextWorkers
}
count := make(map[int]int)
for _, m := range machines {
if !cp && role != "" && role != m.Spec.Role {
continue
}
count[m.Spec.Rack]++
}
return count
}
func (g *Generator) appendNextWorker(m *Machine) {
g.nextWorkers = append(g.nextWorkers, m)
g.countWorkerByRole[m.Spec.Role]++
}
func (g *Generator) removeNextWorker(m *Machine) {
g.nextWorkers = removeMachine(g.nextWorkers, m)
g.countWorkerByRole[m.Spec.Role]--
}