Skip to content

Added Boskos project lending for E2E test AND prune non-go files from deps #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@
[prune]
go-tests = true
unused-packages = true
non-go = true

[[constraint]]
branch = "master"
name = "github.com/kubernetes-csi/csi-test"


[[constraint]]
branch = "master"
name = "k8s.io/test-infra"
100 changes: 80 additions & 20 deletions test/remote/run_remote/run_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import (

"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/test-infra/boskos/client"
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider"
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote/remote"

"github.com/golang/glog"
"golang.org/x/oauth2/google"
"google.golang.org/api/cloudresourcemanager/v1"
compute "google.golang.org/api/compute/v0.beta"
)

Expand All @@ -46,6 +48,7 @@ var deleteInstances = flag.Bool("delete-instances", true, "If true, delete any i
var buildOnly = flag.Bool("build-only", false, "If true, build e2e_gce_pd_test.tar.gz and exit.")
var ginkgoFlags = flag.String("ginkgo-flags", "", "Passed to ginkgo to specify additional flags such as --skip=.")
var serviceAccount = flag.String("service-account", "", "GCP Service Account to start the test instance under")
var runInProw = flag.Bool("run-in-prow", false, "If true, use a Boskos loaned project and special CI service accounts and ssh keys")

// envs is the type used to collect all node envs. The key is the env name,
// and the value is the env value
Expand Down Expand Up @@ -82,6 +85,8 @@ var (
computeService *compute.Service
arc Archive
suite remote.TestSuite

boskos = client.NewClient(os.Getenv("JOB_NAME"), "http://boskos")
)

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

if *serviceAccount == "" {
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.")
if *runInProw {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hummm why not just check if project is empty?

Copy link
Contributor Author

@davidz627 davidz627 Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather there be a special flag for running in prow since there's a lot of special set-up involved. If the project is empty and runInProw is not set then the user gets a nice reasonable error to set the project instead of something that mentions Boskos and other things they dont need to know about

// Try to get a Boskos project
glog.V(4).Infof("Running in PROW")
glog.V(4).Infof("Fetching a Boskos loaned project")

p, err := boskos.Acquire("gce-project", "free", "busy")
if err != nil {
glog.Fatal("boskos failed to acquire project: %v", err)
}

if p == nil {
glog.Fatal("boskos does not have a free gce-project at the moment")
}

glog.Infof("Overwriting supplied project %v with project from Boskos: %v", *project, p.GetName())

*project = p.GetName()

go func(c *client.Client, proj string) {
for range time.Tick(time.Minute * 5) {
if err := c.UpdateOne(p.Name, "busy", nil); err != nil {
glog.Warningf("[Boskos] Update %s failed with %v", p, err)
}
}
}(boskos, p.Name)

// If we're on CI overwrite the service account
glog.V(4).Infof("Fetching the default compute service account")

c, err := google.DefaultClient(context.TODO(), cloudresourcemanager.CloudPlatformScope)
if err != nil {
glog.Fatalf("Failed to get Google Default Client: %v", err)
}

cloudresourcemanagerService, err := cloudresourcemanager.New(c)
if err != nil {
glog.Fatalf("Failed to create new cloudresourcemanager: %v", err)
}

resp, err := cloudresourcemanagerService.Projects.Get(*project).Do()
if err != nil {
glog.Fatal("Failed to get project %v from Cloud Resource Manager: %v", *project, err)
}

// Default Compute Engine service account
// [PROJECT_NUMBER][email protected]
sa := fmt.Sprintf("%[email protected]", resp.ProjectNumber)
glog.Infof("Overwriting supplied service account %v with PROW service account %v", *serviceAccount, sa)

*serviceAccount = sa
}

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

if *serviceAccount == "" {
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.")
}

rand.Seed(time.Now().UTC().UnixNano())
if *buildOnly {
// Build the archive and exit
Expand Down Expand Up @@ -163,6 +220,12 @@ func main() {
fmt.Printf("%s<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<%s\n", blue, noColour)
fmt.Println() // Print an empty line

if boskos.HasResource() {
if berr := boskos.ReleaseAll("dirty"); berr != nil {
glog.Fatalf("[Boskos] Fail To Release: %v, kubetest err: %v", berr, err)
}
}

// Set the exit code if there were failures
if !results.exitOk {
fmt.Printf("Failure: %d errors encountered.\n", errCount)
Expand Down Expand Up @@ -266,11 +329,14 @@ func test(tests []string) *TestResult {

// Provision a gce instance using image
func createInstance(serviceAccount string) (string, error) {
var err error

name := "gce-pd-csi-e2e"
myuuid := string(uuid.NewUUID())
glog.V(2).Infof("Creating instance: %v", name)
glog.V(4).Infof("Creating instance: %v", name)

imageURL := "https://www.googleapis.com/compute/v1/projects/ml-images/global/images/debian-9-tf-1-9-v20180626"
// TODO: Pick a better boot disk image
imageURL := "projects/ml-images/global/images/family/tf-1-9"
i := &compute.Instance{
Name: name,
MachineType: machineType(""),
Expand All @@ -296,18 +362,15 @@ func createInstance(serviceAccount string) (string, error) {
},
}

if serviceAccount != "" {
saObj := &compute.ServiceAccount{
Email: serviceAccount,
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
}
i.ServiceAccounts = []*compute.ServiceAccount{saObj}
saObj := &compute.ServiceAccount{
Email: serviceAccount,
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
}
i.ServiceAccounts = []*compute.ServiceAccount{saObj}

var err error
if gotInstance, err := computeService.Instances.Get(*project, *zone, i.Name).Do(); err != nil {
if _, err := computeService.Instances.Get(*project, *zone, i.Name).Do(); err != nil {
op, err := computeService.Instances.Insert(*project, *zone, i).Do()
glog.V(4).Infof("Inserted instance in project %v, zone %v: %#v", *project, *zone, i)
glog.V(4).Infof("Inserted instance %v in project %v, zone %v", i.Name, *project, *zone)
if err != nil {
ret := fmt.Sprintf("could not create instance %s: API error: %v", name, err)
if op != nil {
Expand All @@ -318,19 +381,16 @@ func createInstance(serviceAccount string) (string, error) {
return "", fmt.Errorf("could not create instance %s: %+v", name, op.Error)
}
} else {
glog.V(4).Infof("Compute service GOT instance %v, skipping instance creation: %#v", i.Name, gotInstance)
glog.V(4).Infof("Compute service GOT instance %v, skipping instance creation", i.Name)
}

pubkey, ok := os.LookupEnv("JENKINS_GCE_SSH_PUBLIC_KEY_FILE")
if ok {
glog.Infof("Running on Jenkins and JENKINS_GCE_SSH_PUBLIC_KEY_FILE set")
if pubkey, ok := os.LookupEnv("JENKINS_GCE_SSH_PUBLIC_KEY_FILE"); ok {
glog.V(4).Infof("JENKINS_GCE_SSH_PUBLIC_KEY_FILE set to %v, adding public key to Instance", pubkey)
// If we're on CI add public SSH keys to the instance
err = addPubKeyToInstance(*project, *zone, i.Name, pubkey)
if err != nil {
return "", fmt.Errorf("could not add Jenkins public key %v to instance %v: %v", pubkey, i.Name, err)
}
} else {
glog.V(4).Infof("JENKINS_GCE_SSH_PUBLIC_KEY_FILE not set, not adding SSH public key to instance")
}

then := time.Now()
Expand Down Expand Up @@ -462,7 +522,7 @@ func getComputeClient() (*compute.Service, error) {
}

func deleteInstance(host string) {
glog.Infof("Deleting instance %q", host)
glog.V(4).Infof("Deleting instance %q", host)
_, err := computeService.Instances.Delete(*project, *zone, host).Do()
if err != nil {
if gce.IsGCEError(err, "notFound") {
Expand Down
8 changes: 8 additions & 0 deletions test/run-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e
set -x

readonly PKGDIR=sigs.k8s.io/gcp-compute-persistent-disk-csi-driver

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
50 changes: 50 additions & 0 deletions vendor/github.com/ghodss/yaml/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading