cloud

package
v0.0.0-...-1402089 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 69 Imported by: 73

Documentation

Overview

Package cloud handles interactions with third-party cloud providers.

Index

Constants

View Source
const (
	// StatusUnknown is a catch-all for unrecognized status codes.
	StatusUnknown = CloudStatus(iota)

	// StatusPending indicates that it is not yet clear if the instance has been
	// successfully started or not (e.g. pending spot request).
	StatusPending

	// StatusInitializing means the instance request has been successfully
	// fulfilled, but it's not yet done booting up.
	StatusInitializing

	// StatusFailed indicates that an attempt to start the instance has failed.
	// This could be due to billing, lack of capacity, etc.
	StatusFailed

	// StatusRunning means the machine is done booting, and active.
	StatusRunning

	// StatusStopping indicates that the instance is in the processing of
	// stopping but has not yet stopped completely.
	StatusStopping

	// StatusStopped indicates that the instance is shut down, but can be
	// started again.
	StatusStopped

	// StatusTerminated indicates that the instance is deleted.
	StatusTerminated

	// StatusNonExistent indicates that the instance doesn't exist.
	StatusNonExistent
)
View Source
const (
	VolumeTypeStandard = "standard"
	VolumeTypeIo1      = "io1"
	VolumeTypeGp3      = "gp3"
	VolumeTypeGp2      = "gp2"
	VolumeTypeSc1      = "sc1"
	VolumeTypeSt1      = "st1"
)
View Source
const (
	EC2ErrorNotFound        = "InvalidInstanceID.NotFound"
	EC2DuplicateKeyPair     = "InvalidKeyPair.Duplicate"
	EC2InsufficientCapacity = "InsufficientInstanceCapacity"
	EC2InvalidParam         = "InvalidParameterValue"
	EC2VolumeNotFound       = "InvalidVolume.NotFound"
	EC2VolumeResizeRate     = "VolumeModificationRateExceeded"
)
View Source
const (
	// SecretsManagerResourceFilter is the name of the resource filter to find
	// Secrets Manager secrets.
	SecretsManagerResourceFilter = "secretsmanager:secret"
	// PodDefinitionResourceFilter is the name of the resource filter to find
	// ECS pod definitions.
	PodDefinitionResourceFilter = "ecs:task-definition"
)
View Source
const MockIPV4 = "12.34.56.78"
View Source
const MockIPV6 = "abcd:1234:459c:2d00:cfe4:843b:1d60:8e47"

Variables

View Source
var (
	// bson fields for the EC2ProviderSettings struct
	AMIKey            = bsonutil.MustHaveTag(EC2ProviderSettings{}, "AMI")
	InstanceTypeKey   = bsonutil.MustHaveTag(EC2ProviderSettings{}, "InstanceType")
	SecurityGroupsKey = bsonutil.MustHaveTag(EC2ProviderSettings{}, "SecurityGroupIDs")
	KeyNameKey        = bsonutil.MustHaveTag(EC2ProviderSettings{}, "KeyName")
	MountPointsKey    = bsonutil.MustHaveTag(EC2ProviderSettings{}, "MountPoints")
)
View Source
var (
	// bson fields for the MountPoint struct
	VirtualNameKey = bsonutil.MustHaveTag(MountPoint{}, "VirtualName")
	DeviceNameKey  = bsonutil.MustHaveTag(MountPoint{}, "DeviceName")
	SizeKey        = bsonutil.MustHaveTag(MountPoint{}, "Size")
	VolumeTypeKey  = bsonutil.MustHaveTag(MountPoint{}, "VolumeType")
)
View Source
var (
	// bson fields for the StaticSettings struct
	HostsKey = bsonutil.MustHaveTag(StaticSettings{}, "Hosts")

	// bson fields for the Host struct
	NameKey = bsonutil.MustHaveTag(StaticHost{}, "Name")
)
View Source
var (
	EC2InsufficientCapacityError = errors.New(EC2InsufficientCapacity)
)

Functions

func AttachVolume

func AttachVolume(ctx context.Context, volumeId string, hostId string) (int, error)

func AttachVolumeBadRequest

func AttachVolumeBadRequest(err error) bool

func AztoRegion

func AztoRegion(az string) string

AztoRegion takes an availability zone and returns the region id.

func CheckInstanceTypeValid

func CheckInstanceTypeValid(ctx context.Context, d distro.Distro, requestedType string, allowedTypes []string) error

assumes distro already modified to have one region

