@@ -58,7 +58,6 @@ const (
58
58
59
59
DiskTypeSSD = "pd-ssd"
60
60
DiskTypeStandard = "pd-standard"
61
- diskTypeDefault = DiskTypeStandard
62
61
63
62
attachableDiskTypePersistent = "PERSISTENT"
64
63
@@ -171,19 +170,19 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
171
170
return generateCreateVolumeResponse (existingDisk , capBytes , zones ), nil
172
171
}
173
172
174
- snapshotId := ""
173
+ snapshotID := ""
175
174
content := req .GetVolumeContentSource ()
176
175
if content != nil {
177
176
if content .GetSnapshot () != nil {
178
177
// TODO(#161): Add support for Volume Source (cloning) introduced in CSI v1.0.0
179
- snapshotId = content .GetSnapshot ().GetSnapshotId ()
178
+ snapshotID = content .GetSnapshot ().GetSnapshotId ()
180
179
181
180
// Verify that snapshot exists
182
- sl , err := gceCS .getSnapshotById (ctx , snapshotId )
181
+ sl , err := gceCS .getSnapshotByID (ctx , snapshotID )
183
182
if err != nil {
184
- return nil , status .Errorf (codes .Internal , "CreateVolume failed to get snapshot %s: %v" , snapshotId , err )
183
+ return nil , status .Errorf (codes .Internal , "CreateVolume failed to get snapshot %s: %v" , snapshotID , err )
185
184
} else if len (sl .Entries ) == 0 {
186
- return nil , status .Errorf (codes .NotFound , "CreateVolume source snapshot %s does not exist" , snapshotId )
185
+ return nil , status .Errorf (codes .NotFound , "CreateVolume source snapshot %s does not exist" , snapshotID )
187
186
}
188
187
}
189
188
}
@@ -195,15 +194,15 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
195
194
if len (zones ) != 1 {
196
195
return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v" , zones ))
197
196
}
198
- disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , diskType , capacityRange , capBytes , snapshotId , diskEncryptionKmsKey )
197
+ disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , diskType , capacityRange , capBytes , snapshotID , diskEncryptionKmsKey )
199
198
if err != nil {
200
199
return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume failed to create single zonal disk %#v: %v" , name , err ))
201
200
}
202
201
case replicationTypeRegionalPD :
203
202
if len (zones ) != 2 {
204
203
return nil , status .Errorf (codes .Internal , fmt .Sprintf ("CreateVolume failed to get a 2 zones for creating regional disk, instead got: %v" , zones ))
205
204
}
206
- disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , diskType , capacityRange , capBytes , snapshotId , diskEncryptionKmsKey )
205
+ disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , diskType , capacityRange , capBytes , snapshotID , diskEncryptionKmsKey )
207
206
if err != nil {
208
207
return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume failed to create regional disk %#v: %v" , name , err ))
209
208
}
@@ -651,7 +650,7 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
651
650
652
651
// case 1: SnapshotId is not empty, return snapshots that match the snapshot id.
653
652
if len (req .GetSnapshotId ()) != 0 {
654
- return gceCS .getSnapshotById (ctx , req .GetSnapshotId ())
653
+ return gceCS .getSnapshotByID (ctx , req .GetSnapshotId ())
655
654
}
656
655
657
656
// case 2: no SnapshotId is set, so we return all the snapshots that satify the reqeust.
@@ -686,7 +685,7 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
686
685
}
687
686
688
687
func (gceCS * GCEControllerServer ) getSnapshots (ctx context.Context , req * csi.ListSnapshotsRequest ) (* csi.ListSnapshotsResponse , error ) {
689
- snapshots := []* compute.Snapshot {}
688
+ var snapshots []* compute.Snapshot
690
689
var nextToken string
691
690
var err error
692
691
if len (req .GetSourceVolumeId ()) != 0 {
@@ -717,11 +716,11 @@ func (gceCS *GCEControllerServer) getSnapshots(ctx context.Context, req *csi.Lis
717
716
718
717
}
719
718
720
- func (gceCS * GCEControllerServer ) getSnapshotById (ctx context.Context , snapshotId string ) (* csi.ListSnapshotsResponse , error ) {
721
- key , err := common .SnapshotIDToKey (snapshotId )
719
+ func (gceCS * GCEControllerServer ) getSnapshotByID (ctx context.Context , snapshotID string ) (* csi.ListSnapshotsResponse , error ) {
720
+ key , err := common .SnapshotIDToKey (snapshotID )
722
721
if err != nil {
723
722
// Cannot get snapshot ID from the passing request
724
- klog .Warningf ("invalid snapshot id format %s" , snapshotId )
723
+ klog .Warningf ("invalid snapshot id format %s" , snapshotID )
725
724
return & csi.ListSnapshotsResponse {}, nil
726
725
}
727
726
@@ -953,12 +952,12 @@ func generateCreateVolumeResponse(disk *gce.CloudDisk, capBytes int64, zones []s
953
952
AccessibleTopology : tops ,
954
953
},
955
954
}
956
- snapshotId := disk .GetSnapshotId ()
957
- if snapshotId != "" {
955
+ snapshotID := disk .GetSnapshotId ()
956
+ if snapshotID != "" {
958
957
source := & csi.VolumeContentSource {
959
958
Type : & csi.VolumeContentSource_Snapshot {
960
959
Snapshot : & csi.VolumeContentSource_SnapshotSource {
961
- SnapshotId : snapshotId ,
960
+ SnapshotId : snapshotID ,
962
961
},
963
962
},
964
963
}
@@ -973,7 +972,7 @@ func cleanSelfLink(selfLink string) string {
973
972
return strings .TrimPrefix (temp , gce .GCEComputeBetaAPIEndpoint )
974
973
}
975
974
976
- func createRegionalDisk (ctx context.Context , cloudProvider gce.GCECompute , name string , zones []string , diskType string , capacityRange * csi.CapacityRange , capBytes int64 , snapshotId , diskEncryptionKmsKey string ) (* gce.CloudDisk , error ) {
975
+ func createRegionalDisk (ctx context.Context , cloudProvider gce.GCECompute , name string , zones []string , diskType string , capacityRange * csi.CapacityRange , capBytes int64 , snapshotID , diskEncryptionKmsKey string ) (* gce.CloudDisk , error ) {
977
976
region , err := common .GetRegionFromZones (zones )
978
977
if err != nil {
979
978
return nil , fmt .Errorf ("failed to get region from zones: %v" , err )
@@ -985,7 +984,7 @@ func createRegionalDisk(ctx context.Context, cloudProvider gce.GCECompute, name
985
984
fullyQualifiedReplicaZones , cloudProvider .GetReplicaZoneURI (replicaZone ))
986
985
}
987
986
988
- err = cloudProvider .InsertDisk (ctx , meta .RegionalKey (name , region ), diskType , capBytes , capacityRange , fullyQualifiedReplicaZones , snapshotId , diskEncryptionKmsKey )
987
+ err = cloudProvider .InsertDisk (ctx , meta .RegionalKey (name , region ), diskType , capBytes , capacityRange , fullyQualifiedReplicaZones , snapshotID , diskEncryptionKmsKey )
989
988
if err != nil {
990
989
return nil , fmt .Errorf ("failed to insert regional disk: %v" , err )
991
990
}
@@ -999,12 +998,12 @@ func createRegionalDisk(ctx context.Context, cloudProvider gce.GCECompute, name
999
998
return disk , nil
1000
999
}
1001
1000
1002
- func createSingleZoneDisk (ctx context.Context , cloudProvider gce.GCECompute , name string , zones []string , diskType string , capacityRange * csi.CapacityRange , capBytes int64 , snapshotId , diskEncryptionKmsKey string ) (* gce.CloudDisk , error ) {
1001
+ func createSingleZoneDisk (ctx context.Context , cloudProvider gce.GCECompute , name string , zones []string , diskType string , capacityRange * csi.CapacityRange , capBytes int64 , snapshotID , diskEncryptionKmsKey string ) (* gce.CloudDisk , error ) {
1003
1002
if len (zones ) != 1 {
1004
1003
return nil , fmt .Errorf ("got wrong number of zones for zonal create volume: %v" , len (zones ))
1005
1004
}
1006
1005
diskZone := zones [0 ]
1007
- err := cloudProvider .InsertDisk (ctx , meta .ZonalKey (name , diskZone ), diskType , capBytes , capacityRange , nil , snapshotId , diskEncryptionKmsKey )
1006
+ err := cloudProvider .InsertDisk (ctx , meta .ZonalKey (name , diskZone ), diskType , capBytes , capacityRange , nil , snapshotID , diskEncryptionKmsKey )
1008
1007
if err != nil {
1009
1008
return nil , fmt .Errorf ("failed to insert zonal disk: %v" , err )
1010
1009
}
0 commit comments