Skip to content

Commit 9eee065

Browse files
authored
Merge pull request #331 from davidz627/fix/lint
LOW PRIORITY Fix random lint errors
2 parents e59f47e + 6424e12 commit 9eee065

File tree

7 files changed

+82
-83
lines changed

7 files changed

+82
-83
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
# GCP Compute Persistent Disk CSI Driver
2+
13
WARNING: This driver is beta and should not be used in performance critical applications
24

35
DISCLAIMER: This is not an officially supported Google product
46

5-
# GCP Compute Persistent Disk CSI Driver
6-
77
The GCP Compute Persistent Disk CSI Driver is a
88
[CSI](https://github.com/container-storage-interface/spec/blob/master/spec.md)
99
Specification compliant driver used by Container Orchestrators to manage the
1010
lifecycle of Google Compute Engine Persistent Disks.
1111

1212
## Project Status
13+
1314
Status: Beta
1415
Latest stable image: `gcr.io/gke-release/gcp-compute-persistent-disk-csi-driver:v0.5.1-gke.0`
1516

@@ -27,7 +28,6 @@ Latest stable image: `gcr.io/gke-release/gcp-compute-persistent-disk-csi-driver:
2728
| HEAD Latest | HEAD (Migration ON) | [<img alt="Test Status" src="https://testgrid.k8s.io/q/summary/sig-gcp-compute-persistent-disk-csi-driver/Migration%20Kubernetes%20Master%20Driver%20Latest/tests_status" />](https://testgrid.k8s.io/sig-gcp-compute-persistent-disk-csi-driver#Migration%20Kubernetes%20Master%20Driver%20Latest) |
2829
| HEAD Stable | HEAD (Migration ON) | [<img alt="Test Status" src="https://testgrid.k8s.io/q/summary/sig-gcp-compute-persistent-disk-csi-driver/Migration%20Kubernetes%20Master%20Driver%20Stable/tests_status" />](https://testgrid.k8s.io/sig-gcp-compute-persistent-disk-csi-driver#Migration%20Kubernetes%20Master%20Driver%20Stable) |
2930

30-
3131
### CSI Compatibility
3232

3333
This plugin is compatible with CSI versions [v1.0.0](https://github.com/container-storage-interface/spec/blob/v1.0.0/spec.md)

pkg/gce-cloud-provider/compute/fake-gce.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (cloud *FakeCloudProvider) ValidateExistingDisk(ctx context.Context, resp *
187187
return nil
188188
}
189189

190-
func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotId, diskEncryptionKmsKey string) error {
190+
func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotID, diskEncryptionKmsKey string) error {
191191
if disk, ok := cloud.disks[volKey.Name]; ok {
192192
err := cloud.ValidateExistingDisk(ctx, disk, diskType,
193193
int64(capacityRange.GetRequiredBytes()),
@@ -206,7 +206,7 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
206206
Description: "Disk created by GCE-PD CSI Driver",
207207
Type: cloud.GetDiskTypeURI(volKey, diskType),
208208
SelfLink: fmt.Sprintf("projects/%s/zones/%s/disks/%s", cloud.project, volKey.Zone, volKey.Name),
209-
SourceSnapshotId: snapshotId,
209+
SourceSnapshotId: snapshotID,
210210
}
211211
if diskEncryptionKmsKey != "" {
212212
diskToCreateGA.DiskEncryptionKey = &compute.CustomerEncryptionKey{
@@ -221,7 +221,7 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
221221
Description: "Regional disk created by GCE-PD CSI Driver",
222222
Type: cloud.GetDiskTypeURI(volKey, diskType),
223223
SelfLink: fmt.Sprintf("projects/%s/regions/%s/disks/%s", cloud.project, volKey.Region, volKey.Name),
224-
SourceSnapshotId: snapshotId,
224+
SourceSnapshotId: snapshotID,
225225
}
226226
if diskEncryptionKmsKey != "" {
227227
diskToCreateBeta.DiskEncryptionKey = &computebeta.CustomerEncryptionKey{

pkg/gce-cloud-provider/compute/gce-compute.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type GCECompute interface {
4343
GetDisk(ctx context.Context, volumeKey *meta.Key) (*CloudDisk, error)
4444
RepairUnderspecifiedVolumeKey(ctx context.Context, volumeKey *meta.Key) (*meta.Key, error)
4545
ValidateExistingDisk(ctx context.Context, disk *CloudDisk, diskType string, reqBytes, limBytes int64) error
46-
InsertDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotId, diskEncryptionKmsKey string) error
46+
InsertDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotID, diskEncryptionKmsKey string) error
4747
DeleteDisk(ctx context.Context, volumeKey *meta.Key) error
4848
AttachDisk(ctx context.Context, volKey *meta.Key, readWrite, diskType, instanceZone, instanceName string) error
4949
DetachDisk(ctx context.Context, deviceName string, instanceZone, instanceName string) error
@@ -204,26 +204,26 @@ func (cloud *CloudProvider) ValidateExistingDisk(ctx context.Context, resp *Clou
204204
return nil
205205
}
206206

207-
func (cloud *CloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotId, diskEncryptionKmsKey string) error {
207+
func (cloud *CloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotID, diskEncryptionKmsKey string) error {
208208
switch volKey.Type() {
209209
case meta.Zonal:
210-
return cloud.insertZonalDisk(ctx, volKey, diskType, capBytes, capacityRange, snapshotId, diskEncryptionKmsKey)
210+
return cloud.insertZonalDisk(ctx, volKey, diskType, capBytes, capacityRange, snapshotID, diskEncryptionKmsKey)
211211
case meta.Regional:
212-
return cloud.insertRegionalDisk(ctx, volKey, diskType, capBytes, capacityRange, replicaZones, snapshotId, diskEncryptionKmsKey)
212+
return cloud.insertRegionalDisk(ctx, volKey, diskType, capBytes, capacityRange, replicaZones, snapshotID, diskEncryptionKmsKey)
213213
default:
214214
return fmt.Errorf("could not insert disk, key was neither zonal nor regional, instead got: %v", volKey.String())
215215
}
216216
}
217217

218-
func (cloud *CloudProvider) insertRegionalDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotId, diskEncryptionKmsKey string) error {
218+
func (cloud *CloudProvider) insertRegionalDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, replicaZones []string, snapshotID, diskEncryptionKmsKey string) error {
219219
diskToCreateBeta := &computebeta.Disk{
220220
Name: volKey.Name,
221221
SizeGb: common.BytesToGb(capBytes),
222222
Description: "Regional disk created by GCE-PD CSI Driver",
223223
Type: cloud.GetDiskTypeURI(volKey, diskType),
224224
}
225-
if snapshotId != "" {
226-
diskToCreateBeta.SourceSnapshot = snapshotId
225+
if snapshotID != "" {
226+
diskToCreateBeta.SourceSnapshot = snapshotID
227227
}
228228
if len(replicaZones) != 0 {
229229
diskToCreateBeta.ReplicaZones = replicaZones
@@ -274,16 +274,16 @@ func (cloud *CloudProvider) insertRegionalDisk(ctx context.Context, volKey *meta
274274
return nil
275275
}
276276

277-
func (cloud *CloudProvider) insertZonalDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, snapshotId, diskEncryptionKmsKey string) error {
277+
func (cloud *CloudProvider) insertZonalDisk(ctx context.Context, volKey *meta.Key, diskType string, capBytes int64, capacityRange *csi.CapacityRange, snapshotID, diskEncryptionKmsKey string) error {
278278
diskToCreate := &compute.Disk{
279279
Name: volKey.Name,
280280
SizeGb: common.BytesToGb(capBytes),
281281
Description: "Disk created by GCE-PD CSI Driver",
282282
Type: cloud.GetDiskTypeURI(volKey, diskType),
283283
}
284284

285-
if snapshotId != "" {
286-
diskToCreate.SourceSnapshot = snapshotId
285+
if snapshotID != "" {
286+
diskToCreate.SourceSnapshot = snapshotID
287287
}
288288

289289
if diskEncryptionKmsKey != "" {

pkg/gce-pd-csi-driver/controller.go

+19-20
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const (
5858

5959
DiskTypeSSD = "pd-ssd"
6060
DiskTypeStandard = "pd-standard"
61-
diskTypeDefault = DiskTypeStandard
6261

6362
attachableDiskTypePersistent = "PERSISTENT"
6463

@@ -171,19 +170,19 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
171170
return generateCreateVolumeResponse(existingDisk, capBytes, zones), nil
172171
}
173172

174-
snapshotId := ""
173+
snapshotID := ""
175174
content := req.GetVolumeContentSource()
176175
if content != nil {
177176
if content.GetSnapshot() != nil {
178177
// TODO(#161): Add support for Volume Source (cloning) introduced in CSI v1.0.0
179-
snapshotId = content.GetSnapshot().GetSnapshotId()
178+
snapshotID = content.GetSnapshot().GetSnapshotId()
180179

181180
// Verify that snapshot exists
182-
sl, err := gceCS.getSnapshotById(ctx, snapshotId)
181+
sl, err := gceCS.getSnapshotByID(ctx, snapshotID)
183182
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)
185184
} 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)
187186
}
188187
}
189188
}
@@ -195,15 +194,15 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
195194
if len(zones) != 1 {
196195
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v", zones))
197196
}
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)
199198
if err != nil {
200199
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume failed to create single zonal disk %#v: %v", name, err))
201200
}
202201
case replicationTypeRegionalPD:
203202
if len(zones) != 2 {
204203
return nil, status.Errorf(codes.Internal, fmt.Sprintf("CreateVolume failed to get a 2 zones for creating regional disk, instead got: %v", zones))
205204
}
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)
207206
if err != nil {
208207
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume failed to create regional disk %#v: %v", name, err))
209208
}
@@ -651,7 +650,7 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
651650

652651
// case 1: SnapshotId is not empty, return snapshots that match the snapshot id.
653652
if len(req.GetSnapshotId()) != 0 {
654-
return gceCS.getSnapshotById(ctx, req.GetSnapshotId())
653+
return gceCS.getSnapshotByID(ctx, req.GetSnapshotId())
655654
}
656655

657656
// 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
686685
}
687686

688687
func (gceCS *GCEControllerServer) getSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
689-
snapshots := []*compute.Snapshot{}
688+
var snapshots []*compute.Snapshot
690689
var nextToken string
691690
var err error
692691
if len(req.GetSourceVolumeId()) != 0 {
@@ -717,11 +716,11 @@ func (gceCS *GCEControllerServer) getSnapshots(ctx context.Context, req *csi.Lis
717716

718717
}
719718

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)
722721
if err != nil {
723722
// 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)
725724
return &csi.ListSnapshotsResponse{}, nil
726725
}
727726

@@ -953,12 +952,12 @@ func generateCreateVolumeResponse(disk *gce.CloudDisk, capBytes int64, zones []s
953952
AccessibleTopology: tops,
954953
},
955954
}
956-
snapshotId := disk.GetSnapshotId()
957-
if snapshotId != "" {
955+
snapshotID := disk.GetSnapshotId()
956+
if snapshotID != "" {
958957
source := &csi.VolumeContentSource{
959958
Type: &csi.VolumeContentSource_Snapshot{
960959
Snapshot: &csi.VolumeContentSource_SnapshotSource{
961-
SnapshotId: snapshotId,
960+
SnapshotId: snapshotID,
962961
},
963962
},
964963
}
@@ -973,7 +972,7 @@ func cleanSelfLink(selfLink string) string {
973972
return strings.TrimPrefix(temp, gce.GCEComputeBetaAPIEndpoint)
974973
}
975974

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) {
977976
region, err := common.GetRegionFromZones(zones)
978977
if err != nil {
979978
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
985984
fullyQualifiedReplicaZones, cloudProvider.GetReplicaZoneURI(replicaZone))
986985
}
987986

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)
989988
if err != nil {
990989
return nil, fmt.Errorf("failed to insert regional disk: %v", err)
991990
}
@@ -999,12 +998,12 @@ func createRegionalDisk(ctx context.Context, cloudProvider gce.GCECompute, name
999998
return disk, nil
1000999
}
10011000

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) {
10031002
if len(zones) != 1 {
10041003
return nil, fmt.Errorf("got wrong number of zones for zonal create volume: %v", len(zones))
10051004
}
10061005
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)
10081007
if err != nil {
10091008
return nil, fmt.Errorf("failed to insert zonal disk: %v", err)
10101009
}

0 commit comments

Comments
 (0)