Skip to content

Commit cd33337

Browse files
committed
Use default service account when creating test instance.
Signed-off-by: Lantao Liu <[email protected]>
1 parent 1c10061 commit cd33337

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

test/e2e_node/runner/remote/run_remote.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,13 @@ func testImage(imageConfig *internalGCEImage, junitFilePrefix string) *TestResul
547547

548548
// Provision a gce instance using image
549549
func createInstance(imageConfig *internalGCEImage) (string, error) {
550-
klog.V(1).Infof("Creating instance %+v", *imageConfig)
550+
p, err := computeService.Projects.Get(*project).Do()
551+
if err != nil {
552+
return "", fmt.Errorf("failed to get project info %q", *project)
553+
}
554+
// Use default service account
555+
serviceAccount := p.DefaultServiceAccount
556+
klog.V(1).Infof("Creating instance %+v with service account %q", *imageConfig, serviceAccount)
551557
name := imageToInstanceName(imageConfig)
552558
i := &compute.Instance{
553559
Name: name,
@@ -572,6 +578,14 @@ func createInstance(imageConfig *internalGCEImage) (string, error) {
572578
},
573579
},
574580
},
581+
ServiceAccounts: []*compute.ServiceAccount{
582+
{
583+
Email: serviceAccount,
584+
Scopes: []string{
585+
"https://www.googleapis.com/auth/cloud-platform",
586+
},
587+
},
588+
},
575589
}
576590

577591
for _, accelerator := range imageConfig.resources.Accelerators {
@@ -591,7 +605,6 @@ func createInstance(imageConfig *internalGCEImage) (string, error) {
591605
i.GuestAccelerators = append(i.GuestAccelerators, ac)
592606
}
593607

594-
var err error
595608
i.Metadata = imageConfig.metadata
596609
if _, err := computeService.Instances.Get(*project, *zone, i.Name).Do(); err != nil {
597610
op, err := computeService.Instances.Insert(*project, *zone, i).Do()

0 commit comments

Comments
 (0)