func CreateSpawnHost

func CreateSpawnHost(ctx context.Context, so SpawnOptions, settings *evergreen.Settings) (*host.Host, error)

CreateSpawnHost spawns a host with the given options.

func CreateVolume

func CreateVolume(ctx context.Context, env evergreen.Environment, volume *host.Volume, provider string) (*host.Volume, error)

func DeleteVolume

func DeleteVolume(ctx context.Context, volumeId string) (int, error)

func DetachVolume

func DetachVolume(ctx context.Context, volumeId string) (int, error)

func ExportECSPod

func ExportECSPod(p *pod.Pod, c cocoa.ECSClient, v cocoa.Vault) (cocoa.ECSPod, error)

ExportECSPod exports the pod DB model to its equivalent cocoa.ECSPod backed by the given ECS client and secret vault.

func ExportECSPodDefinition

func ExportECSPodDefinition(podDef definition.PodDefinition) cocoa.ECSTaskDefinition

ExportECSPodDefinition exports the pod definition into an cocoa.ECSTaskDefinition.

func ExportECSPodDefinitionOptions

func ExportECSPodDefinitionOptions(settings *evergreen.Settings, opts pod.TaskContainerCreationOptions) (*cocoa.ECSPodDefinitionOptions, error)

ExportECSPodDefinitionOptions exports the ECS pod creation options into cocoa.ECSPodDefinitionOptions to create the pod definition.

func ExportECSPodExecutionOptions

func ExportECSPodExecutionOptions(ecsConfig evergreen.ECSConfig, containerOpts pod.TaskContainerCreationOptions) (*cocoa.ECSPodExecutionOptions, error)

ExportECSPodExecutionOptions exports the ECS configuration into cocoa.ECSPodExecutionOptions.

func GetFilteredResourceIDs

func GetFilteredResourceIDs(ctx context.Context, c cocoa.TagClient, resources []string, tags map[string][]string, limit int) ([]string, error)

GetFilteredResourceIDs gets resources that match the given resource and tag filters. If the limit is positive, it will return at most that many results. If the limit is zero, this will return no results. If the limit is negative, the results are unlimited

func GetMockClient

func GetMockClient() *dockerClientMock

func Gp2EquivalentIOPSForGp3

func Gp2EquivalentIOPSForGp3(volumeSize int32) int32

Gp2EquivalentIOPSForGp3 returns an IOPS value for gp3 volumes that's at least equivalent to the IOPS of gp2 volumes. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/general-purpose.html for more information.

func Gp2EquivalentThroughputForGp3

func Gp2EquivalentThroughputForGp3(volumeSize int32) int32

Gp2EquivalentThroughputForGp3 returns a throughput value for gp3 volumes that's at least equivalent to the throughput of gp2 volumes. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/general-purpose.html for more information.

func ImportECSPodResources

func ImportECSPodResources(res cocoa.ECSPodResources) pod.ResourceInfo

ImportECSPodResources imports the ECS pod resource information into the equivalent pod.ResourceInfo.

func IsEC2InstanceID

func IsEC2InstanceID(id string) bool

IsEC2InstanceID returns whether or not a host's ID is an EC2 instance ID or not.

func MakeECSClient

func MakeECSClient(ctx context.Context, settings *evergreen.Settings) (cocoa.ECSClient, error)

MakeECSClient creates a cocoa.ECSClient to interact with ECS.

func MakeECSPodCreator

func MakeECSPodCreator(c cocoa.ECSClient, v cocoa.Vault) (cocoa.ECSPodCreator, error)

MakeECSPodCreator creates a cocoa.ECSPodCreator to create pods backed by ECS and secrets backed by an optional cocoa.Vault.

func MakeECSPodDefinitionManager

func MakeECSPodDefinitionManager(c cocoa.ECSClient, v cocoa.Vault) (cocoa.ECSPodDefinitionManager, error)

MakeECSPodDefinitionManager creates a cocoa.ECSPodDefinitionManager that creates pod definitions in ECS and secrets backed by an optional cocoa.Vault.

func MakeExtendedSpawnHostExpiration

func MakeExtendedSpawnHostExpiration(host *host.Host, extendBy time.Duration) (time.Time, error)

func MakeSecretsManagerClient

func MakeSecretsManagerClient(ctx context.Context, settings *evergreen.Settings) (cocoa.SecretsManagerClient, error)

MakeSecretsManagerClient creates a cocoa.SecretsManagerClient to interact with Secrets Manager.

