Skip to content

Commit 01a3ba2

Browse files
authored
Merge pull request #404 from davidz627/fix/rePDAPI
Move all RePD compute API calls to v1 from v1beta
2 parents b152af2 + 1f9ca24 commit 01a3ba2

File tree

8 files changed

+90
-170
lines changed

8 files changed

+90
-170
lines changed

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ limitations under the License.
1515
package gcecloudprovider
1616

1717
import (
18-
computebeta "google.golang.org/api/compute/v0.beta"
19-
compute "google.golang.org/api/compute/v1"
18+
computev1 "google.golang.org/api/compute/v1"
2019
)
2120

2221
type CloudDisk struct {
23-
ZonalDisk *compute.Disk
24-
RegionalDisk *computebeta.Disk
22+
ZonalDisk *computev1.Disk
23+
RegionalDisk *computev1.Disk
2524
}
2625

2726
type CloudDiskType string
@@ -35,13 +34,13 @@ const (
3534
Global = "global"
3635
)
3736

38-
func ZonalCloudDisk(disk *compute.Disk) *CloudDisk {
37+
func ZonalCloudDisk(disk *computev1.Disk) *CloudDisk {
3938
return &CloudDisk{
4039
ZonalDisk: disk,
4140
}
4241
}
4342

44-
func RegionalCloudDisk(disk *computebeta.Disk) *CloudDisk {
43+
func RegionalCloudDisk(disk *computev1.Disk) *CloudDisk {
4544
return &CloudDisk{
4645
RegionalDisk: disk,
4746
}

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

+29-40
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import (
2222

2323
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
2424
csi "github.com/container-storage-interface/spec/lib/go/csi"
25-
computebeta "google.golang.org/api/compute/v0.beta"
26-
compute "google.golang.org/api/compute/v1"
25+
computev1 "google.golang.org/api/compute/v1"
2726
"google.golang.org/api/googleapi"
2827
"google.golang.org/grpc/codes"
2928
"google.golang.org/grpc/status"
@@ -43,8 +42,8 @@ type FakeCloudProvider struct {
4342
zone string
4443

4544
disks map[string]*CloudDisk
46-
instances map[string]*compute.Instance
47-
snapshots map[string]*compute.Snapshot
45+
instances map[string]*computev1.Instance
46+
snapshots map[string]*computev1.Snapshot
4847
}
4948

5049
var _ GCECompute = &FakeCloudProvider{}
@@ -54,8 +53,8 @@ func CreateFakeCloudProvider(project, zone string, cloudDisks []*CloudDisk) (*Fa
5453
project: project,
5554
zone: zone,
5655
disks: map[string]*CloudDisk{},
57-
instances: map[string]*compute.Instance{},
58-
snapshots: map[string]*compute.Snapshot{},
56+
instances: map[string]*computev1.Instance{},
57+
snapshots: map[string]*computev1.Snapshot{},
5958
}
6059
for _, d := range cloudDisks {
6160
fcp.disks[d.GetName()] = d
@@ -95,9 +94,9 @@ func (cloud *FakeCloudProvider) ListZones(ctx context.Context, region string) ([
9594
return []string{cloud.zone, "country-region-fakesecondzone"}, nil
9695
}
9796

98-
func (cloud *FakeCloudProvider) ListSnapshots(ctx context.Context, filter string, maxEntries int64, pageToken string) ([]*compute.Snapshot, string, error) {
97+
func (cloud *FakeCloudProvider) ListSnapshots(ctx context.Context, filter string, maxEntries int64, pageToken string) ([]*computev1.Snapshot, string, error) {
9998
var sourceDisk string
100-
snapshots := []*compute.Snapshot{}
99+
snapshots := []*computev1.Snapshot{}
101100
if len(filter) > 0 {
102101
filterSplits := strings.Fields(filter)
103102
if len(filterSplits) != 3 || filterSplits[0] != "sourceDisk" {
@@ -141,7 +140,7 @@ func (cloud *FakeCloudProvider) ListSnapshots(ctx context.Context, filter string
141140
max = rem
142141
}
143142

144-
results := []*compute.Snapshot{}
143+
results := []*computev1.Snapshot{}
145144
j := startingToken
146145
for i := 0; i < max; i++ {
147146
results = append(results, snapshots[j])
@@ -200,7 +199,7 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
200199
var diskToCreate *CloudDisk
201200
switch volKey.Type() {
202201
case meta.Zonal:
203-
diskToCreateGA := &compute.Disk{
202+
diskToCreateGA := &computev1.Disk{
204203
Name: volKey.Name,
205204
SizeGb: common.BytesToGb(capBytes),
206205
Description: "Disk created by GCE-PD CSI Driver",
@@ -209,13 +208,13 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
209208
SourceSnapshotId: snapshotID,
210209
}
211210
if diskEncryptionKmsKey != "" {
212-
diskToCreateGA.DiskEncryptionKey = &compute.CustomerEncryptionKey{
211+
diskToCreateGA.DiskEncryptionKey = &computev1.CustomerEncryptionKey{
213212
KmsKeyName: diskEncryptionKmsKey,
214213
}
215214
}
216215
diskToCreate = ZonalCloudDisk(diskToCreateGA)
217216
case meta.Regional:
218-
diskToCreateBeta := &computebeta.Disk{
217+
diskToCreateV1 := &computev1.Disk{
219218
Name: volKey.Name,
220219
SizeGb: common.BytesToGb(capBytes),
221220
Description: "Regional disk created by GCE-PD CSI Driver",
@@ -224,11 +223,11 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
224223
SourceSnapshotId: snapshotID,
225224
}
226225
if diskEncryptionKmsKey != "" {
227-
diskToCreateBeta.DiskEncryptionKey = &computebeta.CustomerEncryptionKey{
226+
diskToCreateV1.DiskEncryptionKey = &computev1.CustomerEncryptionKey{
228227
KmsKeyName: diskEncryptionKmsKey,
229228
}
230229
}
231-
diskToCreate = RegionalCloudDisk(diskToCreateBeta)
230+
diskToCreate = RegionalCloudDisk(diskToCreateV1)
232231
default:
233232
return fmt.Errorf("could not create disk, key was neither zonal nor regional, instead got: %v", volKey.String())
234233
}
@@ -248,7 +247,7 @@ func (cloud *FakeCloudProvider) DeleteDisk(ctx context.Context, volKey *meta.Key
248247
func (cloud *FakeCloudProvider) AttachDisk(ctx context.Context, volKey *meta.Key, readWrite, diskType, instanceZone, instanceName string) error {
249248
source := cloud.GetDiskSourceURI(volKey)
250249

251-
attachedDiskV1 := &compute.AttachedDisk{
250+
attachedDiskV1 := &computev1.AttachedDisk{
252251
DeviceName: volKey.Name,
253252
Kind: diskKind,
254253
Mode: readWrite,
@@ -309,12 +308,12 @@ func (cloud *FakeCloudProvider) GetReplicaZoneURI(zone string) string {
309308
}
310309

311310
// Instance Methods
312-
func (cloud *FakeCloudProvider) InsertInstance(instance *compute.Instance, instanceZone, instanceName string) {
311+
func (cloud *FakeCloudProvider) InsertInstance(instance *computev1.Instance, instanceZone, instanceName string) {
313312
cloud.instances[instanceName] = instance
314313
return
315314
}
316315

317-
func (cloud *FakeCloudProvider) GetInstanceOrError(ctx context.Context, instanceZone, instanceName string) (*compute.Instance, error) {
316+
func (cloud *FakeCloudProvider) GetInstanceOrError(ctx context.Context, instanceZone, instanceName string) (*computev1.Instance, error) {
318317
instance, ok := cloud.instances[instanceName]
319318
if !ok {
320319
return nil, notFoundError()
@@ -323,7 +322,7 @@ func (cloud *FakeCloudProvider) GetInstanceOrError(ctx context.Context, instance
323322
}
324323

325324
// Snapshot Methods
326-
func (cloud *FakeCloudProvider) GetSnapshot(ctx context.Context, snapshotName string) (*compute.Snapshot, error) {
325+
func (cloud *FakeCloudProvider) GetSnapshot(ctx context.Context, snapshotName string) (*computev1.Snapshot, error) {
327326
snapshot, ok := cloud.snapshots[snapshotName]
328327
if !ok {
329328
return nil, notFoundError()
@@ -332,33 +331,23 @@ func (cloud *FakeCloudProvider) GetSnapshot(ctx context.Context, snapshotName st
332331
return snapshot, nil
333332
}
334333

335-
func (cloud *FakeCloudProvider) CreateSnapshot(ctx context.Context, volKey *meta.Key, snapshotName string) (*compute.Snapshot, error) {
334+
func (cloud *FakeCloudProvider) CreateSnapshot(ctx context.Context, volKey *meta.Key, snapshotName string) (*computev1.Snapshot, error) {
336335
if snapshot, ok := cloud.snapshots[snapshotName]; ok {
337336
return snapshot, nil
338337
}
339338

340-
var snapshotToCreate *compute.Snapshot
339+
snapshotToCreate := &computev1.Snapshot{
340+
Name: snapshotName,
341+
DiskSizeGb: int64(DiskSizeGb),
342+
CreationTimestamp: Timestamp,
343+
Status: "UPLOADING",
344+
SelfLink: cloud.getGlobalSnapshotURI(snapshotName),
345+
}
341346
switch volKey.Type() {
342347
case meta.Zonal:
343-
snapshotToCreateGA := &compute.Snapshot{
344-
Name: snapshotName,
345-
DiskSizeGb: int64(DiskSizeGb),
346-
CreationTimestamp: Timestamp,
347-
Status: "UPLOADING",
348-
SelfLink: cloud.getGlobalSnapshotURI(snapshotName),
349-
SourceDisk: cloud.getZonalDiskSourceURI(volKey.Name, volKey.Zone),
350-
}
351-
snapshotToCreate = snapshotToCreateGA
348+
snapshotToCreate.SourceDisk = cloud.getZonalDiskSourceURI(volKey.Name, volKey.Zone)
352349
case meta.Regional:
353-
snapshotToCreateBeta := &compute.Snapshot{
354-
Name: volKey.Name,
355-
DiskSizeGb: int64(DiskSizeGb),
356-
CreationTimestamp: Timestamp,
357-
Status: "UPLOADING",
358-
SelfLink: cloud.getGlobalSnapshotURI(snapshotName),
359-
SourceDisk: cloud.getRegionalDiskSourceURI(volKey.Name, volKey.Region),
360-
}
361-
snapshotToCreate = snapshotToCreateBeta
350+
snapshotToCreate.SourceDisk = cloud.getRegionalDiskSourceURI(volKey.Name, volKey.Region)
362351
default:
363352
return nil, fmt.Errorf("could not create snapshot, disk key was neither zonal nor regional, instead got: %v", volKey.String())
364353
}
@@ -385,7 +374,7 @@ func (cloud *FakeCloudProvider) DeleteSnapshot(ctx context.Context, snapshotName
385374
return nil
386375
}
387376

388-
func (cloud *FakeCloudProvider) ValidateExistingSnapshot(resp *compute.Snapshot, volKey *meta.Key) error {
377+
func (cloud *FakeCloudProvider) ValidateExistingSnapshot(resp *computev1.Snapshot, volKey *meta.Key) error {
389378
if resp == nil {
390379
return fmt.Errorf("disk does not exist")
391380
}
@@ -442,7 +431,7 @@ type FakeBlockingCloudProvider struct {
442431
// Upon starting a CreateSnapshot, it passes a chan 'executeCreateSnapshot' into readyToExecute, then blocks on executeCreateSnapshot.
443432
// The test calling this function can block on readyToExecute to ensure that the operation has started and
444433
// allowed the CreateSnapshot to continue by passing a struct into executeCreateSnapshot.
445-
func (cloud *FakeBlockingCloudProvider) CreateSnapshot(ctx context.Context, volKey *meta.Key, snapshotName string) (*compute.Snapshot, error) {
434+
func (cloud *FakeBlockingCloudProvider) CreateSnapshot(ctx context.Context, volKey *meta.Key, snapshotName string) (*computev1.Snapshot, error) {
446435
executeCreateSnapshot := make(chan struct{})
447436
cloud.ReadyToExecute <- executeCreateSnapshot
448437
<-executeCreateSnapshot

0 commit comments

Comments
 (0)