@@ -25,6 +25,8 @@ import (
2525
2626	"github.com/container-storage-interface/spec/lib/go/csi" 
2727	"github.com/golang/glog" 
28+ 	"github.com/golang/protobuf/ptypes" 
29+ 	"github.com/golang/protobuf/ptypes/timestamp" 
2830	"google.golang.org/grpc" 
2931	"google.golang.org/grpc/connectivity" 
3032	"k8s.io/api/core/v1" 
@@ -46,13 +48,13 @@ type CSIConnection interface {
4648	SupportsControllerListSnapshots (ctx  context.Context ) (bool , error )
4749
4850	// CreateSnapshot creates a snapshot for a volume 
49- 	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 )
51+ 	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 )
5052
5153	// DeleteSnapshot deletes a snapshot from a volume 
5254	DeleteSnapshot (ctx  context.Context , snapshotID  string , snapshotterCredentials  map [string ]string ) (err  error )
5355
54- 	// GetSnapshotStatus returns a snapshot's status , creation time, and restore size. 
55- 	GetSnapshotStatus (ctx  context.Context , snapshotID  string ) (* csi. SnapshotStatus , int64 , int64 , error )
56+ 	// GetSnapshotStatus returns if  a snapshot is ready to use , creation time, and restore size. 
57+ 	GetSnapshotStatus (ctx  context.Context , snapshotID  string ) (bool , int64 , int64 , error )
5658
5759	// Probe checks that the CSI driver is ready to process requests 
5860	Probe (ctx  context.Context ) error 
@@ -188,41 +190,45 @@ func (c *csiConnection) SupportsControllerListSnapshots(ctx context.Context) (bo
188190	return  false , nil 
189191}
190192
191- 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 ) {
193+ 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 ) {
192194	glog .V (5 ).Infof ("CSI CreateSnapshot: %s" , snapshotName )
193195	if  volume .Spec .CSI  ==  nil  {
194- 		return  "" , "" , 0 , 0 , nil , fmt .Errorf ("CSIPersistentVolumeSource not defined in spec" )
196+ 		return  "" , "" , 0 , 0 , false , fmt .Errorf ("CSIPersistentVolumeSource not defined in spec" )
195197	}
196198
197199	client  :=  csi .NewControllerClient (c .conn )
198200
199201	driverName , err  :=  c .GetDriverName (ctx )
200202	if  err  !=  nil  {
201- 		return  "" , "" , 0 , 0 , nil , err 
203+ 		return  "" , "" , 0 , 0 , false , err 
202204	}
203205
204206	req  :=  csi.CreateSnapshotRequest {
205- 		SourceVolumeId :         volume .Spec .CSI .VolumeHandle ,
206- 		Name :                   snapshotName ,
207- 		Parameters :             parameters ,
208- 		CreateSnapshotSecrets :  snapshotterCredentials ,
207+ 		SourceVolumeId : volume .Spec .CSI .VolumeHandle ,
208+ 		Name :           snapshotName ,
209+ 		Parameters :     parameters ,
210+ 		Secrets :         snapshotterCredentials ,
209211	}
210212
211213	rsp , err  :=  client .CreateSnapshot (ctx , & req )
212214	if  err  !=  nil  {
213- 		return  "" , "" , 0 , 0 , nil , err 
215+ 		return  "" , "" , 0 , 0 , false , err 
214216	}
215217
216- 	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 )
217- 	return  driverName , rsp .Snapshot .Id , rsp .Snapshot .CreatedAt , rsp .Snapshot .SizeBytes , rsp .Snapshot .Status , nil 
218+ 	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 )
219+ 	creationTime , err  :=  timestampToUnixTime (rsp .Snapshot .CreationTime )
220+ 	if  err  !=  nil  {
221+ 		return  "" , "" , 0 , 0 , false , err 
222+ 	}
223+ 	return  driverName , rsp .Snapshot .SnapshotId , creationTime , rsp .Snapshot .SizeBytes , rsp .Snapshot .ReadyToUse , nil 
218224}
219225
220226func  (c  * csiConnection ) DeleteSnapshot (ctx  context.Context , snapshotID  string , snapshotterCredentials  map [string ]string ) (err  error ) {
221227	client  :=  csi .NewControllerClient (c .conn )
222228
223229	req  :=  csi.DeleteSnapshotRequest {
224- 		SnapshotId :             snapshotID ,
225- 		DeleteSnapshotSecrets :  snapshotterCredentials ,
230+ 		SnapshotId : snapshotID ,
231+ 		Secrets :     snapshotterCredentials ,
226232	}
227233
228234	if  _ , err  :=  client .DeleteSnapshot (ctx , & req ); err  !=  nil  {
@@ -232,7 +238,7 @@ func (c *csiConnection) DeleteSnapshot(ctx context.Context, snapshotID string, s
232238	return  nil 
233239}
234240
235- func  (c  * csiConnection ) GetSnapshotStatus (ctx  context.Context , snapshotID  string ) (* csi. SnapshotStatus , int64 , int64 , error ) {
241+ func  (c  * csiConnection ) GetSnapshotStatus (ctx  context.Context , snapshotID  string ) (bool , int64 , int64 , error ) {
236242	client  :=  csi .NewControllerClient (c .conn )
237243
238244	req  :=  csi.ListSnapshotsRequest {
@@ -241,14 +247,18 @@ func (c *csiConnection) GetSnapshotStatus(ctx context.Context, snapshotID string
241247
242248	rsp , err  :=  client .ListSnapshots (ctx , & req )
243249	if  err  !=  nil  {
244- 		return  nil , 0 , 0 , err 
250+ 		return  false , 0 , 0 , err 
245251	}
246252
247253	if  rsp .Entries  ==  nil  ||  len (rsp .Entries ) ==  0  {
248- 		return  nil , 0 , 0 , fmt .Errorf ("can not find snapshot for snapshotID %s" , snapshotID )
254+ 		return  false , 0 , 0 , fmt .Errorf ("can not find snapshot for snapshotID %s" , snapshotID )
249255	}
250256
251- 	return  rsp .Entries [0 ].Snapshot .Status , rsp .Entries [0 ].Snapshot .CreatedAt , rsp .Entries [0 ].Snapshot .SizeBytes , nil 
257+ 	creationTime , err  :=  timestampToUnixTime (rsp .Entries [0 ].Snapshot .CreationTime )
258+ 	if  err  !=  nil  {
259+ 		return  false , 0 , 0 , err 
260+ 	}
261+ 	return  rsp .Entries [0 ].Snapshot .ReadyToUse , creationTime , rsp .Entries [0 ].Snapshot .SizeBytes , nil 
252262}
253263
254264func  (c  * csiConnection ) Close () error  {
@@ -262,3 +272,13 @@ func logGRPC(ctx context.Context, method string, req, reply interface{}, cc *grp
262272	glog .V (5 ).Infof ("GRPC error: %v" , err )
263273	return  err 
264274}
275+ 
276+ func  timestampToUnixTime (t  * timestamp.Timestamp ) (int64 , error ) {
277+ 	time , err  :=  ptypes .Timestamp (t )
278+ 	if  err  !=  nil  {
279+ 		return  - 1 , err 
280+ 	}
281+ 	// TODO: clean this up, we probably don't need this translation layer 
282+ 	// and can just use time.Time 
283+ 	return  time .UnixNano (), nil 
284+ }
0 commit comments