func MakeSecretsManagerVault

func MakeSecretsManagerVault(c cocoa.SecretsManagerClient) (cocoa.Vault, error)

MakeSecretsManagerVault creates a cocoa.Vault backed by Secrets Manager with an optional cocoa.SecretCache.

func MakeTagClient

func MakeTagClient(ctx context.Context, settings *evergreen.Settings) (cocoa.TagClient, error)

MakeTagClient creates a cocoa.TagClient to interact with the Resource Groups Tagging API.

func ModifySpawnHost

func ModifySpawnHost(ctx context.Context, env evergreen.Environment, host *host.Host, opts host.HostModifyOptions) error

func ModifyVolumeBadRequest

func ModifyVolumeBadRequest(err error) bool

func RequestNewVolume

func RequestNewVolume(ctx context.Context, volume host.Volume) (*host.Volume, int, error)

func SetHostRDPPassword

func SetHostRDPPassword(ctx context.Context, env evergreen.Environment, h *host.Host, pwd string) (int, error)

SetHostRDPPassword is a shared utility function to change the password on a windows host

func TerminateSpawnHost

func TerminateSpawnHost(ctx context.Context, env evergreen.Environment, host *host.Host, user, reason string) error

func UsesHourlyBilling

func UsesHourlyBilling(d *distro.Distro) bool

UsesHourlyBilling returns if a distro is billed hourly.

func ValidVolumeOptions

func ValidVolumeOptions(v *host.Volume, s *evergreen.Settings) error

Types

type AWSClient

