From e20c2b1f3238f4a828a292377bfc63016ad5a30d Mon Sep 17 00:00:00 2001 From: Odin Ugedal Date: Fri, 16 Aug 2019 15:32:10 +0200 Subject: [PATCH] Add support for preemptible instances in node-e2e Preemptible instances are cheaper, and the small chanse of a vm being killed doesn't matter when running during development. This is a tradeoff the user should be able to decide on. More info here: https://cloud.google.com/compute/docs/instances/preemptible The default setting is false, so unless setting PREEMPTIBLE_INSTANCES=true, everything will behave as before. Signed-off-by: Odin Ugedal --- build/root/Makefile | 2 ++ hack/make-rules/test-e2e-node.sh | 3 ++- test/e2e_node/runner/remote/run_remote.go | 12 +++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/build/root/Makefile b/build/root/Makefile index 969afb15523..eff357b9ded 100644 --- a/build/root/Makefile +++ b/build/root/Makefile @@ -238,6 +238,8 @@ define TEST_E2E_NODE_HELP_INFO # run tests against. Defaults to "". # DELETE_INSTANCES: For REMOTE=true only. Delete any instances created as # part of this test run. Defaults to false. +# PREEMPTIBLE_INSTANCES: For REMOTE=true only. Mark created gce instances +# as preemptible. Defaults to false. # ARTIFACTS: For REMOTE=true only. Local directory to scp test artifacts into # from the remote hosts. Defaults to "/tmp/_artifacts". # REPORT: For REMOTE=false only. Local directory to write juntil xml results diff --git a/hack/make-rules/test-e2e-node.sh b/hack/make-rules/test-e2e-node.sh index ec8f663a994..0e262ccbcca 100755 --- a/hack/make-rules/test-e2e-node.sh +++ b/hack/make-rules/test-e2e-node.sh @@ -94,6 +94,7 @@ if [ "${remote}" = true ] ; then instance_prefix=${INSTANCE_PREFIX:-"test"} cleanup=${CLEANUP:-"true"} delete_instances=${DELETE_INSTANCES:-"false"} + preemptible_instances=${PREEMPTIBLE_INSTANCES:-"false"} test_suite=${TEST_SUITE:-"default"} # Get the compute zone @@ -149,7 +150,7 @@ if [ "${remote}" = true ] ; then --image-project="${image_project}" --instance-name-prefix="${instance_prefix}" \ --delete-instances="${delete_instances}" --test_args="${test_args}" --instance-metadata="${metadata}" \ --image-config-file="${image_config_file}" --system-spec-name="${system_spec_name}" \ - --extra-envs="${extra_envs}" --test-suite="${test_suite}" \ + --preemptible-instances="${preemptible_instances}" --extra-envs="${extra_envs}" --test-suite="${test_suite}" \ 2>&1 | tee -i "${artifacts}/build-log.txt" exit $? diff --git a/test/e2e_node/runner/remote/run_remote.go b/test/e2e_node/runner/remote/run_remote.go index a44f1fc1475..5f0ed0eb722 100644 --- a/test/e2e_node/runner/remote/run_remote.go +++ b/test/e2e_node/runner/remote/run_remote.go @@ -56,6 +56,7 @@ var imageConfigFile = flag.String("image-config-file", "", "yaml file describing var imageConfigDir = flag.String("image-config-dir", "", "(optional)path to image config files") var imageProject = flag.String("image-project", "", "gce project the hosts live in") var images = flag.String("images", "", "images to test") +var preemptibleInstances = flag.Bool("preemptible-instances", false, "If true, gce instances will be configured to be preemptible") var hosts = flag.String("hosts", "", "hosts to test") var cleanup = flag.Bool("cleanup", true, "If true remove files from remote hosts and delete temporary instances") var deleteInstances = flag.Bool("delete-instances", true, "If true, delete any instances created") @@ -599,14 +600,15 @@ func createInstance(imageConfig *internalGCEImage) (string, error) { }, } + scheduling := compute.Scheduling{ + Preemptible: *preemptibleInstances, + } for _, accelerator := range imageConfig.resources.Accelerators { if i.GuestAccelerators == nil { autoRestart := true i.GuestAccelerators = []*compute.AcceleratorConfig{} - i.Scheduling = &compute.Scheduling{ - OnHostMaintenance: "TERMINATE", - AutomaticRestart: &autoRestart, - } + scheduling.OnHostMaintenance = "TERMINATE" + scheduling.AutomaticRestart = &autoRestart } aType := fmt.Sprintf(acceleratorTypeResourceFormat, *project, *zone, accelerator.Type) ac := &compute.AcceleratorConfig{ @@ -615,7 +617,7 @@ func createInstance(imageConfig *internalGCEImage) (string, error) { } i.GuestAccelerators = append(i.GuestAccelerators, ac) } - + i.Scheduling = &scheduling i.Metadata = imageConfig.metadata if _, err := computeService.Instances.Get(*project, *zone, i.Name).Do(); err != nil { op, err := computeService.Instances.Insert(*project, *zone, i).Do()