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 <odin@ugedal.com>
This commit is contained in:
Odin Ugedal 2019-08-16 15:32:10 +02:00
parent 4e7fd98763
commit e20c2b1f32
No known key found for this signature in database
GPG Key ID: AFF9C8242CF7A7AF
3 changed files with 11 additions and 6 deletions

View File

@ -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

View File

@ -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 $?

View File

@ -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()