-
Notifications
You must be signed in to change notification settings - Fork 159
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
k8s-ci-robot
merged 4 commits into
kubernetes-sigs:master
from
davidz627:feature/BoskosLoan
Jun 28, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
91f2834
Added logic for getting project and service account when running in PROW
davidz627 346762e
Updated deps to include test-infra requirement for Boskos
davidz627 d3a4822
Change DEBUG logs to verbosity 4
davidz627 9d90f23
Pruned non-go files
davidz627 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|
||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 { | ||
// 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 == "" { | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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(""), | ||
|
@@ -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 { | ||
|
@@ -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() | ||
|
@@ -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") { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 mentionsBoskos
and other things they dont need to know about