type AWSClient interface {
	// Create a new aws-sdk-client or mock if one does not exist, otherwise no-op.
	Create(context.Context, string) error

	// RunInstances is a wrapper for ec2.RunInstances.
	RunInstances(context.Context, *ec2.RunInstancesInput) (*ec2.RunInstancesOutput, error)

	// DescribeInstances is a wrapper for ec2.DescribeInstances.
	DescribeInstances(context.Context, *ec2.DescribeInstancesInput) (*ec2.DescribeInstancesOutput, error)

	// ModifyInstanceAttribute is a wrapper for ec2.ModifyInstanceAttribute.
	ModifyInstanceAttribute(context.Context, *ec2.ModifyInstanceAttributeInput) (*ec2.ModifyInstanceAttributeOutput, error)

	// DescribeInstanceTypeOfferings is a wrapper for ec2.DescribeInstanceTypeOfferings.
	DescribeInstanceTypeOfferings(context.Context, *ec2.DescribeInstanceTypeOfferingsInput) (*ec2.DescribeInstanceTypeOfferingsOutput, error)

	// CreateTags is a wrapper for ec2.CreateTags.
	CreateTags(context.Context, *ec2.CreateTagsInput) (*ec2.CreateTagsOutput, error)

	// DeleteTags is a wrapper for ec2.DeleteTags.
	DeleteTags(context.Context, *ec2.DeleteTagsInput) (*ec2.DeleteTagsOutput, error)

	// TerminateInstances is a wrapper for ec2.TerminateInstances.
	TerminateInstances(context.Context, *ec2.TerminateInstancesInput) (*ec2.TerminateInstancesOutput, error)

	// StopInstances is a wrapper for ec2.StopInstances.
	StopInstances(context.Context, *ec2.StopInstancesInput) (*ec2.StopInstancesOutput, error)

	// StartInstances is a wrapper for ec2.StartInstances.
	StartInstances(context.Context, *ec2.StartInstancesInput) (*ec2.StartInstancesOutput, error)

	// CreateVolume is a wrapper for ec2.CreateVolume.
	CreateVolume(context.Context, *ec2.CreateVolumeInput) (*ec2.CreateVolumeOutput, error)

	// DeleteVolume is a wrapper for ec2.DeleteWrapper.
	DeleteVolume(context.Context, *ec2.DeleteVolumeInput) (*ec2.DeleteVolumeOutput, error)

	// AttachVolume is a wrapper for ec2.AttachVolume. Generates device name on error if applicable.
	AttachVolume(context.Context, *ec2.AttachVolumeInput, generateDeviceNameOptions) (*ec2.AttachVolumeOutput, error)

	// DetachVolume is a wrapper for ec2.DetachVolume.
	DetachVolume(context.Context, *ec2.DetachVolumeInput) (*ec2.DetachVolumeOutput, error)

	// ModifyVolume is a wrapper for ec2.ModifyVolume.
	ModifyVolume(context.Context, *ec2.ModifyVolumeInput) (*ec2.ModifyVolumeOutput, error)

	// DescribeVolumes is a wrapper for ec2.DescribeVolumes.
	DescribeVolumes(context.Context, *ec2.DescribeVolumesInput) (*ec2.DescribeVolumesOutput, error)

	// DescribeSubnets is a wrapper for ec2.DescribeSubnets.
	DescribeSubnets(context.Context, *ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error)

	// DescribeVpcs is a wrapper for ec2.DescribeVpcs.
	DescribeVpcs(context.Context, *ec2.DescribeVpcsInput) (*ec2.DescribeVpcsOutput, error)

	// GetInstanceInfo returns info about an ec2 instance.
	GetInstanceInfo(context.Context, string) (*types.Instance, error)

	// CreateKeyPair is a wrapper for ec2.CreateKeyPair.
	CreateKeyPair(context.Context, *ec2.CreateKeyPairInput) (*ec2.CreateKeyPairOutput, error)

	// ImportKeyPair is a wrapper for ec2.ImportKeyPair.
	ImportKeyPair(context.Context, *ec2.ImportKeyPairInput) (*ec2.ImportKeyPairOutput, error)

	// DeleteKeyPair is a wrapper for ec2.DeleteKeyPair.
	DeleteKeyPair(context.Context, *ec2.DeleteKeyPairInput) (*ec2.DeleteKeyPairOutput, error)

	// CreateLaunchTemplate is a wrapper for ec2.CreateLaunchTemplate.
	CreateLaunchTemplate(context.Context, *ec2.CreateLaunchTemplateInput) (*ec2.CreateLaunchTemplateOutput, error)

	// DeleteLaunchTemplate is a wrapper for ec2.DeleteLaunchTemplate.
	DeleteLaunchTemplate(context.Context, *ec2.DeleteLaunchTemplateInput) (*ec2.DeleteLaunchTemplateOutput, error)

	// GetLaunchTemplates gets all the launch templates that match the input.
	GetLaunchTemplates(context.Context, *ec2.DescribeLaunchTemplatesInput) ([]types.LaunchTemplate, error)

	// CreateFleet is a wrapper for ec2.CreateFleet.
	CreateFleet(context.Context, *ec2.CreateFleetInput) (*ec2.CreateFleetOutput, error)

	GetKey(context.Context, *host.Host) (string, error)

	SetTags(context.Context, []string, *host.Host) error

	GetInstanceBlockDevices(context.Context, *host.Host) ([]types.InstanceBlockDeviceMapping, error)

	GetVolumeIDs(context.Context, *host.Host) ([]string, error)

	GetPublicDNSName(ctx context.Context, h *host.Host) (string, error)

	// ChangeResourceRecordSets is a wrapper for route53.ChangeResourceRecordSets.
	ChangeResourceRecordSets(context.Context, *route53.ChangeResourceRecordSetsInput) (*route53.ChangeResourceRecordSetsOutput, error)

	// AssumeRole is a wrapper for sts.AssumeRole.
	AssumeRole(ctx context.Context, input *sts.AssumeRoleInput) (*sts.AssumeRoleOutput, error)
}

AWSClient is a wrapper for aws-sdk-go so we can use a mock in testing.

type AssumeRoleCredentials

type AssumeRoleCredentials struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
	Expiration      time.Time
}

AssumeRoleCredentials are the credentials to be returned from assuming a role.

type AssumeRoleOptions

type AssumeRoleOptions struct {
	// RoleARN is the Amazon Resource Name (ARN) of the role to assume.
	RoleARN string
	// Policy is an optional field that can be used to restrict the permissions.
	Policy *string
	// DurationSeconds is an optional field of the duration of the role session.
	// It defaults to 15 minutes.
	DurationSeconds *int32
}

AssumeRoleOptions are the options for assuming a role. Some internal options are not present and are set by the manager (e.g. ExternalID).

type BatchManager

type BatchManager interface {
	// GetInstanceStatuses gets the statuses of a slice of instances. It returns
	// a map of the instance IDs to their current status. If some of the
	// instance statuses cannot be retrieved, implementations are allowed to
	// either return an error or return StatusNonExistent for those hosts.
	// If there is no error, implementations should return the same number of
	// results in the map as there are hosts.
	GetInstanceStatuses(context.Context, []host.Host) (map[string]CloudStatus, error)
}

BatchManager is an interface for cloud providers that support batch operations.

