Skip to content

Commit 630e259

Browse files
committed
return error for not found case makes checking existence fail
error only for other case. found or not found are 2 common return values with no err
1 parent f98871d commit 630e259

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pkg/cloud/ibmcloud/actuators/machine/actuator.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ func (ic *IbmCloudClient) Create(ctx context.Context, cluster *clusterv1.Cluster
129129
return err
130130
}
131131

132+
if guest == nil {
133+
return fmt.Errorf("Guest host does not found")
134+
}
135+
132136
return ic.updateAnnotation(machine, strconv.Itoa(*guest.Id))
133137
}
134138

@@ -167,11 +171,12 @@ func (ic *IbmCloudClient) Update(ctx context.Context, cluster *clusterv1.Cluster
167171

168172
// Exists test for the existance of a machine and is invoked by the Machine Controller
169173
func (ic *IbmCloudClient) Exists(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) (bool, error) {
170-
_, err := ic.getGuest(machine)
174+
guest, err := ic.getGuest(machine)
171175
if err != nil {
172176
return false, err
173177
}
174-
return true, nil
178+
179+
return guest != nil, nil
175180
}
176181

177182
func (ic *IbmCloudClient) getGuest(machine *clusterv1.Machine) (*datatypes.Virtual_Guest, error) {

pkg/cloud/ibmcloud/clients/machines.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (gs *GuestService) GetGuest(name string) (*datatypes.Virtual_Guest, error)
188188
return &guest, nil
189189
}
190190
}
191-
return nil, fmt.Errorf("Virtual guest %q does not found", name)
191+
return nil, nil
192192
}
193193

194194
// TODO: directly get ID of ssh key instead of list and search

0 commit comments

Comments
 (0)