Skip to content

Commit e6c1a78

Browse files
committed
Add back the count checks in vms, volumes, snapshots to not break the CSI driver logic
1 parent f508ea3 commit e6c1a78

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

pkg/cloud/snapshots.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ func (c *client) GetSnapshotByID(ctx context.Context, snapshotID string) (*Snaps
3434
"id": snapshotID,
3535
})
3636

37-
snapshot, _, err := c.Snapshot.GetSnapshotByID(snapshotID)
37+
snapshot, count, err := c.Snapshot.GetSnapshotByID(snapshotID)
3838
if err != nil {
39+
if count == 0 {
40+
return nil, ErrNotFound
41+
}
3942
return nil, err
4043
}
4144

@@ -91,8 +94,11 @@ func (c *client) GetSnapshotByName(ctx context.Context, name string) (*Snapshot,
9194
logger.V(2).Info("CloudStack API call", "command", "GetSnapshotByName", "params", map[string]string{
9295
"name": name,
9396
})
94-
snapshot, _, err := c.Snapshot.GetSnapshotByName(name)
97+
snapshot, count, err := c.Snapshot.GetSnapshotByName(name)
9598
if err != nil {
99+
if count == 0 {
100+
return nil, ErrNotFound
101+
}
96102
return nil, err
97103
}
98104

pkg/cloud/vms.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ func (c *client) GetVMByID(ctx context.Context, vmID string) (*VM, error) {
3131
"id": vmID,
3232
})
3333

34-
vm, _, err := c.VirtualMachine.GetVirtualMachineByID(vmID)
34+
vm, count, err := c.VirtualMachine.GetVirtualMachineByID(vmID)
3535
if err != nil {
36+
if count == 0 {
37+
return nil, ErrNotFound
38+
}
3639
return nil, err
3740
}
3841

@@ -48,8 +51,11 @@ func (c *client) getVMByName(ctx context.Context, name string) (*VM, error) {
4851
"name": name,
4952
})
5053

51-
vm, _, err := c.VirtualMachine.GetVirtualMachineByName(name)
54+
vm, count, err := c.VirtualMachine.GetVirtualMachineByName(name)
5255
if err != nil {
56+
if count == 0 {
57+
return nil, ErrNotFound
58+
}
5359
return nil, err
5460
}
5561

pkg/cloud/volumes.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ func (c *client) GetVolumeByID(ctx context.Context, volumeID string) (*Volume, e
5151
"id": volumeID,
5252
})
5353

54-
volume, _, err := c.Volume.GetVolumeByID(volumeID)
54+
volume, count, err := c.Volume.GetVolumeByID(volumeID)
5555
if err != nil {
56+
if count == 0 {
57+
return nil, ErrNotFound
58+
}
5659
return nil, err
5760
}
5861

@@ -67,8 +70,11 @@ func (c *client) GetVolumeByName(ctx context.Context, name string) (*Volume, err
6770
"name": name,
6871
})
6972

70-
volume, _, err := c.Volume.GetVolumeByName(name)
73+
volume, count, err := c.Volume.GetVolumeByName(name)
7174
if err != nil {
75+
if count == 0 {
76+
return nil, ErrNotFound
77+
}
7278
return nil, err
7379
}
7480

0 commit comments

Comments
 (0)