Skip to content

Commit 1a62952

Browse files
committed
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
1 parent abbb26a commit 1a62952

File tree

3 files changed

+0
-13
lines changed

3 files changed

+0
-13
lines changed

cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machinedeployment.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,9 @@ func (r machineDeploymentScalableResource) UnmarkMachineForDeletion(machine *Mac
120120

121121
func (r machineDeploymentScalableResource) MarkMachineForDeletion(machine *Machine) error {
122122
u, err := r.controller.dynamicclient.Resource(*r.controller.machineResource).Namespace(machine.Namespace).Get(context.TODO(), machine.Name, metav1.GetOptions{})
123-
124123
if err != nil {
125124
return err
126125
}
127-
if u == nil {
128-
return fmt.Errorf("unknown machine %s", machine.Name)
129-
}
130126

131127
u = u.DeepCopy()
132128

cluster-autoscaler/cloudprovider/clusterapi/clusterapi_machineset.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,9 @@ func (r machineSetScalableResource) SetSize(nreplicas int32) error {
102102

103103
func (r machineSetScalableResource) MarkMachineForDeletion(machine *Machine) error {
104104
u, err := r.controller.dynamicclient.Resource(*r.controller.machineResource).Namespace(machine.Namespace).Get(context.TODO(), machine.Name, metav1.GetOptions{})
105-
106105
if err != nil {
107106
return err
108107
}
109-
if u == nil {
110-
return fmt.Errorf("unknown machine %s", machine.Name)
111-
}
112108

113109
u = u.DeepCopy()
114110

cluster-autoscaler/cloudprovider/clusterapi/clusterapi_scalableresource.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package clusterapi
1818

1919
import (
2020
"context"
21-
"fmt"
2221

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

6160
func unmarkMachineForDeletion(controller *machineController, machine *Machine) error {
6261
u, err := controller.dynamicclient.Resource(*controller.machineResource).Namespace(machine.Namespace).Get(context.TODO(), machine.Name, metav1.GetOptions{})
63-
6462
if err != nil {
6563
return err
6664
}
67-
if u == nil {
68-
return fmt.Errorf("unknown machine %s", machine.Name)
69-
}
7065

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

0 commit comments

Comments
 (0)