Skip to content

Commit 57440c3

Browse files
committed
add support to create snapshots at project level using csi driver
1 parent 8cb8b80 commit 57440c3

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

examples/k8s/snapshot/pvc-from-snapshot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spec:
77
- ReadWriteOnce
88
resources:
99
requests:
10-
storage: 10Gi
10+
storage: 1Gi
1111
dataSource:
1212
name: snapshot-1
1313
kind: VolumeSnapshot

pkg/cloud/snapshots.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ import (
66

77
"google.golang.org/grpc/codes"
88
"google.golang.org/grpc/status"
9+
"k8s.io/klog/v2"
910
)
1011

1112
func (c *client) GetSnapshotByID(ctx context.Context, snapshotID ...string) (*Snapshot, error) {
13+
logger := klog.FromContext(ctx)
1214
p := c.Snapshot.NewListSnapshotsParams()
1315
if snapshotID != nil {
1416
p.SetId(snapshotID[0])
1517
}
18+
if c.projectID != "" {
19+
p.SetProjectid(c.projectID)
20+
}
21+
logger.V(2).Info("CloudStack API call", "command", "ListSnapshots", "params", map[string]string{
22+
"id": snapshotID[0],
23+
"projectid": c.projectID,
24+
})
1625
l, err := c.Snapshot.ListSnapshots(p)
1726
if err != nil {
1827
return nil, err
@@ -37,7 +46,13 @@ func (c *client) GetSnapshotByID(ctx context.Context, snapshotID ...string) (*Sn
3746
}
3847

3948
func (c *client) CreateSnapshot(ctx context.Context, volumeID string) (*Snapshot, error) {
49+
logger := klog.FromContext(ctx)
4050
p := c.Snapshot.NewCreateSnapshotParams(volumeID)
51+
52+
logger.V(2).Info("CloudStack API call", "command", "CreateSnapshot", "params", map[string]string{
53+
"volumeid": volumeID,
54+
})
55+
4156
snapshot, err := c.Snapshot.CreateSnapshot(p)
4257
if err != nil {
4358
return nil, status.Errorf(codes.Internal, "Error %v", err)

pkg/cloud/volumes.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ func (c *client) ExpandVolume(ctx context.Context, volumeID string, newSizeInGB
166166

167167
func (c *client) CreateVolumeFromSnapshot(ctx context.Context, zoneID, name, domainID, projectID, snapshotID string, sizeInGB int64) (*Volume, error) {
168168
logger := klog.FromContext(ctx)
169-
snapshot, _, err := c.Snapshot.GetSnapshotByID(snapshotID)
170-
if err != nil {
171-
return nil, fmt.Errorf("failed to retrieve snapshot '%s': %w", snapshotID, err)
172-
}
173169

174170
p := c.Volume.NewCreateVolumeParams()
175171
p.SetZoneid(zoneID)
@@ -178,7 +174,7 @@ func (c *client) CreateVolumeFromSnapshot(ctx context.Context, zoneID, name, dom
178174
}
179175
p.SetName(name)
180176
p.SetSize(sizeInGB)
181-
p.SetSnapshotid(snapshot.Id)
177+
p.SetSnapshotid(snapshotID)
182178

183179
logger.V(2).Info("CloudStack API call", "command", "CreateVolume", "params", map[string]string{
184180
"name": name,

pkg/driver/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,10 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
332332
// Error with CloudStack
333333
return nil, status.Errorf(codes.Internal, "Error %v", err)
334334
}
335+
klog.V(4).Infof("CreateSnapshot of volume: %s", volume)
335336
snapshot, err := cs.connector.CreateSnapshot(ctx, volume.ID)
336337
if err != nil {
337-
return nil, status.Errorf(codes.Internal, "Failed to create snapshot %s: %v", snapshot.ID, err.Error())
338+
return nil, status.Errorf(codes.Internal, "Failed to create snapshot for volume %s: %v", volume.ID, err.Error())
338339
}
339340

340341
t, err := time.Parse("2006-01-02T15:04:05-0700", snapshot.CreatedAt)

0 commit comments

Comments
 (0)