type CloudHost

type CloudHost struct {
	Host     *host.Host
	CloudMgr Manager
}

CloudHost is a provider-agnostic host object that delegates methods like status checks, ssh options, DNS name checks, termination, etc. to the underlying provider's implementation.

func GetCloudHost

func GetCloudHost(ctx context.Context, host *host.Host, env evergreen.Environment) (*CloudHost, error)

GetCloudHost returns an instance of CloudHost wrapping the given model.Host, giving access to the provider-specific methods to manipulate on the host.

func (*CloudHost) GetDNSName

func (cloudHost *CloudHost) GetDNSName(ctx context.Context) (string, error)

func (*CloudHost) GetInstanceState

func (cloudHost *CloudHost) GetInstanceState(ctx context.Context) (CloudInstanceState, error)

func (*CloudHost) ModifyHost

func (cloudHost *CloudHost) ModifyHost(ctx context.Context, opts host.HostModifyOptions) error

func (*CloudHost) StartInstance

func (cloudHost *CloudHost) StartInstance(ctx context.Context, user string) error

func (*CloudHost) StopInstance

func (cloudHost *CloudHost) StopInstance(ctx context.Context, shouldKeepOff bool, user string) error

func (*CloudHost) TerminateInstance

func (cloudHost *CloudHost) TerminateInstance(ctx context.Context, user, reason string) error

type CloudInstanceState

type CloudInstanceState struct {
	// Status is the current status of the instance.
	Status CloudStatus
	// StateReason is a human-readable explanation of why the instance is in
	// its current state.
	StateReason string
}

type CloudStatus

type CloudStatus int

func (CloudStatus) String

func (stat CloudStatus) String() string

type ContainerManager

type ContainerManager interface {
	Manager

	// GetContainers returns the IDs of all running containers on a specified host
	GetContainers(context.Context, *host.Host) ([]string, error)
	// RemoveOldestImage removes the earliest created image on a specified host
	RemoveOldestImage(ctx context.Context, h *host.Host) error
	// CalculateImageSpaceUsage returns the total space taken up by docker images on a specified host
	CalculateImageSpaceUsage(ctx context.Context, h *host.Host) (int64, error)
	// GetContainerImage downloads a container image onto parent specified by URL, and builds evergreen agent unless otherwise specified
	GetContainerImage(ctx context.Context, parent *host.Host, options host.DockerOptions) error
}

func ConvertContainerManager

func ConvertContainerManager(m Manager) (ContainerManager, error)

ConvertContainerManager converts a regular manager into a container manager, errors if type conversion not possible.

type ContainerStatus

type ContainerStatus struct {
	IsRunning  bool
	HasStarted bool
}

type DockerClient

type DockerClient interface {
	Init(string) error
	EnsureImageDownloaded(context.Context, *host.Host, host.DockerOptions) (string, error)
	BuildImageWithAgent(context.Context, string, *host.Host, string) (string, error)
	CreateContainer(context.Context, *host.Host, *host.Host) error
	GetContainer(context.Context, *host.Host, string) (*types.ContainerJSON, error)
	GetDockerLogs(context.Context, string, *host.Host, types.ContainerLogsOptions) (io.Reader, error)
	GetDockerStatus(context.Context, string, *host.Host) (*ContainerStatus, error)
	ListContainers(context.Context, *host.Host) ([]types.Container, error)
	RemoveImage(context.Context, *host.Host, string) error
	RemoveContainer(context.Context, *host.Host, string) error
	StartContainer(context.Context, *host.Host, string) error
	AttachToContainer(context.Context, *host.Host, string, host.DockerOptions) (*types.HijackedResponse, error)
	ListImages(context.Context, *host.Host) ([]types.ImageSummary, error)
}

The DockerClient interface wraps the Docker dockerClient interaction.

func GetDockerClient

func GetDockerClient(s *evergreen.Settings) DockerClient

type EC2FleetManagerOptions

type EC2FleetManagerOptions struct {
	// contains filtered or unexported fields
}

type EC2ManagerOptions

type EC2ManagerOptions struct {
	// contains filtered or unexported fields
}

EC2ManagerOptions are used to construct a new ec2Manager.

type EC2ProviderSettings

type EC2ProviderSettings struct {
	// Region is the EC2 region in which the instance will start. Empty is equivalent to the Evergreen default region.
	// This should remain one of the first fields to speed up the birch document iterator.
	Region string `mapstructure:"region" json:"region" bson:"region,omitempty"`

	// AMI is the AMI ID.
	AMI string `mapstructure:"ami" json:"ami,omitempty" bson:"ami,omitempty"`

	// InstanceType is the EC2 instance type.
	InstanceType string `mapstructure:"instance_type" json:"instance_type,omitempty" bson:"instance_type,omitempty"`

	// IPv6 is set to true if the instance should have only an IPv6 address.
	IPv6 bool `mapstructure:"ipv6" json:"ipv6,omitempty" bson:"ipv6,omitempty"`

	// KeyName is the AWS SSH key name.
	KeyName string `mapstructure:"key_name" json:"key_name,omitempty" bson:"key_name,omitempty"`

	// MountPoints are the disk mount points for EBS volumes.
	MountPoints []MountPoint `mapstructure:"mount_points" json:"mount_points,omitempty" bson:"mount_points,omitempty"`

	// SecurityGroupIDs is a list of security group IDs.
	SecurityGroupIDs []string `mapstructure:"security_group_ids" json:"security_group_ids,omitempty" bson:"security_group_ids,omitempty"`

	// IAMInstanceProfileARN is the Amazon Resource Name (ARN) of the instance profile.
	IAMInstanceProfileARN string `` /* 134-byte string literal not displayed */

	// SubnetId is only set in a VPC. Either subnet id or vpc name must set.
	SubnetId string `mapstructure:"subnet_id" json:"subnet_id,omitempty" bson:"subnet_id,omitempty"`

	// Tenancy, if set, determines how EC2 instances are distributed across
	// physical hardware.
	Tenancy evergreen.EC2Tenancy `mapstructure:"tenancy" json:"tenancy,omitempty" bson:"tenancy,omitempty"`

	// VpcName is used to get the subnet ID automatically. Either subnet id or vpc name must set.
	VpcName string `mapstructure:"vpc_name" json:"vpc_name,omitempty" bson:"vpc_name,omitempty"`

	// IsVpc is set to true if the security group is part of a VPC.
	IsVpc bool `mapstructure:"is_vpc" json:"is_vpc,omitempty" bson:"is_vpc,omitempty"`

	// UserData specifies configuration that runs after the instance starts.
	UserData string `mapstructure:"user_data" json:"user_data,omitempty" bson:"user_data,omitempty"`

	// MergeUserDataParts specifies whether multiple user data parts should be
	// merged into a single user data part.
	// EVG-7760: This is primarily a workaround for a problem with Windows not
	// allowing multiple scripts of the same type as part of a multipart user
	// data upload.
	MergeUserDataParts bool `mapstructure:"merge_user_data_parts" json:"merge_user_data_parts,omitempty" bson:"merge_user_data_parts,omitempty"`

	// FleetOptions specifies options for creating host with Fleet. It is ignored by other managers.
	FleetOptions FleetConfig `mapstructure:"fleet_options" json:"fleet_options,omitempty" bson:"fleet_options,omitempty"`
}

EC2ProviderSettings describes properties of managed instances.

func (*EC2ProviderSettings) FromDistroSettings

func (s *EC2ProviderSettings) FromDistroSettings(d distro.Distro, region string) error

region is only provided if we want to filter by region

func (*EC2ProviderSettings) FromDocument

func (s *EC2ProviderSettings) FromDocument(doc *birch.Document) error

func (*EC2ProviderSettings) ToDocument

func (s *EC2ProviderSettings) ToDocument() (*birch.Document, error)

func (*EC2ProviderSettings) Validate

func (s *EC2ProviderSettings) Validate() error

Validate that essential EC2ProviderSettings fields are not empty.

type FleetConfig

type FleetConfig struct {
	// UseOnDemand will cause Fleet to use on-demand instances to instantiate hosts. Defaults to spot instances.
	UseOnDemand bool `mapstructure:"use_on_demand" json:"use_on_demand,omitempty" bson:"use_on_demand,omitempty"`

	// UseCapacityOptimized will cause Fleet to use the capacity-optimized allocation strategy for spawning hosts. Defaults to the AWS default (lowest-cost).
	// See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html for more information about Fleet allocation strategies.
	UseCapacityOptimized bool `mapstructure:"use_capacity_optimized" json:"use_capacity_optimized,omitempty" bson:"use_capacity_optimized,omitempty"`
}

FleetConfig specifies how the EC2 Fleet manager should spawn hosts.

type Manager

type Manager interface {
	// Load credentials or other settings from the config file
	Configure(context.Context, *evergreen.Settings) error

	// SpawnHost attempts to create a new host by requesting one from the
	// provider's API.
	SpawnHost(context.Context, *host.Host) (*host.Host, error)

	// ModifyHost modifies an existing host
	ModifyHost(context.Context, *host.Host, host.HostModifyOptions) error

	// Gets the state of an instance
	GetInstanceState(context.Context, *host.Host) (CloudInstanceState, error)

	// SetPortMappings sets the port mappings for the container
	SetPortMappings(context.Context, *host.Host, *host.Host) error

	// TerminateInstance destroys the host in the underlying provider
	TerminateInstance(context.Context, *host.Host, string, string) error

	// StopInstance stops an instance.
	StopInstance(ctx context.Context, h *host.Host, shouldKeepOff bool, user string) error

	// StartInstance starts a stopped instance.
	StartInstance(context.Context, *host.Host, string) error

	// GetDNSName returns the DNS name of a host.
	GetDNSName(context.Context, *host.Host) (string, error)

	// AttachVolume attaches a volume to a host.
	AttachVolume(context.Context, *host.Host, *host.VolumeAttachment) error

	// DetachVolume detaches a volume from a host.
	DetachVolume(context.Context, *host.Host, string) error

	// CreateVolume creates a new volume for attaching to a host.
	CreateVolume(context.Context, *host.Volume) (*host.Volume, error)

	// DeleteVolume deletes a volume.
	DeleteVolume(context.Context, *host.Volume) error

	// ModifyVolume modifies an existing volume.
	ModifyVolume(context.Context, *host.Volume, *model.VolumeModifyOptions) error

	// GetVolumeAttachment gets a volume's attachment
	GetVolumeAttachment(context.Context, string) (*VolumeAttachment, error)

	// CheckInstanceType determines if the given instance type is available in the current region.
	CheckInstanceType(context.Context, string) error

	// TimeTilNextPayment returns how long there is until the next payment
	// is due for a particular host
	TimeTilNextPayment(*host.Host) time.Duration

	// Cleanup triggers the manager to clean up resources left behind by day-to-day operations.
	Cleanup(context.Context) error

	// AddSSHKey adds an SSH key for this manager's hosts. Adding an existing
	// key is a no-op.
	AddSSHKey(context.Context, evergreen.SSHKeyPair) error
}

Manager is an interface which handles creating new hosts or modifying them via some third-party API.

func GetEC2ManagerForVolume

func GetEC2ManagerForVolume(ctx context.Context, vol *host.Volume) (Manager, error)

func GetManager

func GetManager(ctx context.Context, env evergreen.Environment, mgrOpts ManagerOpts) (Manager, error)

GetManager returns an implementation of Manager for the given manager options. It returns an error if the provider name doesn't have a known implementation.

type ManagerOpts

type ManagerOpts struct {
	Provider       string
	Region         string
	ProviderKey    string
	ProviderSecret string
}

ManagerOpts is a struct containing the fields needed to get a new cloud manager of the proper type.

func GetManagerOptions

func GetManagerOptions(d distro.Distro) (ManagerOpts, error)

GetManagerOptions gets the manager options from the provider settings object for a given provider name.

type MockInstance

type MockInstance struct {
	IsSSHReachable     bool
	Status             CloudStatus
	SSHOptions         []string
	TimeTilNextPayment time.Duration
	DNSName            string
	Tags               []host.Tag
	Type               string
	BlockDevices       []string
}

MockInstance mocks a running server that Evergreen knows about. It contains fields that can be set to change the response the cloud manager returns when this mock instance is queried for.

type MockProvider

type MockProvider interface {
	Len() int
	Reset()
	Get(string) MockInstance
	Set(string, MockInstance)
	IterIDs() <-chan string
	IterInstances() <-chan MockInstance
}

func GetMockProvider

func GetMockProvider() MockProvider

type MockProviderSettings

type MockProviderSettings struct {
	Region string `mapstructure:"region" json:"region" bson:"region,omitempty"`
}

func (*MockProviderSettings) FromDistroSettings

func (_ *MockProviderSettings) FromDistroSettings(_ distro.Distro, _ string) error

func (*MockProviderSettings) Validate

func (_ *MockProviderSettings) Validate() error

type MockVolume

type MockVolume struct {
	DeviceName   string
	Type         string
	Size         int32
	Expiration   time.Time
	NoExpiration bool
}

type MountPoint

