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
3 changed files with 11 additions and 6 deletions

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