Update snapshotter to use CSI spec 1.0. This breaks the snapshot handling of error and uploading status
This commit is contained in:
@@ -25,6 +25,8 @@ import (
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"github.com/golang/glog"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"k8s.io/api/core/v1"
|
||||
@@ -46,13 +48,13 @@ type CSIConnection interface {
|
||||
SupportsControllerListSnapshots(ctx context.Context) (bool, error)
|
||||
|
||||
// CreateSnapshot creates a snapshot for a volume
|
||||
CreateSnapshot(ctx context.Context, snapshotName string, volume *v1.PersistentVolume, parameters map[string]string, snapshotterCredentials map[string]string) (driverName string, snapshotId string, timestamp int64, size int64, status *csi.SnapshotStatus, err error)
|
||||
CreateSnapshot(ctx context.Context, snapshotName string, volume *v1.PersistentVolume, parameters map[string]string, snapshotterCredentials map[string]string) (driverName string, snapshotId string, timestamp int64, size int64, readyToUse bool, err error)
|
||||
|
||||
// DeleteSnapshot deletes a snapshot from a volume
|
||||
DeleteSnapshot(ctx context.Context, snapshotID string, snapshotterCredentials map[string]string) (err error)
|
||||
|
||||
// GetSnapshotStatus returns a snapshot's status, creation time, and restore size.
|
||||
GetSnapshotStatus(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, int64, int64, error)
|
||||
// GetSnapshotStatus returns if a snapshot is ready to use, creation time, and restore size.
|
||||
GetSnapshotStatus(ctx context.Context, snapshotID string) (bool, int64, int64, error)
|
||||
|
||||
// Probe checks that the CSI driver is ready to process requests
|
||||
Probe(ctx context.Context) error
|
||||
@@ -188,41 +190,45 @@ func (c *csiConnection) SupportsControllerListSnapshots(ctx context.Context) (bo
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (c *csiConnection) CreateSnapshot(ctx context.Context, snapshotName string, volume *v1.PersistentVolume, parameters map[string]string, snapshotterCredentials map[string]string) (string, string, int64, int64, *csi.SnapshotStatus, error) {
|
||||
func (c *csiConnection) CreateSnapshot(ctx context.Context, snapshotName string, volume *v1.PersistentVolume, parameters map[string]string, snapshotterCredentials map[string]string) (string, string, int64, int64, bool, error) {
|
||||
glog.V(5).Infof("CSI CreateSnapshot: %s", snapshotName)
|
||||
if volume.Spec.CSI == nil {
|
||||
return "", "", 0, 0, nil, fmt.Errorf("CSIPersistentVolumeSource not defined in spec")
|
||||
return "", "", 0, 0, false, fmt.Errorf("CSIPersistentVolumeSource not defined in spec")
|
||||
}
|
||||
|
||||
client := csi.NewControllerClient(c.conn)
|
||||
|
||||
driverName, err := c.GetDriverName(ctx)
|
||||
if err != nil {
|
||||
return "", "", 0, 0, nil, err
|
||||
return "", "", 0, 0, false, err
|
||||
}
|
||||
|
||||
req := csi.CreateSnapshotRequest{
|
||||
SourceVolumeId: volume.Spec.CSI.VolumeHandle,
|
||||
Name: snapshotName,
|
||||
Parameters: parameters,
|
||||
CreateSnapshotSecrets: snapshotterCredentials,
|
||||
SourceVolumeId: volume.Spec.CSI.VolumeHandle,
|
||||
Name: snapshotName,
|
||||
Parameters: parameters,
|
||||
Secrets: snapshotterCredentials,
|
||||
}
|
||||
|
||||
rsp, err := client.CreateSnapshot(ctx, &req)
|
||||
if err != nil {
|
||||
return "", "", 0, 0, nil, err
|
||||
return "", "", 0, 0, false, err
|
||||
}
|
||||
|
||||
glog.V(5).Infof("CSI CreateSnapshot: %s driver name [%s] snapshot ID [%s] time stamp [%d] size [%d] status [%s]", snapshotName, driverName, rsp.Snapshot.Id, rsp.Snapshot.CreatedAt, rsp.Snapshot.SizeBytes, *rsp.Snapshot.Status)
|
||||
return driverName, rsp.Snapshot.Id, rsp.Snapshot.CreatedAt, rsp.Snapshot.SizeBytes, rsp.Snapshot.Status, nil
|
||||
glog.V(5).Infof("CSI CreateSnapshot: %s driver name [%s] snapshot ID [%s] time stamp [%d] size [%d] readyToUse [%v]", snapshotName, driverName, rsp.Snapshot.SnapshotId, rsp.Snapshot.CreationTime, rsp.Snapshot.SizeBytes, rsp.Snapshot.ReadyToUse)
|
||||
creationTime, err := timestampToUnixTime(rsp.Snapshot.CreationTime)
|
||||
if err != nil {
|
||||
return "", "", 0, 0, false, err
|
||||
}
|
||||
return driverName, rsp.Snapshot.SnapshotId, creationTime, rsp.Snapshot.SizeBytes, rsp.Snapshot.ReadyToUse, nil
|
||||
}
|
||||
|
||||
func (c *csiConnection) DeleteSnapshot(ctx context.Context, snapshotID string, snapshotterCredentials map[string]string) (err error) {
|
||||
client := csi.NewControllerClient(c.conn)
|
||||
|
||||
req := csi.DeleteSnapshotRequest{
|
||||
SnapshotId: snapshotID,
|
||||
DeleteSnapshotSecrets: snapshotterCredentials,
|
||||
SnapshotId: snapshotID,
|
||||
Secrets: snapshotterCredentials,
|
||||
}
|
||||
|
||||
if _, err := client.DeleteSnapshot(ctx, &req); err != nil {
|
||||
@@ -232,7 +238,7 @@ func (c *csiConnection) DeleteSnapshot(ctx context.Context, snapshotID string, s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *csiConnection) GetSnapshotStatus(ctx context.Context, snapshotID string) (*csi.SnapshotStatus, int64, int64, error) {
|
||||
func (c *csiConnection) GetSnapshotStatus(ctx context.Context, snapshotID string) (bool, int64, int64, error) {
|
||||
client := csi.NewControllerClient(c.conn)
|
||||
|
||||
req := csi.ListSnapshotsRequest{
|
||||
@@ -241,14 +247,18 @@ func (c *csiConnection) GetSnapshotStatus(ctx context.Context, snapshotID string
|
||||
|
||||
rsp, err := client.ListSnapshots(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
return false, 0, 0, err
|
||||
}
|
||||
|
||||
if rsp.Entries == nil || len(rsp.Entries) == 0 {
|
||||
return nil, 0, 0, fmt.Errorf("can not find snapshot for snapshotID %s", snapshotID)
|
||||
return false, 0, 0, fmt.Errorf("can not find snapshot for snapshotID %s", snapshotID)
|
||||
}
|
||||
|
||||
return rsp.Entries[0].Snapshot.Status, rsp.Entries[0].Snapshot.CreatedAt, rsp.Entries[0].Snapshot.SizeBytes, nil
|
||||
creationTime, err := timestampToUnixTime(rsp.Entries[0].Snapshot.CreationTime)
|
||||
if err != nil {
|
||||
return false, 0, 0, err
|
||||
}
|
||||
return rsp.Entries[0].Snapshot.ReadyToUse, creationTime, rsp.Entries[0].Snapshot.SizeBytes, nil
|
||||
}
|
||||
|
||||
func (c *csiConnection) Close() error {
|
||||
@@ -262,3 +272,13 @@ func logGRPC(ctx context.Context, method string, req, reply interface{}, cc *grp
|
||||
glog.V(5).Infof("GRPC error: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
func timestampToUnixTime(t *timestamp.Timestamp) (int64, error) {
|
||||
time, err := ptypes.Timestamp(t)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
// TODO: clean this up, we probably don't need this translation layer
|
||||
// and can just use time.Time
|
||||
return time.UnixNano(), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user