@@ -30,11 +30,13 @@ import (
30
30
31
31
"k8s.io/apimachinery/pkg/util/uuid"
32
32
"k8s.io/apimachinery/pkg/util/wait"
33
+ "k8s.io/test-infra/boskos/client"
33
34
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider"
34
35
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote/remote"
35
36
36
37
"github.com/golang/glog"
37
38
"golang.org/x/oauth2/google"
39
+ "google.golang.org/api/cloudresourcemanager/v1"
38
40
compute "google.golang.org/api/compute/v0.beta"
39
41
)
40
42
@@ -46,6 +48,7 @@ var deleteInstances = flag.Bool("delete-instances", true, "If true, delete any i
46
48
var buildOnly = flag .Bool ("build-only" , false , "If true, build e2e_gce_pd_test.tar.gz and exit." )
47
49
var ginkgoFlags = flag .String ("ginkgo-flags" , "" , "Passed to ginkgo to specify additional flags such as --skip=." )
48
50
var serviceAccount = flag .String ("service-account" , "" , "GCP Service Account to start the test instance under" )
51
+ var runInProw = flag .Bool ("run-in-prow" , false , "If true, use a Boskos loaned project and special CI service accounts and ssh keys" )
49
52
50
53
// envs is the type used to collect all node envs. The key is the env name,
51
54
// and the value is the env value
82
85
computeService * compute.Service
83
86
arc Archive
84
87
suite remote.TestSuite
88
+
89
+ boskos = client .NewClient (os .Getenv ("JOB_NAME" ), "http://boskos" )
85
90
)
86
91
87
92
// Archive contains information about the test tar
@@ -103,8 +108,56 @@ func main() {
103
108
flag .Parse ()
104
109
suite = remote .InitE2ERemote ()
105
110
106
- if * serviceAccount == "" {
107
- 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
+ if * runInProw {
112
+ // Try to get a Boskos project
113
+ glog .V (4 ).Infof ("Running in PROW" )
114
+ glog .V (4 ).Infof ("Fetching a Boskos loaned project" )
115
+
116
+ p , err := boskos .Acquire ("gce-project" , "free" , "busy" )
117
+ if err != nil {
118
+ glog .Fatal ("boskos failed to acquire project: %v" , err )
119
+ }
120
+
121
+ if p == nil {
122
+ glog .Fatal ("boskos does not have a free gce-project at the moment" )
123
+ }
124
+
125
+ glog .Infof ("Overwriting supplied project %v with project from Boskos: %v" , * project , p .GetName ())
126
+
127
+ * project = p .GetName ()
128
+
129
+ go func (c * client.Client , proj string ) {
130
+ for range time .Tick (time .Minute * 5 ) {
131
+ if err := c .UpdateOne (p .Name , "busy" , nil ); err != nil {
132
+ glog .Warningf ("[Boskos] Update %s failed with %v" , p , err )
133
+ }
134
+ }
135
+ }(boskos , p .Name )
136
+
137
+ // If we're on CI overwrite the service account
138
+ glog .V (4 ).Infof ("Fetching the default compute service account" )
139
+
140
+ c , err := google .DefaultClient (context .TODO (), cloudresourcemanager .CloudPlatformScope )
141
+ if err != nil {
142
+ glog .Fatalf ("Failed to get Google Default Client: %v" , err )
143
+ }
144
+
145
+ cloudresourcemanagerService , err := cloudresourcemanager .New (c )
146
+ if err != nil {
147
+ glog .Fatalf ("Failed to create new cloudresourcemanager: %v" , err )
148
+ }
149
+
150
+ resp , err := cloudresourcemanagerService .Projects .Get (* project ).Do ()
151
+ if err != nil {
152
+ glog .Fatal ("Failed to get project %v from Cloud Resource Manager: %v" , * project , err )
153
+ }
154
+
155
+ // Default Compute Engine service account
156
+ // [PROJECT_NUMBER][email protected]
157
+ sa := fmt .
Sprintf (
"%[email protected] " ,
resp .
ProjectNumber )
158
+ glog .Infof ("Overwriting supplied service account %v with PROW service account %v" , * serviceAccount , sa )
159
+
160
+ * serviceAccount = sa
108
161
}
109
162
110
163
if * project == "" {
@@ -115,6 +168,10 @@ func main() {
115
168
glog .Fatal ("Zone must be specified" )
116
169
}
117
170
171
+ if * serviceAccount == "" {
172
+ 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." )
173
+ }
174
+
118
175
rand .Seed (time .Now ().UTC ().UnixNano ())
119
176
if * buildOnly {
120
177
// Build the archive and exit
@@ -163,6 +220,12 @@ func main() {
163
220
fmt .Printf ("%s<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<%s\n " , blue , noColour )
164
221
fmt .Println () // Print an empty line
165
222
223
+ if boskos .HasResource () {
224
+ if berr := boskos .ReleaseAll ("dirty" ); berr != nil {
225
+ glog .Fatalf ("[Boskos] Fail To Release: %v, kubetest err: %v" , berr , err )
226
+ }
227
+ }
228
+
166
229
// Set the exit code if there were failures
167
230
if ! results .exitOk {
168
231
fmt .Printf ("Failure: %d errors encountered.\n " , errCount )
@@ -266,11 +329,14 @@ func test(tests []string) *TestResult {
266
329
267
330
// Provision a gce instance using image
268
331
func createInstance (serviceAccount string ) (string , error ) {
332
+ var err error
333
+
269
334
name := "gce-pd-csi-e2e"
270
335
myuuid := string (uuid .NewUUID ())
271
- glog .V (2 ).Infof ("Creating instance: %v" , name )
336
+ glog .V (4 ).Infof ("Creating instance: %v" , name )
272
337
273
- imageURL := "https://www.googleapis.com/compute/v1/projects/ml-images/global/images/debian-9-tf-1-9-v20180626"
338
+ // TODO: Pick a better boot disk image
339
+ imageURL := "projects/ml-images/global/images/family/tf-1-9"
274
340
i := & compute.Instance {
275
341
Name : name ,
276
342
MachineType : machineType ("" ),
@@ -296,18 +362,15 @@ func createInstance(serviceAccount string) (string, error) {
296
362
},
297
363
}
298
364
299
- if serviceAccount != "" {
300
- saObj := & compute.ServiceAccount {
301
- Email : serviceAccount ,
302
- Scopes : []string {"https://www.googleapis.com/auth/cloud-platform" },
303
- }
304
- i .ServiceAccounts = []* compute.ServiceAccount {saObj }
365
+ saObj := & compute.ServiceAccount {
366
+ Email : serviceAccount ,
367
+ Scopes : []string {"https://www.googleapis.com/auth/cloud-platform" },
305
368
}
369
+ i .ServiceAccounts = []* compute.ServiceAccount {saObj }
306
370
307
- var err error
308
- if gotInstance , err := computeService .Instances .Get (* project , * zone , i .Name ).Do (); err != nil {
371
+ if _ , err := computeService .Instances .Get (* project , * zone , i .Name ).Do (); err != nil {
309
372
op , err := computeService .Instances .Insert (* project , * zone , i ).Do ()
310
- glog .V (4 ).Infof ("Inserted instance in project %v, zone %v: %#v " , * project , * zone , i )
373
+ glog .V (4 ).Infof ("Inserted instance %v in project %v, zone %v" , i . Name , * project , * zone )
311
374
if err != nil {
312
375
ret := fmt .Sprintf ("could not create instance %s: API error: %v" , name , err )
313
376
if op != nil {
@@ -318,19 +381,16 @@ func createInstance(serviceAccount string) (string, error) {
318
381
return "" , fmt .Errorf ("could not create instance %s: %+v" , name , op .Error )
319
382
}
320
383
} else {
321
- glog .V (4 ).Infof ("Compute service GOT instance %v, skipping instance creation: %#v " , i .Name , gotInstance )
384
+ glog .V (4 ).Infof ("Compute service GOT instance %v, skipping instance creation" , i .Name )
322
385
}
323
386
324
- pubkey , ok := os .LookupEnv ("JENKINS_GCE_SSH_PUBLIC_KEY_FILE" )
325
- if ok {
326
- glog .Infof ("Running on Jenkins and JENKINS_GCE_SSH_PUBLIC_KEY_FILE set" )
387
+ if pubkey , ok := os .LookupEnv ("JENKINS_GCE_SSH_PUBLIC_KEY_FILE" ); ok {
388
+ glog .V (4 ).Infof ("JENKINS_GCE_SSH_PUBLIC_KEY_FILE set to %v, adding public key to Instance" , pubkey )
327
389
// If we're on CI add public SSH keys to the instance
328
390
err = addPubKeyToInstance (* project , * zone , i .Name , pubkey )
329
391
if err != nil {
330
392
return "" , fmt .Errorf ("could not add Jenkins public key %v to instance %v: %v" , pubkey , i .Name , err )
331
393
}
332
- } else {
333
- glog .V (4 ).Infof ("JENKINS_GCE_SSH_PUBLIC_KEY_FILE not set, not adding SSH public key to instance" )
334
394
}
335
395
336
396
then := time .Now ()
@@ -462,7 +522,7 @@ func getComputeClient() (*compute.Service, error) {
462
522
}
463
523
464
524
func deleteInstance (host string ) {
465
- glog .Infof ("Deleting instance %q" , host )
525
+ glog .V ( 4 ). Infof ("Deleting instance %q" , host )
466
526
_ , err := computeService .Instances .Delete (* project , * zone , host ).Do ()
467
527
if err != nil {
468
528
if gce .IsGCEError (err , "notFound" ) {
0 commit comments