Skip to content

Commit 9cb6caf

Browse files
authored
Merge pull request #1692 from mattcary/cloudtop
Fix e2e tests to run on cloudtop
2 parents 78ef53b + abaaf5c commit 9cb6caf

File tree

5 files changed

+61
-19
lines changed

5 files changed

+61
-19
lines changed

test/e2e/tests/setup_e2e_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
imageURL = flag.String("image-url", "projects/debian-cloud/global/images/family/debian-11", "OS image url to get image from")
4444
runInProw = flag.Bool("run-in-prow", false, "If true, use a Boskos loaned project and special CI service accounts and ssh keys")
4545
deleteInstances = flag.Bool("delete-instances", false, "Delete the instances after tests run")
46+
cloudtopHost = flag.Bool("cloudtop-host", false, "The local host is cloudtop, a kind of googler machine with special requirements to access GCP")
4647

4748
testContexts = []*remote.TestContext{}
4849
computeService *compute.Service
@@ -116,11 +117,21 @@ var _ = AfterSuite(func() {
116117
}
117118
})
118119

120+
func getRemoteInstanceConfig() *remote.InstanceConfig {
121+
return &remote.InstanceConfig{
122+
Project: *project,
123+
Architecture: *architecture,
124+
MachineType: *machineType,
125+
ServiceAccount: *serviceAccount,
126+
ImageURL: *imageURL,
127+
CloudtopHost: *cloudtopHost}
128+
}
129+
119130
func NewTestContext(zone string) *remote.TestContext {
120131
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", zone)
121132
klog.Infof("Setting up node %s", nodeID)
122133

123-
i, err := remote.SetupInstance(*project, *architecture, zone, nodeID, *machineType, *serviceAccount, *imageURL, computeService)
134+
i, err := remote.SetupInstance(getRemoteInstanceConfig(), zone, nodeID, computeService)
124135
if err != nil {
125136
klog.Fatalf("Failed to setup instance %v: %v", nodeID, err)
126137
}

test/e2e/tests/single_zone_e2e_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
12891289

12901290
zone := "us-central1-c"
12911291
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", zone)
1292-
i, err := remote.SetupInstance(*project, *architecture, zone, nodeID, *machineType, *serviceAccount, *imageURL, computeService)
1292+
i, err := remote.SetupInstance(getRemoteInstanceConfig(), zone, nodeID, computeService)
12931293

12941294
if err != nil {
12951295
klog.Fatalf("Failed to setup instance %v: %v", nodeID, err)

test/remote/instance.go

+39-13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"net/http"
2424
"os"
25+
"os/exec"
2526
"strings"
2627
"time"
2728

@@ -44,12 +45,25 @@ const (
4445
timestampFormat = "20060102T150405"
4546
)
4647

48+
// InstanceConfig is the common bundle of options used for instance creation.
49+
type InstanceConfig struct {
50+
Project string
51+
Architecture string
52+
MachineType string
53+
ServiceAccount string
54+
ImageURL string
55+
CloudtopHost bool
56+
}
57+
4758
type InstanceInfo struct {
48-
project string
49-
architecture string
50-
zone string
51-
name string
52-
machineType string
59+
project string
60+
architecture string
61+
zone string
62+
name string
63+
machineType string
64+
serviceAccount string
65+
imageURL string
66+
cloudtopHost bool
5367

5468
// External IP is filled in after instance creation
5569
externalIP string
@@ -69,19 +83,22 @@ func (i *InstanceInfo) GetNodeID() string {
6983
return common.CreateNodeID(i.project, i.zone, i.name)
7084
}
7185

72-
func CreateInstanceInfo(project, instanceArchitecture, instanceZone, name, machineType string, cs *compute.Service) (*InstanceInfo, error) {
86+
func CreateInstanceInfo(config *InstanceConfig, zone, name string, cs *compute.Service) (*InstanceInfo, error) {
7387
return &InstanceInfo{
74-
project: project,
75-
architecture: instanceArchitecture,
76-
zone: instanceZone,
88+
project: config.Project,
89+
architecture: config.Architecture,
90+
zone: zone,
7791
name: name,
78-
machineType: machineType,
92+
machineType: config.MachineType,
93+
cloudtopHost: config.CloudtopHost,
94+
serviceAccount: config.ServiceAccount,
95+
imageURL: config.ImageURL,
7996
computeService: cs,
8097
}, nil
8198
}
8299

83100
// Provision a gce instance using image
84-
func (i *InstanceInfo) CreateOrGetInstance(imageURL, serviceAccount string) error {
101+
func (i *InstanceInfo) CreateOrGetInstance() error {
85102
var err error
86103
var instance *compute.Instance
87104
klog.V(4).Infof("Creating instance: %v", i.name)
@@ -112,14 +129,14 @@ func (i *InstanceInfo) CreateOrGetInstance(imageURL, serviceAccount string) erro
112129
Type: "PERSISTENT",
113130
InitializeParams: &compute.AttachedDiskInitializeParams{
114131
DiskName: "my-root-pd-" + myuuid,
115-
SourceImage: imageURL,
132+
SourceImage: i.imageURL,
116133
},
117134
},
118135
},
119136
}
120137

121138
saObj := &compute.ServiceAccount{
122-
Email: serviceAccount,
139+
Email: i.serviceAccount,
123140
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
124141
}
125142
newInst.ServiceAccounts = []*compute.ServiceAccount{saObj}
@@ -187,6 +204,15 @@ func (i *InstanceInfo) CreateOrGetInstance(imageURL, serviceAccount string) erro
187204
return false, nil
188205
}
189206

207+
if i.cloudtopHost {
208+
output, err := exec.Command("gcloud", "compute", "ssh", i.name, "--zone", i.zone, "--project", i.project, "--", "-o", "ProxyCommand=corp-ssh-helper %h %p", "--", "echo").CombinedOutput()
209+
if err != nil {
210+
klog.Errorf("Failed to bootstrap ssh (%v): %s", err, string(output))
211+
return false, nil
212+
}
213+
klog.V(4).Infof("Bootstrapped cloudtop ssh for instance %v", i.name)
214+
}
215+
190216
externalIP := getexternalIP(instance)
191217
if len(externalIP) > 0 {
192218
i.externalIP = externalIP

test/remote/setup-teardown.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ type processes struct {
5454
}
5555

5656
// SetupInstance sets up the specified GCE Instance for E2E testing and returns a handle to the instance object for future use.
57-
func SetupInstance(instanceProject, instanceArchitecture, instanceZone, instanceName, instanceMachineType, instanceServiceAccount, instanceImageURL string, cs *compute.Service) (*InstanceInfo, error) {
57+
func SetupInstance(config *InstanceConfig, instanceZone, instanceName string, cs *compute.Service) (*InstanceInfo, error) {
5858
// Create the instance in the requisite zone
59-
instance, err := CreateInstanceInfo(instanceProject, instanceArchitecture, instanceZone, instanceName, instanceMachineType, cs)
59+
instance, err := CreateInstanceInfo(config, instanceZone, instanceName, cs)
6060
if err != nil {
6161
return nil, err
6262
}
6363

64-
err = instance.CreateOrGetInstance(instanceImageURL, instanceServiceAccount)
64+
err = instance.CreateOrGetInstance()
6565
if err != nil {
6666
return nil, err
6767
}

test/run-e2e-local.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ readonly PKGDIR=sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
1111
# This requires application default credentials to be set up, eg by
1212
# `gcloud auth application-default login`
1313

14-
ginkgo --v "test/e2e/tests" -- --project "${PROJECT}" --service-account "${IAM_NAME}" --v=6 --logtostderr
14+
CLOUDTOP_HOST=
15+
if hostname | grep -q c.googlers.com ; then
16+
CLOUDTOP_HOST=--cloudtop-host
17+
fi
18+
19+
ginkgo --v "test/e2e/tests" -- --project "${PROJECT}" --service-account "${IAM_NAME}" "${CLOUDTOP_HOST}" --v=6 --logtostderr

0 commit comments

Comments
 (0)