From 1a6295200361ed8de057a8336ffb981d4c073fb5 Mon Sep 17 00:00:00 2001 From: Michael McCune Date: Tue, 2 Jun 2020 16:24:30 -0400 Subject: [PATCH] remove redundant error checks in mark/unmark deletion functions 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 --- .../cloudprovider/clusterapi/clusterapi_machinedeployment.go | 4 ---- .../cloudprovider/clusterapi/clusterapi_machineset.go | 4 ---- .../cloudprovider/clusterapi/clusterapi_scalableresource.go | 5 ----- 3 files changed, 13 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machinedeployment.go b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machinedeployment.go index 5acdefbaf97a..fe636c8ffc16 100644 --- a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machinedeployment.go +++ b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machinedeployment.go @@ -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() diff --git a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machineset.go b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machineset.go index 03b86f073335..97d396c119aa 100644 --- a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machineset.go +++ b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machineset.go @@ -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() diff --git a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_scalableresource.go b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_scalableresource.go index 454531599ffd..aa1228fb4420 100644 --- a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_scalableresource.go +++ b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_scalableresource.go @@ -18,7 +18,6 @@ package clusterapi import ( "context" - "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -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 {