Skip to content

Commit

Permalink
change priorty of reboot queue cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
YZ775 committed Mar 26, 2024
1 parent 269dc52 commit 77a75cd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
17 changes: 16 additions & 1 deletion op/reboot_decide.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func CheckRebootDequeue(ctx context.Context, c *cke.Cluster, rqEntries []*cke.Re
for _, entry := range rqEntries {
switch {
case !entry.ClusterMember(c):
case entry.Status == cke.RebootStatusCancelled:
case entry.Status == cke.RebootStatusRebooting && rebootCompleted(ctx, c, entry):
default:
continue
Expand All @@ -257,6 +256,22 @@ func CheckRebootDequeue(ctx context.Context, c *cke.Cluster, rqEntries []*cke.Re
return dequeued
}

func CheckRebootCanceled(ctx context.Context, c *cke.Cluster, rqEntries []*cke.RebootQueueEntry) []*cke.RebootQueueEntry {
dequeued := []*cke.RebootQueueEntry{}

for _, entry := range rqEntries {
switch {
case entry.Status == cke.RebootStatusCancelled:
default:
continue
}

dequeued = append(dequeued, entry)
}

return dequeued
}

func rebootCompleted(ctx context.Context, c *cke.Cluster, entry *cke.RebootQueueEntry) bool {
if c.Reboot.CommandTimeoutSeconds != nil && *c.Reboot.CommandTimeoutSeconds != 0 {
var cancel context.CancelFunc
Expand Down
2 changes: 2 additions & 0 deletions server/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,15 @@ func (c Controller) runOnce(ctx context.Context, leaderKey string, tick <-chan t
newlyDrained := op.ChooseDrainedNodes(cluster, apiServers, rqEntries)
drainCompleted, drainTimedout, _ := op.CheckDrainCompletion(ctx, inf, nf.HealthyAPIServer(), cluster, rqEntries)
rebootDequeued := op.CheckRebootDequeue(ctx, cluster, rqEntries)
RebootCanceled := op.CheckRebootCanceled(ctx, cluster, rqEntries)

ops, phase := DecideOps(cluster, status, constraints, rcs, DecideOpsRebootArgs{
RQEntries: rqEntries,
NewlyDrained: newlyDrained,
DrainCompleted: drainCompleted,
DrainTimedout: drainTimedout,
RebootDequeued: rebootDequeued,
RebootCanceled: RebootCanceled,
}, c.config)

st := &cke.ServerStatus{
Expand Down
6 changes: 6 additions & 0 deletions server/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type DecideOpsRebootArgs struct {
DrainCompleted []*cke.RebootQueueEntry
DrainTimedout []*cke.RebootQueueEntry
RebootDequeued []*cke.RebootQueueEntry
RebootCanceled []*cke.RebootQueueEntry
}

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

if len(rebootArgs.RebootCanceled) > 0 {
phaseReboot = true
ops = append(ops, op.RebootDequeueOp(rebootArgs.RebootCanceled))
return ops, phaseReboot
}
if len(rebootArgs.NewlyDrained) > 0 {
phaseReboot = true
sshCheckNodes := make([]*cke.Node, 0, len(nf.cluster.Nodes))
Expand Down
9 changes: 7 additions & 2 deletions server/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,11 @@ func (d testData) withRebootDequeued(entries []*cke.RebootQueueEntry) testData {
return d
}

func (d testData) withRebootCanceled(entries []*cke.RebootQueueEntry) testData {
d.RebootArgs.RebootCanceled = entries
return d
}

func (d testData) withDisableProxy() testData {
d.Cluster.Options.Proxy.Disable = true
return d
Expand Down Expand Up @@ -1274,7 +1279,7 @@ func TestDecideOps(t *testing.T) {
Node: nodeNames[2],
Status: cke.RebootStatusCancelled,
},
}).withRebootDequeued([]*cke.RebootQueueEntry{
}).withRebootCanceled([]*cke.RebootQueueEntry{
{
Index: 1,
Node: nodeNames[2],
Expand Down Expand Up @@ -2700,7 +2705,7 @@ func TestDecideOps(t *testing.T) {
Node: nodeNames[4],
Status: cke.RebootStatusCancelled,
},
}).withRebootDequeued([]*cke.RebootQueueEntry{
}).withRebootCanceled([]*cke.RebootQueueEntry{
{
Index: 1,
Node: nodeNames[4],
Expand Down

0 comments on commit 77a75cd

Please sign in to comment.