Skip to content

Commit

Permalink
remove redundant error checks in mark/unmark deletion functions
Browse files Browse the repository at this point in the history
This change removes a few nil checks against resources returned in the
Mark and Unmark deletion functions of the cluster-autoscaler CAPI
provider. These checks look to see if the returned value for a resource
are nil, but the function will not return nil if it returns an
error[0]. We only need to check the error return as discussed here[1].

[0]
https://github.com/kubernetes/client-go/blob/master/dynamic/simple.go#L234
[1]
https://github.com/openshift/kubernetes-autoscaler/pull/141/files#r414480960
  • Loading branch information
elmiko committed Jun 3, 2020
1 parent abbb26a commit 1a62952
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,9 @@ func (r machineDeploymentScalableResource) UnmarkMachineForDeletion(machine *Mac

func (r machineDeploymentScalableResource) MarkMachineForDeletion(machine *Machine) error {
u, err := r.controller.dynamicclient.Resource(*r.controller.machineResource).Namespace(machine.Namespace).Get(context.TODO(), machine.Name, metav1.GetOptions{})

if err != nil {
return err
}
if u == nil {
return fmt.Errorf("unknown machine %s", machine.Name)
}

u = u.DeepCopy()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ func (r machineSetScalableResource) SetSize(nreplicas int32) error {

func (r machineSetScalableResource) MarkMachineForDeletion(machine *Machine) error {
u, err := r.controller.dynamicclient.Resource(*r.controller.machineResource).Namespace(machine.Namespace).Get(context.TODO(), machine.Name, metav1.GetOptions{})

if err != nil {
return err
}
if u == nil {
return fmt.Errorf("unknown machine %s", machine.Name)
}

u = u.DeepCopy()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package clusterapi

import (
"context"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -60,13 +59,9 @@ type scalableResource interface {

func unmarkMachineForDeletion(controller *machineController, machine *Machine) error {
u, err := controller.dynamicclient.Resource(*controller.machineResource).Namespace(machine.Namespace).Get(context.TODO(), machine.Name, metav1.GetOptions{})

if err != nil {
return err
}
if u == nil {
return fmt.Errorf("unknown machine %s", machine.Name)
}

annotations := u.GetAnnotations()
if _, ok := annotations[machineDeleteAnnotationKey]; ok {
Expand Down

0 comments on commit 1a62952

Please sign in to comment.