Documentation ¶
Overview ¶
Package ec2 provides a way to interact with the AWS EC2 API.
Index ¶
- Constants
- Variables
- func DefaultAMILookup(ec2Client ec2iface.EC2API, ...) (*ec2.Image, error)
- func GenerateAmiName(amiNameFormat, baseOS, kubernetesVersion string) (string, error)
- func GetLatestImage(imgs []*ec2.Image) (*ec2.Image, error)
- func MachinePoolAnnotationJSON(lts scope.LaunchTemplateScope, annotation string) (map[string]interface{}, error)
- func UpdateMachinePoolAnnotationJSON(lts scope.LaunchTemplateScope, annotation string, ...) error
- type AMILookup
- type Service
- func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, userDataFormat string) (*infrav1.Instance, error)
- func (s *Service) CreateLaunchTemplate(scope scope.LaunchTemplateScope, imageID *string, ...) (string, error)
- func (s *Service) CreateLaunchTemplateVersion(id string, scope scope.LaunchTemplateScope, imageID *string, ...) error
- func (s *Service) DeleteBastion() error
- func (s *Service) DeleteLaunchTemplate(id string) error
- func (s *Service) DetachSecurityGroupsFromNetworkInterface(groups []string, interfaceID string) error
- func (s *Service) DiscoverLaunchTemplateAMI(scope scope.LaunchTemplateScope) (*string, error)
- func (s *Service) GetAdditionalSecurityGroupsIDs(securityGroups []infrav1.AWSResourceReference) ([]string, error)
- func (s *Service) GetCoreNodeSecurityGroups(scope scope.LaunchTemplateScope) ([]string, error)
- func (s *Service) GetCoreSecurityGroups(scope *scope.MachineScope) ([]string, error)
- func (s *Service) GetDHCPOptionSetDomainName(ec2client ec2iface.EC2API, vpcID *string) *string
- func (s *Service) GetInstanceSecurityGroups(instanceID string) (map[string][]string, error)
- func (s *Service) GetLaunchTemplate(launchTemplateName string) (*expinfrav1.AWSLaunchTemplate, string, *apimachinerytypes.NamespacedName, ...)
- func (s *Service) GetLaunchTemplateID(launchTemplateName string) (string, error)
- func (s *Service) GetLaunchTemplateLatestVersion(id string) (string, error)
- func (s *Service) GetRunningInstanceByTags(scope *scope.MachineScope) (*infrav1.Instance, error)
- func (s *Service) InstanceIfExists(id *string) (*infrav1.Instance, error)
- func (s *Service) LaunchTemplateNeedsUpdate(scope scope.LaunchTemplateScope, incoming *expinfrav1.AWSLaunchTemplate, ...) (bool, error)
- func (s *Service) ModifyInstanceMetadataOptions(instanceID string, options *infrav1.InstanceMetadataOptions) error
- func (s *Service) PruneLaunchTemplateVersions(id string) error
- func (s *Service) ReconcileBastion() error
- func (s *Service) ReconcileElasticIPFromPublicPool(pool *infrav1.ElasticIPPool, instance *infrav1.Instance) (bool, error)
- func (s *Service) ReconcileLaunchTemplate(scope scope.LaunchTemplateScope, ec2svc services.EC2Interface, ...) error
- func (s *Service) ReconcileTags(scope scope.LaunchTemplateScope, ...) error
- func (s *Service) ReleaseElasticIP(instanceID string) error
- func (s *Service) SDKToInstance(v *ec2.Instance) (*infrav1.Instance, error)
- func (s *Service) SDKToLaunchTemplate(d *ec2.LaunchTemplateVersion) (*expinfrav1.AWSLaunchTemplate, string, *apimachinerytypes.NamespacedName, ...)
- func (s *Service) TerminateInstance(instanceID string) error
- func (s *Service) TerminateInstanceAndWait(instanceID string) error
- func (s *Service) UpdateInstanceSecurityGroups(instanceID string, ids []string) error
- func (s *Service) UpdateResourceTags(resourceID *string, create, remove map[string]string) error
Constants ¶
const ( // DefaultArchitectureTag is the default architecture used when the architcture can't be determined from instance type. DefaultArchitectureTag = Amd64ArchitectureTag // Amd64ArchitectureTag is the reference AWS uses for amd64 architecture images. Amd64ArchitectureTag = "x86_64" // Arm64ArchitectureTag is the reference AWS uses for arm64 architecture images. Arm64ArchitectureTag = "arm64" // DefaultMachineAMIOwnerID is a CNCF owned account. This was previously a VMWare owned account // but the project lost access to it. See the k8s.io repo for the infra definition. DefaultMachineAMIOwnerID = "819546954734" // DefaultAmiNameFormat is defined in the build/ directory of this project. // The pattern is: // 1. the string value `capa-ami-` // 2. the baseOS of the AMI, for example: ubuntu-24.04, centos-7, amazon-2 // 3. the kubernetes version as defined by the packages produced by kubernetes/release with or without v as a prefix, for example: 1.13.0, 1.12.5-mybuild.1, v1.17.3 // 4. a `-` followed by any additional characters. DefaultAmiNameFormat = "capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*" )
const ( // TagsLastAppliedAnnotation is the key for the AWSMachinePool object annotation // which tracks the tags that the AWSMachinePool actuator is responsible // for. These are the tags that have been handled by the // AdditionalTags in the AWSMachinePool Provider Config. // See https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ // for annotation formatting rules. TagsLastAppliedAnnotation = "sigs.k8s.io/cluster-api-provider-aws-last-applied-tags" )
Variables ¶
var ( // ErrInstanceNotFoundByID defines an error for when the instance with the provided provider ID is missing. ErrInstanceNotFoundByID = errors.New("failed to find instance by id") // ErrDescribeInstance defines an error for when AWS SDK returns error when describing instances. ErrDescribeInstance = errors.New("failed to describe instance by id") )
Functions ¶
func DefaultAMILookup ¶
func DefaultAMILookup(ec2Client ec2iface.EC2API, ownerID, baseOS, kubernetesVersion, architecture, amiNameFormat string) (*ec2.Image, error)
DefaultAMILookup will do a default AMI lookup.
func GenerateAmiName ¶
GenerateAmiName will generate an AMI name.
func GetLatestImage ¶
GetLatestImage assumes imgs is not empty. Responsibility of the caller to check.
func MachinePoolAnnotationJSON ¶
func MachinePoolAnnotationJSON(lts scope.LaunchTemplateScope, annotation string) (map[string]interface{}, error)
MachinePoolAnnotationJSON returns the annotation's json value as a map.
func UpdateMachinePoolAnnotationJSON ¶
func UpdateMachinePoolAnnotationJSON(lts scope.LaunchTemplateScope, annotation string, content map[string]interface{}) error
UpdateMachinePoolAnnotationJSON updates the annotation with the given content.
Types ¶
type Service ¶
type Service struct { EC2Client ec2iface.EC2API // SSMClient is used to look up the official EKS AMI ID SSMClient ssmiface.SSMAPI // contains filtered or unexported fields }
Service holds a collection of interfaces. The interfaces are broken down like this to group functions together. One alternative is to have a large list of functions from the ec2 client.
func NewService ¶
NewService returns a new service given the ec2 api client.
func (*Service) CreateInstance ¶
func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, userDataFormat string) (*infrav1.Instance, error)
CreateInstance runs an ec2 instance.
func (*Service) CreateLaunchTemplate ¶
func (s *Service) CreateLaunchTemplate(scope scope.LaunchTemplateScope, imageID *string, userDataSecretKey apimachinerytypes.NamespacedName, userData []byte) (string, error)
CreateLaunchTemplate generates a launch template to be used with the autoscaling group.
func (*Service) CreateLaunchTemplateVersion ¶
func (s *Service) CreateLaunchTemplateVersion(id string, scope scope.LaunchTemplateScope, imageID *string, userDataSecretKey apimachinerytypes.NamespacedName, userData []byte) error
CreateLaunchTemplateVersion will create a launch template.
func (*Service) DeleteBastion ¶
DeleteBastion deletes the Bastion instance.
func (*Service) DeleteLaunchTemplate ¶
DeleteLaunchTemplate delete a launch template.
func (*Service) DetachSecurityGroupsFromNetworkInterface ¶
func (s *Service) DetachSecurityGroupsFromNetworkInterface(groups []string, interfaceID string) error
DetachSecurityGroupsFromNetworkInterface looks up an ENI by interfaceID and detaches a list of Security Groups from that ENI.
func (*Service) DiscoverLaunchTemplateAMI ¶
func (s *Service) DiscoverLaunchTemplateAMI(scope scope.LaunchTemplateScope) (*string, error)
DiscoverLaunchTemplateAMI will discover the AMI launch template.
func (*Service) GetAdditionalSecurityGroupsIDs ¶
func (s *Service) GetAdditionalSecurityGroupsIDs(securityGroups []infrav1.AWSResourceReference) ([]string, error)
GetAdditionalSecurityGroupsIDs returns the security group IDs for the additional security groups.
func (*Service) GetCoreNodeSecurityGroups ¶
func (s *Service) GetCoreNodeSecurityGroups(scope scope.LaunchTemplateScope) ([]string, error)
GetCoreNodeSecurityGroups looks up the security group IDs managed by this actuator They are considered "core" to its proper functioning.
func (*Service) GetCoreSecurityGroups ¶
func (s *Service) GetCoreSecurityGroups(scope *scope.MachineScope) ([]string, error)
GetCoreSecurityGroups looks up the security group IDs managed by this actuator They are considered "core" to its proper functioning.
func (*Service) GetDHCPOptionSetDomainName ¶ added in v2.4.2
GetDHCPOptionSetDomainName returns the domain DNS name for the VPC from the DHCP Options.
func (*Service) GetInstanceSecurityGroups ¶
GetInstanceSecurityGroups returns a map from ENI id to the security groups applied to that ENI While some security group operations take place at the "instance" level, these are in fact an API convenience for manipulating the first ("primary") ENI's properties.
func (*Service) GetLaunchTemplate ¶
func (s *Service) GetLaunchTemplate(launchTemplateName string) (*expinfrav1.AWSLaunchTemplate, string, *apimachinerytypes.NamespacedName, error)
GetLaunchTemplate returns the existing LaunchTemplate or nothing if it doesn't exist. For now by name until we need the input to be something different.
func (*Service) GetLaunchTemplateID ¶
GetLaunchTemplateID returns the existing LaunchTemplateId or empty string if it doesn't exist.
func (*Service) GetLaunchTemplateLatestVersion ¶
GetLaunchTemplateLatestVersion returns the latest version of a launch template.
func (*Service) GetRunningInstanceByTags ¶
GetRunningInstanceByTags returns the existing instance or nothing if it doesn't exist.
func (*Service) InstanceIfExists ¶
InstanceIfExists returns the existing instance by id and errors if it cannot find the instance(ErrInstanceNotFoundByID) or API call fails (ErrDescribeInstance). Returns empty instance with nil error, only when providerID is nil.
func (*Service) LaunchTemplateNeedsUpdate ¶
func (s *Service) LaunchTemplateNeedsUpdate(scope scope.LaunchTemplateScope, incoming *expinfrav1.AWSLaunchTemplate, existing *expinfrav1.AWSLaunchTemplate) (bool, error)
LaunchTemplateNeedsUpdate checks if a new launch template version is needed.
FIXME(dlipovetsky): This check should account for changed userdata, but does not yet do so. Although userdata is stored in an EC2 Launch Template, it is not a field of AWSLaunchTemplate.
func (*Service) ModifyInstanceMetadataOptions ¶ added in v2.1.0
func (s *Service) ModifyInstanceMetadataOptions(instanceID string, options *infrav1.InstanceMetadataOptions) error
ModifyInstanceMetadataOptions modifies the metadata options of the given EC2 instance.
func (*Service) PruneLaunchTemplateVersions ¶
PruneLaunchTemplateVersions deletes one old launch template version. It does not delete the "latest" version, because that version may still be in use. It does not delete the "default" version, because that version cannot be deleted. It does not assume that versions are sequential. Versions may be deleted out of band.
func (*Service) ReconcileBastion ¶
ReconcileBastion ensures a bastion is created for the cluster.
func (*Service) ReconcileElasticIPFromPublicPool ¶ added in v2.5.1
func (s *Service) ReconcileElasticIPFromPublicPool(pool *infrav1.ElasticIPPool, instance *infrav1.Instance) (bool, error)
ReconcileElasticIPFromPublicPool reconciles the elastic IP from a custom Public IPv4 Pool.
func (*Service) ReconcileLaunchTemplate ¶
func (s *Service) ReconcileLaunchTemplate( scope scope.LaunchTemplateScope, ec2svc services.EC2Interface, canUpdateLaunchTemplate func() (bool, error), runPostLaunchTemplateUpdateOperation func() error, ) error
ReconcileLaunchTemplate reconciles a launch template and triggers instance refresh conditionally, depending on changes.
func (*Service) ReconcileTags ¶
func (s *Service) ReconcileTags(scope scope.LaunchTemplateScope, resourceServicesToUpdate []scope.ResourceServiceToUpdate) error
ReconcileTags reconciles the tags for the AWSMachinePool instances.
func (*Service) ReleaseElasticIP ¶ added in v2.5.1
ReleaseElasticIP releases a specific Elastic IP based on the instance role.
func (*Service) SDKToInstance ¶
SDKToInstance converts an AWS EC2 SDK instance to the CAPA instance type. SDKToInstance populates all instance fields except for rootVolumeSize, because EC2.DescribeInstances does not return the size of storage devices. An additional call to EC2 is required to get this value.
func (*Service) SDKToLaunchTemplate ¶
func (s *Service) SDKToLaunchTemplate(d *ec2.LaunchTemplateVersion) (*expinfrav1.AWSLaunchTemplate, string, *apimachinerytypes.NamespacedName, error)
SDKToLaunchTemplate converts an AWS EC2 SDK instance to the CAPA instance type.
func (*Service) TerminateInstance ¶
TerminateInstance terminates an EC2 instance. Returns nil on success, error in all other cases.
func (*Service) TerminateInstanceAndWait ¶
TerminateInstanceAndWait terminates and waits for an EC2 instance to terminate.
func (*Service) UpdateInstanceSecurityGroups ¶
UpdateInstanceSecurityGroups modifies the security groups of the given EC2 instance.
func (*Service) UpdateResourceTags ¶
UpdateResourceTags updates the tags for an instance. This will be called if there is anything to create (update) or delete. We may not always have to perform each action, so we check what we're receiving to avoid calling AWS if we don't need to.