Skip to content

Add --gce_max_run_duration and --gce_instance_termination_action - #7202

Open
thestephenromano wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
thestephenromano:gce-max-run-duration
Open

thestephenromano wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
thestephenromano:gce-max-run-duration

Conversation

@thestephenromano

Copy link
Copy Markdown

Summary

This adds --gce_max_run_duration (seconds, at least 30) and --gce_instance_termination_action (DELETE by default, or STOP).

When the duration is set, PKB passes --max-run-duration and --instance-termination-action to gcloud compute instances create. GCE then deletes or stops the instance after that lifetime, whether or not PKB is still running. Both values are recorded in the VM's resource metadata. The flags follow --gce_provisioning_model: applied in _GenerateCreateCommand and reported in GetResourceMetadata.

Why

PKB's own timeout handling depends on the controller staying alive. A provider-side lifetime bounds cost and leftover instances when the controller is killed, loses connectivity, or crashes during a long run.

GCE accepts the limit only at creation: gcloud compute instances set-scheduling --max-run-duration on a running instance fails with "Max run duration cannot be changed while the instance is running". So it can't be added after PKB has created the VM, and it has to go into the create command.

Tests

tests/gce_virtual_machine_test.py gains three cases:

  • the duration with the default DELETE action;
  • an explicit STOP action;
  • no scheduling flags when the duration is unset.

All 100 tests in that file pass. I also tested the same create-time flags live on GCE: an instance created with a one-hour limit and DELETE was deleted by GCE (compute.instances.deferredDelete by system) one hour after its insert, after the controlling PKB process had been killed.

GCE can delete or stop an instance after a fixed lifetime, enforced by the
provider independently of PKB. GCE accepts the limit only when the instance
is created (instances set-scheduling refuses it on a running instance), so
it has to be part of the create command. This exposes it as two flags,
applied in _GenerateCreateCommand and recorded in the VM metadata, in the
same way as --gce_provisioning_model.
@google-cla

google-cla Bot commented Oct 29, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant