Skip to content

Commit fa0c9f5

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

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

pkg/cloud/snapshots.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ 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+
}
42+
3943
return nil, err
4044
}
4145

@@ -91,8 +95,12 @@ func (c *client) GetSnapshotByName(ctx context.Context, name string) (*Snapshot,
9195
logger.V(2).Info("CloudStack API call", "command", "GetSnapshotByName", "params", map[string]string{
9296
"name": name,
9397
})
94-
snapshot, _, err := c.Snapshot.GetSnapshotByName(name)
98+
snapshot, count, err := c.Snapshot.GetSnapshotByName(name)
9599
if err != nil {
100+
if count == 0 {
101+
return nil, ErrNotFound
102+
}
103+
96104
return nil, err
97105
}
98106

pkg/cloud/vms.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ 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+
}
39+
3640
return nil, err
3741
}
3842

@@ -48,8 +52,12 @@ func (c *client) getVMByName(ctx context.Context, name string) (*VM, error) {
4852
"name": name,
4953
})
5054

51-
vm, _, err := c.VirtualMachine.GetVirtualMachineByName(name)
55+
vm, count, err := c.VirtualMachine.GetVirtualMachineByName(name)
5256
if err != nil {
57+
if count == 0 {
58+
return nil, ErrNotFound
59+
}
60+
5361
return nil, err
5462
}
5563

pkg/cloud/volumes.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ 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+
}
59+
5660
return nil, err
5761
}
5862

@@ -67,8 +71,12 @@ func (c *client) GetVolumeByName(ctx context.Context, name string) (*Volume, err
6771
"name": name,
6872
})
6973

70-
volume, _, err := c.Volume.GetVolumeByName(name)
74+
volume, count, err := c.Volume.GetVolumeByName(name)
7175
if err != nil {
76+
if count == 0 {
77+
return nil, ErrNotFound
78+
}
79+
7280
return nil, err
7381
}
7482

0 commit comments

Comments
 (0)