type MountPoint struct {
	VirtualName string `mapstructure:"virtual_name" json:"virtual_name,omitempty" bson:"virtual_name,omitempty"`
	DeviceName  string `mapstructure:"device_name" json:"device_name,omitempty" bson:"device_name,omitempty"`
	Size        int32  `mapstructure:"size" json:"size,omitempty" bson:"size,omitempty"`
	Iops        int32  `mapstructure:"iops" json:"iops,omitempty" bson:"iops,omitempty"`
	Throughput  int32  `mapstructure:"throughput" json:"throughput,omitempty" bson:"throughput,omitempty"`
	SnapshotID  string `mapstructure:"snapshot_id" json:"snapshot_id,omitempty" bson:"snapshot_id,omitempty"`
	VolumeType  string `mapstructure:"volume_type" json:"volume_type,omitempty" bson:"volume_type,omitempty"`
}

type NoopECSPodDefinitionCache

type NoopECSPodDefinitionCache struct{}

NoopECSPodDefinitionCache is an implementation of cocoa.ECSPodDefinitionCache that no-ops for all operations.

func (*NoopECSPodDefinitionCache) Delete

Delete is a no-op.

func (*NoopECSPodDefinitionCache) Put

Put is a no-op.

type NoopSecretCache

type NoopSecretCache struct {
	Tag string
}

NoopSecretCache is an implementation of cocoa.SecretCache that no-ops for all operations.

func (*NoopSecretCache) Delete

Delete is a no-op.

func (*NoopSecretCache) GetTag

func (c *NoopSecretCache) GetTag() string

GetTag returns the tag field.

func (*NoopSecretCache) Put

Put is a no-op.

type ProviderSettings

type ProviderSettings interface {
	Validate() error

	// If zone is specified, returns the provider settings for that region.
	// This is currently only being implemented for EC2 hosts.
	FromDistroSettings(distro.Distro, string) error
}

ProviderSettings exposes provider-specific configuration settings for a Manager.

func GetSettings

func GetSettings(provider string) (ProviderSettings, error)

GetSettings returns an uninitialized ProviderSettings based on the given provider.

type STSManager

type STSManager interface {
	// AssumeRole gets the credentials for a role as the given task.
	AssumeRole(ctx context.Context, taskID string, opts AssumeRoleOptions) (AssumeRoleCredentials, error)
}

STSManager is an interface which handles STS operations. It's main purpose is to expose a friendly API for our own API server.

func GetSTSManager

func GetSTSManager(mock bool) STSManager

GetSTSManager returns either a real or mock STSManager.

type SpawnOptions

type SpawnOptions struct {
	DistroId              string
	Userdata              string
	UserName              string
	PublicKey             string
	ProvisionOptions      *host.ProvisionOptions
	UseProjectSetupScript bool
	InstanceTags          []host.Tag
	InstanceType          string
	Region                string
	NoExpiration          bool
	host.SleepScheduleOptions
	IsVirtualWorkstation bool
	IsCluster            bool
	HomeVolumeSize       int
	HomeVolumeID         string
	Expiration           *time.Time
}

Options holds the required parameters for spawning a host.

type StaticHost

type StaticHost struct {
	Name    string `bson:"name" json:"name" mapstructure:"name"`
	SSHPort int    `bson:"ssh_port,omitempty" json:"ssh_port,omitempty" mapstructure:"ssh_port,omitempty"`
}

type StaticSettings

type StaticSettings struct {
	Hosts []StaticHost `mapstructure:"hosts" json:"hosts" bson:"hosts"`
}

func (*StaticSettings) FromDistroSettings

func (s *StaticSettings) FromDistroSettings(d distro.Distro, _ string) error

func (*StaticSettings) Validate

func (s *StaticSettings) Validate() error

Validate checks that the settings from the configuration are valid.

type VolumeAttachment

type VolumeAttachment struct {
	VolumeID   string
	HostID     string
	DeviceName string
}

VolumeAttachment contains information about a volume attached to a host.

Directories

Path Synopsis
Package parameterstore provides interfaces to interact with parameters (including sensitive secrets) stored in AWS Systems Manager Parameter Store.
Package parameterstore provides interfaces to interact with parameters (including sensitive secrets) stored in AWS Systems Manager Parameter Store.
fakeparameter
Package fakeparameter contains the data model and helpers for testing code that uses Parameter Store.
Package fakeparameter contains the data model and helpers for testing code that uses Parameter Store.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL