Skip to content

Commit bf1aafc

Browse files
Switch to use compute v0.beta
1 parent f1673ea commit bf1aafc

File tree

4 files changed

+61
-16
lines changed

4 files changed

+61
-16
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,14 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, project string,
196196
}
197197

198198
computeDisk := &computev1.Disk{
199-
Name: volKey.Name,
200-
SizeGb: common.BytesToGbRoundUp(capBytes),
201-
Description: "Disk created by GCE-PD CSI Driver",
202-
Type: cloud.GetDiskTypeURI(project, volKey, params.DiskType),
203-
SourceDiskId: volumeContentSourceVolumeID,
204-
Status: cloud.mockDiskStatus,
205-
Labels: params.Labels,
206-
ProvisionedIops: params.ProvisionedIOPSOnCreate,
207-
ProvisionedThroughput: params.ProvisionedThroughputOnCreate,
199+
Name: volKey.Name,
200+
SizeGb: common.BytesToGbRoundUp(capBytes),
201+
Description: "Disk created by GCE-PD CSI Driver",
202+
Type: cloud.GetDiskTypeURI(project, volKey, params.DiskType),
203+
SourceDiskId: volumeContentSourceVolumeID,
204+
Status: cloud.mockDiskStatus,
205+
Labels: params.Labels,
206+
ProvisionedIops: params.ProvisionedIOPSOnCreate,
208207
}
209208

210209
if snapshotID != "" {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444
)
4545

4646
var pdDiskTypeUnsupportedRegex = regexp.MustCompile(pdDiskTypeUnsupportedPattern)
47+
var hyperdiskTypes = []string{"hyperdisk-extreme", "hyperdisk-throughput"}
4748

4849
type GCEAPIVersion string
4950

@@ -559,7 +560,7 @@ func (cloud *CloudProvider) insertZonalDisk(
559560
gceAPIVersion = GCEAPIVersionV1
560561
)
561562

562-
if multiWriter {
563+
if multiWriter || containsBetaDiskType(hyperdiskTypes, params.DiskType) {
563564
gceAPIVersion = GCEAPIVersionBeta
564565
}
565566

@@ -1198,3 +1199,13 @@ func encodeTags(tags map[string]string) (string, error) {
11981199
}
11991200
return string(enc), nil
12001201
}
1202+
1203+
func containsBetaDiskType(betaDiskTypes []string, diskType string) bool {
1204+
for _, betaDiskType := range betaDiskTypes {
1205+
if betaDiskType == diskType {
1206+
return true
1207+
}
1208+
}
1209+
1210+
return false
1211+
}

test/e2e/tests/setup_e2e_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
. "github.com/onsi/ginkgo"
2828
. "github.com/onsi/gomega"
2929
computealpha "google.golang.org/api/compute/v0.alpha"
30+
computebeta "google.golang.org/api/compute/v0.beta"
3031
compute "google.golang.org/api/compute/v1"
3132
"k8s.io/klog/v2"
3233
testutils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
@@ -46,6 +47,7 @@ var (
4647
testContexts = []*remote.TestContext{}
4748
computeService *compute.Service
4849
computeAlphaService *computealpha.Service
50+
computeBetaService *computebeta.Service
4951
kmsClient *cloudkms.KeyManagementClient
5052
)
5153

@@ -75,6 +77,9 @@ var _ = BeforeSuite(func() {
7577
computeAlphaService, err = remote.GetComputeAlphaClient()
7678
Expect(err).To(BeNil())
7779

80+
computeBetaService, err = remote.GetComputeBetaClient()
81+
Expect(err).To(BeNil())
82+
7883
// Create the KMS client.
7984
kmsClient, err = cloudkms.NewKeyManagementClient(context.Background())
8085
Expect(err).To(BeNil())

test/remote/instance.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"golang.org/x/oauth2/google"
3030
computealpha "google.golang.org/api/compute/v0.alpha"
31+
computebeta "google.golang.org/api/compute/v0.beta"
3132
compute "google.golang.org/api/compute/v1"
3233
"google.golang.org/api/googleapi"
3334
"k8s.io/apimachinery/pkg/util/uuid"
@@ -71,12 +72,11 @@ func (i *InstanceInfo) GetNodeID() string {
7172

7273
func CreateInstanceInfo(project, instanceArchitecture, instanceZone, name, machineType string, cs *compute.Service) (*InstanceInfo, error) {
7374
return &InstanceInfo{
74-
project: project,
75-
architecture: instanceArchitecture,
76-
zone: instanceZone,
77-
name: name,
78-
machineType: machineType,
79-
75+
project: project,
76+
architecture: instanceArchitecture,
77+
zone: instanceZone,
78+
name: name,
79+
machineType: machineType,
8080
computeService: cs,
8181
}, nil
8282
}
@@ -330,6 +330,36 @@ func GetComputeAlphaClient() (*computealpha.Service, error) {
330330
return nil, err
331331
}
332332

333+
func GetComputeBetaClient() (*computebeta.Service, error) {
334+
const retries = 10
335+
const backoff = time.Second * 6
336+
337+
klog.V(4).Infof("Getting compute client...")
338+
339+
// Setup the gce client for provisioning instances
340+
// Getting credentials on gce jenkins is flaky, so try a couple times
341+
var err error
342+
var cs *computebeta.Service
343+
for i := 0; i < retries; i++ {
344+
if i > 0 {
345+
time.Sleep(backoff)
346+
}
347+
348+
var client *http.Client
349+
client, err = google.DefaultClient(context.Background(), computebeta.ComputeScope)
350+
if err != nil {
351+
continue
352+
}
353+
354+
cs, err = computebeta.New(client)
355+
if err != nil {
356+
continue
357+
}
358+
return cs, nil
359+
}
360+
return nil, err
361+
}
362+
333363
func generateMetadataWithPublicKey(pubKeyFile string) (*compute.Metadata, error) {
334364
publicKeyByte, err := ioutil.ReadFile(pubKeyFile)
335365
if err != nil {

0 commit comments

Comments
 (0)