Documentation
¶
Overview ¶
Package preempt watches a cloud provider's instance metadata service for the notice that a spot or preemptible machine is about to be reclaimed, so the worker running on it can hand its tasks back at once instead of being killed mid-task.
The watcher is opt-in (worker.preemption.watch) and contacts nothing otherwise. It supports the three notices providers publish:
- aws: the IMDSv2 spot instance-action document.
- gcp: the instance/preempted flag.
- azure: a Preempt event in the Scheduled Events document.
A failed poll never stops the watcher: a metadata service that is briefly unreachable must not leave a machine that is then reclaimed unwatched.
Index ¶
Constants ¶
const ( VendorAWS = "aws" VendorGCP = "gcp" VendorAzure = "azure" )
Vendor names, as written in worker.preemption.watch.
Variables ¶
This section is empty.
Functions ¶
func InstanceID ¶
InstanceID reads the identifier of the cloud instance the worker runs on from the instance metadata service of vendor (aws, gcp or azure), with the same base URLs, endpoint override and client rules as New. The identifier is the one a scale-set or instance-group operation names:
- aws: the EC2 instance ID ("i-0abc..."), read after an IMDSv2 token.
- gcp: the instance name, which "gcloud ... delete-instances" takes.
- azure: the scale-set instance ID, the last segment of the VM's resource ID.
Each request is bounded by the same 2 s timeout as a preemption poll. Any failure is an error; the caller decides what a missing ID costs.
Types ¶
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher polls one vendor's metadata service for a preemption notice.
func New ¶
func New(vendor, endpoint string, interval time.Duration, client *http.Client, logger *slog.Logger) (*Watcher, error)
New builds a Watcher for vendor (aws, gcp or azure), polling every interval. endpoint, when not empty, replaces the vendor's default metadata base URL (for a proxy, or a test). client may be nil for the default client, which never uses an HTTP proxy: the metadata service is link-local, and a proxy named by HTTP_PROXY would answer for a different machine or not at all.