Skip to content

Commit e50e9fd

Browse files
authored
Merge pull request #715 from cybozu-go/change-cancel
change priorty of reboot queue cancel
2 parents 7d544a4 + 2d19ad3 commit e50e9fd

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

op/reboot.go

+19
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,25 @@ func (c rebootDequeueCommand) Command() cke.Command {
523523
}
524524
}
525525

526+
//
527+
528+
type rebootCancelOp struct {
529+
rebootDequeueOp
530+
}
531+
532+
// RebootCancelOp returns an Operator to dequeue cancelled reboot entries.
533+
func RebootCancelOp(entries []*cke.RebootQueueEntry) cke.Operator {
534+
return &rebootCancelOp{
535+
rebootDequeueOp{
536+
entries: entries,
537+
},
538+
}
539+
}
540+
541+
func (o *rebootCancelOp) Name() string {
542+
return "reboot-cancel"
543+
}
544+
526545
func listProtectedNamespaces(ctx context.Context, cs *kubernetes.Clientset, ls *metav1.LabelSelector) (map[string]bool, error) {
527546
selector, err := metav1.LabelSelectorAsSelector(ls)
528547
if err != nil {

op/reboot_decide.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ func CheckRebootDequeue(ctx context.Context, c *cke.Cluster, rqEntries []*cke.Re
245245
for _, entry := range rqEntries {
246246
switch {
247247
case !entry.ClusterMember(c):
248-
case entry.Status == cke.RebootStatusCancelled:
249248
case entry.Status == cke.RebootStatusRebooting && rebootCompleted(ctx, c, entry):
250249
default:
251250
continue
@@ -257,6 +256,18 @@ func CheckRebootDequeue(ctx context.Context, c *cke.Cluster, rqEntries []*cke.Re
257256
return dequeued
258257
}
259258

259+
func CheckRebootCancelled(ctx context.Context, c *cke.Cluster, rqEntries []*cke.RebootQueueEntry) []*cke.RebootQueueEntry {
260+
cancelled := []*cke.RebootQueueEntry{}
261+
262+
for _, entry := range rqEntries {
263+
if entry.Status == cke.RebootStatusCancelled {
264+
cancelled = append(cancelled, entry)
265+
}
266+
}
267+
268+
return cancelled
269+
}
270+
260271
func rebootCompleted(ctx context.Context, c *cke.Cluster, entry *cke.RebootQueueEntry) bool {
261272
if c.Reboot.CommandTimeoutSeconds != nil && *c.Reboot.CommandTimeoutSeconds != 0 {
262273
var cancel context.CancelFunc

server/control.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,15 @@ func (c Controller) runOnce(ctx context.Context, leaderKey string, tick <-chan t
346346
newlyDrained := op.ChooseDrainedNodes(cluster, apiServers, rqEntries)
347347
drainCompleted, drainTimedout, _ := op.CheckDrainCompletion(ctx, inf, nf.HealthyAPIServer(), cluster, rqEntries)
348348
rebootDequeued := op.CheckRebootDequeue(ctx, cluster, rqEntries)
349+
rebootCancelled := op.CheckRebootCancelled(ctx, cluster, rqEntries)
349350

350351
ops, phase := DecideOps(cluster, status, constraints, rcs, DecideOpsRebootArgs{
351-
RQEntries: rqEntries,
352-
NewlyDrained: newlyDrained,
353-
DrainCompleted: drainCompleted,
354-
DrainTimedout: drainTimedout,
355-
RebootDequeued: rebootDequeued,
352+
RQEntries: rqEntries,
353+
NewlyDrained: newlyDrained,
354+
DrainCompleted: drainCompleted,
355+
DrainTimedout: drainTimedout,
356+
RebootDequeued: rebootDequeued,
357+
RebootCancelled: rebootCancelled,
356358
}, c.config)
357359

358360
st := &cke.ServerStatus{

server/strategy.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import (
1717
)
1818

1919
type DecideOpsRebootArgs struct {
20-
RQEntries []*cke.RebootQueueEntry
21-
NewlyDrained []*cke.RebootQueueEntry
22-
DrainCompleted []*cke.RebootQueueEntry
23-
DrainTimedout []*cke.RebootQueueEntry
24-
RebootDequeued []*cke.RebootQueueEntry
20+
RQEntries []*cke.RebootQueueEntry
21+
NewlyDrained []*cke.RebootQueueEntry
22+
DrainCompleted []*cke.RebootQueueEntry
23+
DrainTimedout []*cke.RebootQueueEntry
24+
RebootDequeued []*cke.RebootQueueEntry
25+
RebootCancelled []*cke.RebootQueueEntry
2526
}
2627

2728
// DecideOps returns the next operations to do and the operation phase.
@@ -883,6 +884,11 @@ func rebootOps(c *cke.Cluster, constraints *cke.Constraints, rebootArgs DecideOp
883884
return nil, false
884885
}
885886

887+
if len(rebootArgs.RebootCancelled) > 0 {
888+
phaseReboot = true
889+
ops = append(ops, op.RebootCancelOp(rebootArgs.RebootCancelled))
890+
return ops, phaseReboot
891+
}
886892
if len(rebootArgs.NewlyDrained) > 0 {
887893
phaseReboot = true
888894
sshCheckNodes := make([]*cke.Node, 0, len(nf.cluster.Nodes))

server/strategy_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,11 @@ func (d testData) withRebootDequeued(entries []*cke.RebootQueueEntry) testData {
658658
return d
659659
}
660660

661+
func (d testData) withRebootCancelled(entries []*cke.RebootQueueEntry) testData {
662+
d.RebootArgs.RebootCancelled = entries
663+
return d
664+
}
665+
661666
func (d testData) withDisableProxy() testData {
662667
d.Cluster.Options.Proxy.Disable = true
663668
return d
@@ -1274,14 +1279,14 @@ func TestDecideOps(t *testing.T) {
12741279
Node: nodeNames[2],
12751280
Status: cke.RebootStatusCancelled,
12761281
},
1277-
}).withRebootDequeued([]*cke.RebootQueueEntry{
1282+
}).withRebootCancelled([]*cke.RebootQueueEntry{
12781283
{
12791284
Index: 1,
12801285
Node: nodeNames[2],
12811286
Status: cke.RebootStatusCancelled,
12821287
},
12831288
}),
1284-
ExpectedOps: []opData{{"reboot-dequeue", 1}},
1289+
ExpectedOps: []opData{{"reboot-cancel", 1}},
12851290
},
12861291
{
12871292
Name: "UserResourceAdd",
@@ -2700,15 +2705,15 @@ func TestDecideOps(t *testing.T) {
27002705
Node: nodeNames[4],
27012706
Status: cke.RebootStatusCancelled,
27022707
},
2703-
}).withRebootDequeued([]*cke.RebootQueueEntry{
2708+
}).withRebootCancelled([]*cke.RebootQueueEntry{
27042709
{
27052710
Index: 1,
27062711
Node: nodeNames[4],
27072712
Status: cke.RebootStatusCancelled,
27082713
},
27092714
}),
27102715
ExpectedOps: []opData{
2711-
{"reboot-dequeue", 1},
2716+
{"reboot-cancel", 1},
27122717
},
27132718
},
27142719
}

0 commit comments

Comments
 (0)