Skip to content

Commit ef6b6e3

Browse files
authored
Merge pull request #23 from davidz627/feature/BoskosLoan
Added Boskos project lending for E2E test AND prune non-go files from deps
2 parents fa0ddb1 + 9d90f23 commit ef6b6e3

File tree

154 files changed

+20827
-70807
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+20827
-70807
lines changed

Gopkg.lock

+46-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@
7373
[prune]
7474
go-tests = true
7575
unused-packages = true
76+
non-go = true
7677

7778
[[constraint]]
7879
branch = "master"
7980
name = "github.com/kubernetes-csi/csi-test"
80-
81+
82+
[[constraint]]
83+
branch = "master"
84+
name = "k8s.io/test-infra"

test/remote/run_remote/run_remote.go

+80-20
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ import (
3030

3131
"k8s.io/apimachinery/pkg/util/uuid"
3232
"k8s.io/apimachinery/pkg/util/wait"
33+
"k8s.io/test-infra/boskos/client"
3334
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider"
3435
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote/remote"
3536

3637
"github.com/golang/glog"
3738
"golang.org/x/oauth2/google"
39+
"google.golang.org/api/cloudresourcemanager/v1"
3840
compute "google.golang.org/api/compute/v0.beta"
3941
)
4042

@@ -46,6 +48,7 @@ var deleteInstances = flag.Bool("delete-instances", true, "If true, delete any i
4648
var buildOnly = flag.Bool("build-only", false, "If true, build e2e_gce_pd_test.tar.gz and exit.")
4749
var ginkgoFlags = flag.String("ginkgo-flags", "", "Passed to ginkgo to specify additional flags such as --skip=.")
4850
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")
4952

5053
// envs is the type used to collect all node envs. The key is the env name,
5154
// and the value is the env value
@@ -82,6 +85,8 @@ var (
8285
computeService *compute.Service
8386
arc Archive
8487
suite remote.TestSuite
88+
89+
boskos = client.NewClient(os.Getenv("JOB_NAME"), "http://boskos")
8590
)
8691

8792
// Archive contains information about the test tar
@@ -103,8 +108,56 @@ func main() {
103108
flag.Parse()
104109
suite = remote.InitE2ERemote()
105110

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
108161
}
109162

110163
if *project == "" {
@@ -115,6 +168,10 @@ func main() {
115168
glog.Fatal("Zone must be specified")
116169
}
117170

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+
118175
rand.Seed(time.Now().UTC().UnixNano())
119176
if *buildOnly {
120177
// Build the archive and exit
@@ -163,6 +220,12 @@ func main() {
163220
fmt.Printf("%s<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<%s\n", blue, noColour)
164221
fmt.Println() // Print an empty line
165222

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+
166229
// Set the exit code if there were failures
167230
if !results.exitOk {
168231
fmt.Printf("Failure: %d errors encountered.\n", errCount)
@@ -266,11 +329,14 @@ func test(tests []string) *TestResult {
266329

267330
// Provision a gce instance using image
268331
func createInstance(serviceAccount string) (string, error) {
332+
var err error
333+
269334
name := "gce-pd-csi-e2e"
270335
myuuid := string(uuid.NewUUID())
271-
glog.V(2).Infof("Creating instance: %v", name)
336+
glog.V(4).Infof("Creating instance: %v", name)
272337

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"
274340
i := &compute.Instance{
275341
Name: name,
276342
MachineType: machineType(""),
@@ -296,18 +362,15 @@ func createInstance(serviceAccount string) (string, error) {
296362
},
297363
}
298364

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"},
305368
}
369+
i.ServiceAccounts = []*compute.ServiceAccount{saObj}
306370

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 {
309372
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)
311374
if err != nil {
312375
ret := fmt.Sprintf("could not create instance %s: API error: %v", name, err)
313376
if op != nil {
@@ -318,19 +381,16 @@ func createInstance(serviceAccount string) (string, error) {
318381
return "", fmt.Errorf("could not create instance %s: %+v", name, op.Error)
319382
}
320383
} 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)
322385
}
323386

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)
327389
// If we're on CI add public SSH keys to the instance
328390
err = addPubKeyToInstance(*project, *zone, i.Name, pubkey)
329391
if err != nil {
330392
return "", fmt.Errorf("could not add Jenkins public key %v to instance %v: %v", pubkey, i.Name, err)
331393
}
332-
} else {
333-
glog.V(4).Infof("JENKINS_GCE_SSH_PUBLIC_KEY_FILE not set, not adding SSH public key to instance")
334394
}
335395

336396
then := time.Now()
@@ -462,7 +522,7 @@ func getComputeClient() (*compute.Service, error) {
462522
}
463523

464524
func deleteInstance(host string) {
465-
glog.Infof("Deleting instance %q", host)
525+
glog.V(4).Infof("Deleting instance %q", host)
466526
_, err := computeService.Instances.Delete(*project, *zone, host).Do()
467527
if err != nil {
468528
if gce.IsGCEError(err, "notFound") {

test/run-e2e.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
readonly PKGDIR=sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
7+
8+
go run "$GOPATH/src/${PKGDIR}/test/remote/run_remote/run_remote.go" --logtostderr --v 4 --zone "${ZONE}" --ssh-env gce --delete-instances=true --results-dir=my_test --run-in-prow=true

vendor/github.com/ghodss/yaml/LICENSE

+50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)