Documentation
¶
Overview ¶
Package pool discovers idle, tagged macOS EC2 instances and attaches to one via an S3-backed lease. It never provisions or creates instances itself.
Index ¶
- Constants
- Variables
- func AcquireIdleInstance(ctx context.Context, region, profile, leaseBucket string, pool []string, ...) (instanceID string, leaseToken string, imageID string, err error)
- func CurrentLeaseToken(ctx context.Context, region, profile, leaseBucket, instanceID string) (string, error)
- func NewEC2Client(ctx context.Context, region, profile string) (*awsec2.Client, error)
- func PublishInitialLease(ctx context.Context, ...) (string, error)
- func RevertAndRelease(ctx context.Context, ...) error
- func RevertInPlace(ctx context.Context, ...) (string, error)
- type AcquireResult
- type LocalProvisionOptions
- type PoolInstance
Constants ¶
const ( PoolTagKey = "dd:macos-e2e-pool-instance" PoolTagValue = "true" )
PoolTagKey/PoolTagValue identify every macOS instance managed by the pool, shared by every macOS VM request so they all draw from (and grow) the same pool.
const OwnerUsernameTagKey = "dd:macos-e2e-pool-owner"
OwnerUsernameTagKey additionally scopes discovery to a single developer's own locally-provisioned instance (see LocalProvisionOptions), so developers sharing an account never claim each other's. Its value is the owner's OS username.
Variables ¶
var ErrLeaseAlreadyExists = errors.New("lease record already exists")
ErrLeaseAlreadyExists reports that PublishInitialLease lost its conditional create, i.e. the instance is already registered. Callers recover with CurrentLeaseToken.
Functions ¶
func AcquireIdleInstance ¶
func AcquireIdleInstance(ctx context.Context, region, profile, leaseBucket string, pool []string, stackID string) (instanceID string, leaseToken string, imageID string, err error)
AcquireIdleInstance claims one idle instance from pool via a conditional S3 write (If-Match on the lease object's current ETag), retrying the whole-pool scan up to maxAcquireRetries times, acquireRetryInterval apart, then failing errPoolExhausted.
func CurrentLeaseToken ¶
func CurrentLeaseToken(ctx context.Context, region, profile, leaseBucket, instanceID string) (string, error)
CurrentLeaseToken returns instanceID's current lease ETag, letting a caller that hit ErrLeaseAlreadyExists adopt the existing lease instead of failing.
func NewEC2Client ¶
NewEC2Client builds an EC2 API client scoped to region/profile.
func PublishInitialLease ¶
func PublishInitialLease(ctx context.Context, region, profile, leaseBucket, instanceID, imageID, holder string) (string, error)
PublishInitialLease writes instanceID's first lease record, held by holder and marked Persistent, and returns the lease token. Fails ErrLeaseAlreadyExists if a lease is already present.
func RevertAndRelease ¶
func RevertAndRelease(ctx context.Context, region, profile, leaseBucket, instanceID, leaseToken string, devMode bool) error
RevertAndRelease reverts instanceID's root volume to the lease's current baseline image and releases the lease, conditioned on leaseToken matching the lease object's current ETag. The revert is skipped in dev mode or for a persistent lease.
func RevertInPlace ¶
func RevertInPlace(ctx context.Context, region, profile, leaseBucket, instanceID, leaseToken string) (string, error)
RevertInPlace reverts instanceID's root volume to the lease's current baseline image, like RevertAndRelease, but re-publishes the lease as statusInUse instead of releasing it. Returns the new lease token, which the caller must keep to release.
Types ¶
type AcquireResult ¶
type AcquireResult struct {
Found bool
InstanceID string
HostID string
SubnetID string
LeaseToken string
ImageID string
}
AcquireResult is a successfully claimed pool member. Found is false only when local is non-nil and the developer owns no pool instance yet, signaling the caller to provision one; every other failure is reported as an error instead.
func Acquire ¶
func Acquire(ctx context.Context, region, profile, leaseBucket string, client *awsec2.Client, stackID string, local *LocalProvisionOptions) (AcquireResult, error)
Acquire lists every instance tagged PoolTagKey=PoolTagValue (additionally scoped to OwnerUsernameTagKey=local.Username when local is non-nil) and claims one idle member. An empty pool yields Found: false for a local run; all else is an error.
type LocalProvisionOptions ¶
type LocalProvisionOptions struct {
// Username identifies the developer's own instance via OwnerUsernameTagKey,
// e.g. aws.Environment.Username(). Must be non-empty.
Username string
}
LocalProvisionOptions scopes Acquire to a single developer's own locally-provisioned instance, and turns an empty pool from an error into AcquireResult{Found: false} so the caller can provision one instead.
type PoolInstance ¶
PoolInstance is one EC2 instance discovered by ListPoolInstances, with the Dedicated Host and subnet it currently sits on. SubnetId must be preserved on import since the instance's AZ is fixed by its Dedicated Host.
func ListPoolInstances ¶
func ListPoolInstances(ctx context.Context, client *awsec2.Client, tags map[string]string) ([]PoolInstance, error)
ListPoolInstances returns every running or stopped EC2 instance carrying every tag in tags.