@@ -24,6 +24,7 @@ import (
24
24
"math/rand"
25
25
"net/http"
26
26
"os"
27
+ "os/exec"
27
28
"strings"
28
29
"sync"
29
30
"time"
@@ -110,7 +111,9 @@ func main() {
110
111
glog .Fatal ("You must specify a service account to create an instance under that has at least OWNERS permissions on disks and READER on instances." )
111
112
}
112
113
113
- if * project == "" {
114
+ // TODO: OVERWRITE PROJECT FOR TEST PURPOSES ONLY
115
+ if true /* *project == "" */ {
116
+ // TODO: Check if we're on CI and just overwrite project anyway if we are.
114
117
// Try get a Boskos Project
115
118
glog .Infof ("--project is missing, trying to fetch a project from boskos.\n " +
116
119
"(for local runs please set --project to your dev project)" )
@@ -126,6 +129,8 @@ func main() {
126
129
127
130
* project = p .GetName ()
128
131
132
+ glog .Infof ("Fetched project from Boskos: %v" , * project )
133
+
129
134
go func (c * client.Client , proj string ) {
130
135
for range time .Tick (time .Minute * 5 ) {
131
136
if err := c .UpdateOne (p .Name , "busy" , nil ); err != nil {
@@ -300,7 +305,7 @@ func createInstance(serviceAccount string) (string, error) {
300
305
myuuid := string (uuid .NewUUID ())
301
306
glog .V (2 ).Infof ("Creating instance: %v" , name )
302
307
303
- imageURL := "https://www.googleapis.com/compute/v1/ projects/ml-images/global/images/debian-9- tf-1-9-v20180626 "
308
+ imageURL := "projects/ml-images/global/images/family/ tf-1-9"
304
309
i := & compute.Instance {
305
310
Name : name ,
306
311
MachineType : machineType ("" ),
@@ -326,18 +331,33 @@ func createInstance(serviceAccount string) (string, error) {
326
331
},
327
332
}
328
333
329
- if serviceAccount != "" {
330
- saObj := & compute.ServiceAccount {
331
- Email : serviceAccount ,
332
- Scopes : []string {"https://www.googleapis.com/auth/cloud-platform" },
334
+ // TODO: OVERWRITE SERVICEACCOUNT FOR TEST PURPOSES ONLY
335
+ if true /* serviceAccount == "" */ {
336
+ // TODO: Check if on CI
337
+ // Assume we are on CI and grab service account from gcloud
338
+ glog .Infof ("Running on CI, getting gcloud account" )
339
+ cmd := exec .Command ("gcloud" , "config" , "get-value" , "account" )
340
+ out , err := cmd .Output ()
341
+
342
+ if err != nil {
343
+ return "" , fmt .Errorf ("Failed to get current gclou account: %v" , err )
333
344
}
334
- i .ServiceAccounts = []* compute.ServiceAccount {saObj }
345
+
346
+ serviceAccount = string (out )
347
+ glog .Infof ("Got service account: %v" , serviceAccount )
348
+
335
349
}
336
350
351
+ saObj := & compute.ServiceAccount {
352
+ Email : serviceAccount ,
353
+ Scopes : []string {"https://www.googleapis.com/auth/compute" },
354
+ }
355
+ //i.ServiceAccounts = []*compute.ServiceAccount{saObj}
356
+
337
357
var err error
338
358
if gotInstance , err := computeService .Instances .Get (* project , * zone , i .Name ).Do (); err != nil {
339
359
op , err := computeService .Instances .Insert (* project , * zone , i ).Do ()
340
- glog .V ( 4 ). Infof ("Inserted instance in project %v, zone %v: %#v" , * project , * zone , i )
360
+ glog .Infof ("Inserted instance in project %v, zone %v: %#v" , * project , * zone , i )
341
361
if err != nil {
342
362
ret := fmt .Sprintf ("could not create instance %s: API error: %v" , name , err )
343
363
if op != nil {
@@ -347,21 +367,37 @@ func createInstance(serviceAccount string) (string, error) {
347
367
} else if op .Error != nil {
348
368
return "" , fmt .Errorf ("could not create instance %s: %+v" , name , op .Error )
349
369
}
370
+
371
+ // WAIT FOR OP
372
+ wait .Poll (3 * time .Second , 5 * time .Minute , func () (bool , error ) {
373
+ pollOp , err := computeService .ZoneOperations .Get (* project , * zone , op .Name ).Do ()
374
+ if err != nil {
375
+ glog .Errorf ("WaitForOp(op: %#v, zone: %#v) failed to poll the operation: %v" , op , zone , err )
376
+ return false , err
377
+ }
378
+ glog .Infof ("Insert Op data: %#v" , pollOp )
379
+ glog .Infof ("Op Error: %v" , pollOp .Error )
380
+ done := opIsDone (pollOp )
381
+ return done , err
382
+ })
383
+
350
384
} else {
351
- glog .V ( 4 ). Infof ("Compute service GOT instance %v, skipping instance creation: %#v" , i .Name , gotInstance )
385
+ glog .Infof ("Compute service GOT instance %v, skipping instance creation: %#v" , i .Name , gotInstance )
352
386
}
353
387
354
- pubkey , ok := os .LookupEnv ("JENKINS_GCE_SSH_PUBLIC_KEY_FILE" )
355
- if ok {
356
- glog .Infof ("Running on Jenkins and JENKINS_GCE_SSH_PUBLIC_KEY_FILE set" )
357
- // If we're on CI add public SSH keys to the instance
358
- err = addPubKeyToInstance (* project , * zone , i .Name , pubkey )
359
- if err != nil {
360
- return "" , fmt .Errorf ("could not add Jenkins public key %v to instance %v: %v" , pubkey , i .Name , err )
388
+ /*
389
+ pubkey, ok := os.LookupEnv("JENKINS_GCE_SSH_PUBLIC_KEY_FILE")
390
+ if ok {
391
+ glog.Infof("Running on Jenkins and JENKINS_GCE_SSH_PUBLIC_KEY_FILE set")
392
+ // If we're on CI add public SSH keys to the instance
393
+ err = addPubKeyToInstance(*project, *zone, i.Name, pubkey)
394
+ if err != nil {
395
+ return "", fmt.Errorf("could not add Jenkins public key %v to instance %v: %v", pubkey, i.Name, err)
396
+ }
397
+ } else {
398
+ glog.Infof("JENKINS_GCE_SSH_PUBLIC_KEY_FILE not set, not adding SSH public key to instance")
361
399
}
362
- } else {
363
- glog .V (4 ).Infof ("JENKINS_GCE_SSH_PUBLIC_KEY_FILE not set, not adding SSH public key to instance" )
364
- }
400
+ */
365
401
366
402
then := time .Now ()
367
403
err = wait .Poll (10 * time .Second , 5 * time .Minute , func () (bool , error ) {
@@ -521,3 +557,7 @@ func testsToGinkgoFocus(tests []string) string {
521
557
}
522
558
return focus + "\" "
523
559
}
560
+
561
+ func opIsDone (op * compute.Operation ) bool {
562
+ return op != nil && op .Status == "DONE"
563
+ }
0 commit comments