Merge pull request #81512 from odinuge/preemptible-node-tests

Add support for preemptible instances in node-e2e
This commit is contained in:
Kubernetes Prow Robot 2019-09-20 22:55:24 -07:00 committed by GitHub
commit 3a55875465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 "". # run tests against. Defaults to "".
# DELETE_INSTANCES: For REMOTE=true only. Delete any instances created as # DELETE_INSTANCES: For REMOTE=true only. Delete any instances created as
# part of this test run. Defaults to false. # 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 # ARTIFACTS: For REMOTE=true only. Local directory to scp test artifacts into
# from the remote hosts. Defaults to "/tmp/_artifacts". # from the remote hosts. Defaults to "/tmp/_artifacts".
# REPORT: For REMOTE=false only. Local directory to write juntil xml results # 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"} instance_prefix=${INSTANCE_PREFIX:-"test"}
cleanup=${CLEANUP:-"true"} cleanup=${CLEANUP:-"true"}
delete_instances=${DELETE_INSTANCES:-"false"} delete_instances=${DELETE_INSTANCES:-"false"}
preemptible_instances=${PREEMPTIBLE_INSTANCES:-"false"}
test_suite=${TEST_SUITE:-"default"} test_suite=${TEST_SUITE:-"default"}
# Get the compute zone # Get the compute zone
@ -149,7 +150,7 @@ if [ "${remote}" = true ] ; then
--image-project="${image_project}" --instance-name-prefix="${instance_prefix}" \ --image-project="${image_project}" --instance-name-prefix="${instance_prefix}" \
--delete-instances="${delete_instances}" --test_args="${test_args}" --instance-metadata="${metadata}" \ --delete-instances="${delete_instances}" --test_args="${test_args}" --instance-metadata="${metadata}" \
--image-config-file="${image_config_file}" --system-spec-name="${system_spec_name}" \ --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" 2>&1 | tee -i "${artifacts}/build-log.txt"
exit $? 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 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 imageProject = flag.String("image-project", "", "gce project the hosts live in")
var images = flag.String("images", "", "images to test") 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 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 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") 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 { for _, accelerator := range imageConfig.resources.Accelerators {
if i.GuestAccelerators == nil { if i.GuestAccelerators == nil {
autoRestart := true autoRestart := true
i.GuestAccelerators = []*compute.AcceleratorConfig{} i.GuestAccelerators = []*compute.AcceleratorConfig{}
i.Scheduling = &compute.Scheduling{ scheduling.OnHostMaintenance = "TERMINATE"
OnHostMaintenance: "TERMINATE", scheduling.AutomaticRestart = &autoRestart
AutomaticRestart: &autoRestart,
}
} }
aType := fmt.Sprintf(acceleratorTypeResourceFormat, *project, *zone, accelerator.Type) aType := fmt.Sprintf(acceleratorTypeResourceFormat, *project, *zone, accelerator.Type)
ac := &compute.AcceleratorConfig{ ac := &compute.AcceleratorConfig{
@ -615,7 +617,7 @@ func createInstance(imageConfig *internalGCEImage) (string, error) {
} }
i.GuestAccelerators = append(i.GuestAccelerators, ac) i.GuestAccelerators = append(i.GuestAccelerators, ac)
} }
i.Scheduling = &scheduling
i.Metadata = imageConfig.metadata i.Metadata = imageConfig.metadata
if _, 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() op, err := computeService.Instances.Insert(*project, *zone, i).Do()