Skip to content

Commit

Permalink
last
Browse files Browse the repository at this point in the history
  • Loading branch information
njtran committed May 3, 2023
1 parent 54e0070 commit 9bc6220
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
10 changes: 5 additions & 5 deletions pkg/controllers/deprovisioning/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *Controller) deprovision(ctx context.Context, deprovisioner Deprovisione
if err != nil {
return false, fmt.Errorf("computing deprovisioning decision, %w", err)
}
if cmd.action() == noOpAction {
if cmd.Action() == noOpAction {
return false, nil
}

Expand All @@ -171,11 +171,11 @@ func (c *Controller) deprovision(ctx context.Context, deprovisioner Deprovisione
}

func (c *Controller) executeCommand(ctx context.Context, d Deprovisioner, command Command) error {
deprovisioningActionsPerformedCounter.With(prometheus.Labels{"action": fmt.Sprintf("%s/%s", d, command.action())}).Inc()
logging.FromContext(ctx).Infof("deprovisioning via %s %s", d, command.action())
deprovisioningActionsPerformedCounter.With(prometheus.Labels{"action": fmt.Sprintf("%s/%s", d, command.Action())}).Inc()
logging.FromContext(ctx).Infof("deprovisioning via %s %s", d, command.Action())

reason := fmt.Sprintf("%s/%s", d, command.action())
if command.action() == replaceAction {
reason := fmt.Sprintf("%s/%s", d, command.Action())
if command.Action() == replaceAction {
if err := c.launchReplacementMachines(ctx, command, reason); err != nil {
// If we failed to launch the replacement, don't deprovision. If this is some permanent failure,
// we don't want to disrupt workloads with no way to provision new nodes for them.
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/deprovisioning/multimachineconsolidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (m *MultiMachineConsolidation) ComputeCommand(ctx context.Context, candidat
if err != nil {
return Command{}, err
}
if cmd.action() == noOpAction {
if cmd.Action() == noOpAction {
return cmd, nil
}

Expand Down Expand Up @@ -97,7 +97,7 @@ func (m *MultiMachineConsolidation) firstNMachineConsolidationOption(ctx context
// ensure that the action is sensical for replacements, see explanation on filterOutSameType for why this is
// required
instanceTypeFiltered := false
if action.action() == replaceAction {
if action.Action() == replaceAction {
action.replacements[0].InstanceTypeOptions = filterOutSameType(action.replacements[0], candidatesToConsolidate)
instanceTypeFiltered = len(action.replacements[0].InstanceTypeOptions) == 0
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/deprovisioning/singlemachineconsolidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *SingleMachineConsolidation) ComputeCommand(ctx context.Context, candida
logging.FromContext(ctx).Errorf("computing consolidation %s", err)
continue
}
if cmd.action() == noOpAction {
if cmd.Action() == noOpAction {
continue
}

Expand All @@ -70,7 +70,7 @@ func (c *SingleMachineConsolidation) ComputeCommand(ctx context.Context, candida
return Command{}, fmt.Errorf("command is no longer valid, %s", cmd)
}

if cmd.action() != noOpAction {
if cmd.Action() != noOpAction {
return cmd, nil
}
}
Expand Down
21 changes: 11 additions & 10 deletions pkg/controllers/deprovisioning/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type Candidate struct {
func NewCandidate(ctx context.Context, kubeClient client.Client, recorder events.Recorder, clk clock.Clock, node *state.StateNode,
provisionerMap map[string]*v1alpha5.Provisioner, provisionerToInstanceTypes map[string]map[string]*cloudprovider.InstanceType) (*Candidate, error) {

if node.Node == nil || node.Machine == nil {
return nil, fmt.Errorf("state node doesn't contain both a node and a machine")
}
// check whether the node has all the labels we need
for _, label := range []string{
v1alpha5.LabelCapacityType,
Expand Down Expand Up @@ -101,9 +104,6 @@ func NewCandidate(ctx context.Context, kubeClient client.Client, recorder events
recorder.Publish(deprovisioningevents.Blocked(node.Node, node.Machine, "machine is nominated")...)
return nil, fmt.Errorf("state node is nominated")
}
if node.Node == nil || node.Machine == nil {
return nil, fmt.Errorf("state node doesn't contain both a node and a machine")
}

pods, err := node.Pods(ctx, kubeClient)
if err != nil {
Expand Down Expand Up @@ -147,19 +147,20 @@ const (
deleteAction = "delete"
)

func (o Command) action() string {
if len(o.candidates) == 0 {
return noOpAction
}
if len(o.replacements) > 0 {
func (o Command) Action() string {
switch {
case len(o.candidates) > 0 && len(o.replacements) == 0:
return replaceAction
case len(o.candidates) > 0 && len(o.replacements) == 0:
return deleteAction
default:
return noOpAction
}
return deleteAction
}

func (o Command) String() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "%s, terminating %d machines ", o.action(), len(o.candidates))
fmt.Fprintf(&buf, "%s, terminating %d machines ", o.Action(), len(o.candidates))
for i, old := range o.candidates {
if i != 0 {
fmt.Fprint(&buf, ", ")
Expand Down

0 comments on commit 9bc6220

Please sign in to comment.