aws

package
v0.0.0-...-3d4b6db Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheDefaultTTL                   time.Duration = 0 * time.Second
	DescribeWarmPoolTTL               time.Duration = 60 * time.Second
	DescribeAutoScalingGroupsTTL      time.Duration = 60 * time.Second
	DescribeLaunchConfigurationsTTL   time.Duration = 60 * time.Second
	ListAttachedRolePoliciesTTL       time.Duration = 60 * time.Second
	GetRoleTTL                        time.Duration = 60 * time.Second
	GetInstanceProfileTTL             time.Duration = 60 * time.Second
	DescribeNodegroupTTL              time.Duration = 60 * time.Second
	DescribeLifecycleHooksTTL         time.Duration = 180 * time.Second
	DescribeClusterTTL                time.Duration = 180 * time.Second
	DescribeSecurityGroupsTTL         time.Duration = 180 * time.Second
	DescribeSubnetsTTL                time.Duration = 180 * time.Second
	DescribeLaunchTemplatesTTL        time.Duration = 60 * time.Second
	DescribeLaunchTemplateVersionsTTL time.Duration = 60 * time.Second
	DescribeInstanceTypesTTL          time.Duration = 24 * time.Hour
	DescribeInstanceTypeOfferingTTL   time.Duration = 1 * time.Hour
	GetParameterTTL                   time.Duration = 1 * time.Hour

	CacheBackgroundPruningInterval time.Duration = 1 * time.Hour
	CacheMaxItems                  int64         = 250
	CacheItemsToPrune              uint32        = 25

	LaunchTemplateStrategyCapacityOptimized = "capacity-optimized"
	LaunchTemplateStrategyLowestPrice       = "lowest-price"
	LaunchTemplateAllocationStrategy        = "prioritized"
	LaunchTemplateLatestVersionKey          = "$Latest"
	IAMPolicyPrefix                         = "arn:aws:iam::aws:policy"
	LaunchConfigurationNotFoundErrorMessage = "Launch configuration name not found"
)
View Source
const (
	EksOptimisedAmiPath           = "/aws/service/eks/optimized-ami/%s/amazon-linux-2/%s/image_id"
	EksOptimisedAmazonLinux2Arm64 = "/aws/service/eks/optimized-ami/%s/amazon-linux-2-arm64/%s/image_id"
	EksOptimisedBottlerocket      = "/aws/service/bottlerocket/aws-k8s-%s/x86_64/%s/image_id"
	EksOptimisedBottlerocketArm64 = "/aws/service/bottlerocket/aws-k8s-%s/arm64/%s/image_id"
	EksOptimisedWindowsCore       = "/aws/service/ami-windows-%s/Windows_Server-2019-English-Core-EKS_Optimized-%s/image_id"
	EksOptimisedWindowsFull       = "/aws/service/ami-windows-%s/Windows_Server-2019-English-Full-EKS_Optimized-%s/image_id"
)

Variables

View Source
var (
	DefaultInstanceProfilePropagationDelay = time.Second * 35
	DefaultWaiterDuration                  = time.Second * 5
	DefaultWaiterRetries                   = 12

	DefaultSuspendProcesses = []string{
		"Launch",
		"Terminate",
		"AddToLoadBalancer",
		"AlarmNotification",
		"AZRebalance",
		"HealthCheck",
		"InstanceRefresh",
		"ReplaceUnhealthy",
		"ScheduledActions",
	}

	DefaultAutoscalingMetrics = []string{
		"GroupMinSize",
		"GroupMaxSize",
		"GroupDesiredCapacity",
		"GroupInServiceInstances",
		"GroupPendingInstances",
		"GroupStandbyInstances",
		"GroupTerminatingInstances",
		"GroupInServiceCapacity",
		"GroupPendingCapacity",
		"GroupTerminatingCapacity",
		"GroupStandbyCapacity",
		"GroupTotalInstances",
		"GroupTotalCapacity",
	}

	ConfigurationAllowedVolumeTypes             = []string{"gp2", "io1", "sc1", "st1"}
	TemplateAllowedVolumeTypes                  = []string{"gp2", "gp3", "io1", "io2", "sc1", "st1"}
	AllowedVolumeTypesWithProvisionedIOPS       = []string{"io1", "io2", "gp3"}
	AllowedVolumeTypesWithProvisionedThroughput = []string{"gp3"}
	LifecycleHookTransitionLaunch               = "autoscaling:EC2_INSTANCE_LAUNCHING"
	LifecycleHookTransitionTerminate            = "autoscaling:EC2_INSTANCE_TERMINATING"
)
View Source
var (
	EksAmis = map[string]architectureMap{
		"amazonlinux2": architectureMap{
			"x86_64": EksOptimisedAmiPath,
			"arm64":  EksOptimisedAmazonLinux2Arm64,
		},
		"bottlerocket": architectureMap{
			"x86_64": EksOptimisedBottlerocket,
			"arm64":  EksOptimisedBottlerocketArm64,
		},
		"windows": architectureMap{
			"x86_64": EksOptimisedWindowsCore,
		},
	}
	LatestIdentifiers = map[string]string{
		"bottlerocket": "latest",
		"amazonlinux2": "recommended",
		"windows":      "latest",
	}
)
View Source
var DefaultRetryer = client.DefaultRetryer{
	NumMaxRetries:    12,
	MinThrottleDelay: time.Second * 5,
	MaxThrottleDelay: time.Second * 60,
	MinRetryDelay:    time.Second * 1,
	MaxRetryDelay:    time.Second * 5,
}
View Source
var FiniteDeleted = CloudResourceReconcileState{FiniteDeleted: true}
View Source
var FiniteState = CloudResourceReconcileState{FiniteState: true}
View Source
var ManagedNodeGroupFiniteState = ManagedNodeGroupReconcileState{FiniteState: true}
View Source
var ManagedNodeGroupOngoingState = ManagedNodeGroupReconcileState{OngoingState: true}
View Source
var ManagedNodeGroupUnrecoverableDeleteError = ManagedNodeGroupReconcileState{UnrecoverableDeleteError: true}
View Source
var ManagedNodeGroupUnrecoverableError = ManagedNodeGroupReconcileState{UnrecoverableError: true}
View Source
var OngoingState = CloudResourceReconcileState{OngoingState: true}
View Source
var UnrecoverableDeleteError = CloudResourceReconcileState{UnrecoverableDeleteError: true}
View Source
var UnrecoverableError = CloudResourceReconcileState{UnrecoverableError: true}
View Source
var UpdateRecoverableError = CloudResourceReconcileState{UpdateRecoverableError: true}

Functions

func GetAwsAsgClient

func GetAwsAsgClient(region string, cacheCfg *cache.Config, maxRetries int, collector *common.MetricsCollector) autoscalingiface.AutoScalingAPI

GetAwsAsgClient returns an ASG client

func GetAwsEc2Client

func GetAwsEc2Client(region string, cacheCfg *cache.Config, maxRetries int, collector *common.MetricsCollector) ec2iface.EC2API

GetAwsEc2Client returns an EC2 client

func GetAwsEc2MetadataClient

func GetAwsEc2MetadataClient() *ec2metadata.EC2Metadata

func GetAwsEksClient

func GetAwsEksClient(region string, cacheCfg *cache.Config, maxRetries int, collector *common.MetricsCollector) eksiface.EKSAPI

GetAwsEksClient returns an EKS client

func GetAwsIamClient

func GetAwsIamClient(region string, cacheCfg *cache.Config, maxRetries int, collector *common.MetricsCollector) iamiface.IAMAPI

GetAwsIAMClient returns an IAM client

func GetAwsSsmClient

func GetAwsSsmClient(region string, cacheCfg *cache.Config, maxRetries int, collector *common.MetricsCollector) ssmiface.SSMAPI

func GetInstanceArchitectures

func GetInstanceArchitectures(typeInfo []*ec2.InstanceTypeInfo, instanceType string) []string

func GetInstanceFamily

func GetInstanceFamily(instanceType string) string

func GetInstanceGeneration

func GetInstanceGeneration(instanceType string) string

func GetInstanceTypeArchitectures

func GetInstanceTypeArchitectures(instanceTypes []*ec2.InstanceTypeInfo, instanceType string) []string

func GetInstanceTypeInfo

func GetInstanceTypeInfo(instanceTypes []*ec2.InstanceTypeInfo, instanceType string) *ec2.InstanceTypeInfo

func GetInstanceTypeNetworkInfo

func GetInstanceTypeNetworkInfo(instanceTypes []*ec2.InstanceTypeInfo, instanceType string) *ec2.NetworkInfo

func GetOfferingMemory

func GetOfferingMemory(typeInfo []*ec2.InstanceTypeInfo, instanceType string) int64

func GetOfferingVCPU

func GetOfferingVCPU(typeInfo []*ec2.InstanceTypeInfo, instanceType string) int64

func GetRegion

func GetRegion(metadata *ec2metadata.EC2Metadata) (string, error)

func GetScalingConfigName

func GetScalingConfigName(group *autoscaling.Group) string

func GetScalingGroupTagsByName

func GetScalingGroupTagsByName(name string, client autoscalingiface.AutoScalingAPI) ([]*autoscaling.TagDescription, error)

func GetTagValueByKey

func GetTagValueByKey(tags []*autoscaling.TagDescription, key string) string

func IsNodeGroupInConditionState

func IsNodeGroupInConditionState(key string, condition string) bool

func IsProfileInConditionState

func IsProfileInConditionState(key string, condition string) bool

func IsUsingLaunchConfiguration

func IsUsingLaunchConfiguration(group *autoscaling.Group) bool

func IsUsingLaunchTemplate

func IsUsingLaunchTemplate(group *autoscaling.Group) bool

func IsUsingMixedInstances

func IsUsingMixedInstances(group *autoscaling.Group) bool

func IsUsingWarmPool

func IsUsingWarmPool(group *autoscaling.Group) bool

Types

type AwsWorker

type AwsWorker struct {
	AsgClient   autoscalingiface.AutoScalingAPI
	EksClient   eksiface.EKSAPI
	IamClient   iamiface.IAMAPI
	Ec2Client   ec2iface.EC2API
	SsmClient   ssmiface.SSMAPI
	Ec2Metadata *ec2metadata.EC2Metadata
	Parameters  map[string]interface{}
}

func (*AwsWorker) AttachDefaultPolicyToDefaultRole

func (w *AwsWorker) AttachDefaultPolicyToDefaultRole() error

func (*AwsWorker) AttachManagedPolicies

func (w *AwsWorker) AttachManagedPolicies(name string, managedPolicies []string) error

func (*AwsWorker) CreateDefaultFargateRole

func (w *AwsWorker) CreateDefaultFargateRole() error

func (*AwsWorker) CreateFargateProfile

func (w *AwsWorker) CreateFargateProfile(arn string) error

func (*AwsWorker) CreateLaunchConfig

func (w *AwsWorker) CreateLaunchConfig(input *autoscaling.CreateLaunchConfigurationInput) error

func (*AwsWorker) CreateLaunchTemplate

func (w *AwsWorker) CreateLaunchTemplate(input *ec2.CreateLaunchTemplateInput) error

func (*AwsWorker) CreateLaunchTemplateVersion

func (w *AwsWorker) CreateLaunchTemplateVersion(input *ec2.CreateLaunchTemplateVersionInput) (*ec2.LaunchTemplateVersion, error)

func (*AwsWorker) CreateLifecycleHook

func (w *AwsWorker) CreateLifecycleHook(input *autoscaling.PutLifecycleHookInput) error

func (*AwsWorker) CreateManagedNodeGroup

func (w *AwsWorker) CreateManagedNodeGroup() error

func (*AwsWorker) CreateScalingGroup

func (w *AwsWorker) CreateScalingGroup(input *autoscaling.CreateAutoScalingGroupInput) error

func (*AwsWorker) CreateScalingGroupRole

func (w *AwsWorker) CreateScalingGroupRole(name string) (*iam.Role, *iam.InstanceProfile, error)

func (*AwsWorker) DeleteDefaultFargateRole

func (w *AwsWorker) DeleteDefaultFargateRole() error

func (*AwsWorker) DeleteFargateProfile

func (w *AwsWorker) DeleteFargateProfile() error

func (*AwsWorker) DeleteLaunchConfig

func (w *AwsWorker) DeleteLaunchConfig(name string) error

func (*AwsWorker) DeleteLaunchTemplate

func (w *AwsWorker) DeleteLaunchTemplate(name string) error

func (*AwsWorker) DeleteLaunchTemplateVersions

func (w *AwsWorker) DeleteLaunchTemplateVersions(name string, versions []string) error

func (*AwsWorker) DeleteLifecycleHook

func (w *AwsWorker) DeleteLifecycleHook(asgName, hookName string) error

func (*AwsWorker) DeleteManagedNodeGroup

func (w *AwsWorker) DeleteManagedNodeGroup() error

func (*AwsWorker) DeleteScalingGroup

func (w *AwsWorker) DeleteScalingGroup(name string) error

func (*AwsWorker) DeleteScalingGroupRole

func (w *AwsWorker) DeleteScalingGroupRole(name string, managedPolicies []string) error

func (*AwsWorker) DeleteWarmPool

func (w *AwsWorker) DeleteWarmPool(asgName string) error

func (*AwsWorker) DeriveEksVpcID

func (w *AwsWorker) DeriveEksVpcID(clusterName string) (string, error)

func (*AwsWorker) DescribeAutoscalingGroups

func (w *AwsWorker) DescribeAutoscalingGroups() ([]*autoscaling.Group, error)

func (*AwsWorker) DescribeAutoscalingLaunchConfigs

func (w *AwsWorker) DescribeAutoscalingLaunchConfigs() ([]*autoscaling.LaunchConfiguration, error)

func (*AwsWorker) DescribeEKSCluster

func (w *AwsWorker) DescribeEKSCluster(clusterName string) (*eks.Cluster, error)

func (*AwsWorker) DescribeFargateProfile

func (w *AwsWorker) DescribeFargateProfile() (*eks.FargateProfile, error)

func (*AwsWorker) DescribeInstanceOfferings

func (w *AwsWorker) DescribeInstanceOfferings() ([]*ec2.InstanceTypeOffering, error)

func (*AwsWorker) DescribeInstanceTypes

func (w *AwsWorker) DescribeInstanceTypes() ([]*ec2.InstanceTypeInfo, error)

func (*AwsWorker) DescribeLaunchTemplateVersions

func (w *AwsWorker) DescribeLaunchTemplateVersions(templateName string) ([]*ec2.LaunchTemplateVersion, error)

func (*AwsWorker) DescribeLaunchTemplates

func (w *AwsWorker) DescribeLaunchTemplates() ([]*ec2.LaunchTemplate, error)

func (*AwsWorker) DescribeLifecycleHooks

func (w *AwsWorker) DescribeLifecycleHooks(asgName string) ([]*autoscaling.LifecycleHook, error)

func (*AwsWorker) DescribeWarmPool

func (w *AwsWorker) DescribeWarmPool(asgName string) (*autoscaling.DescribeWarmPoolOutput, error)

func (*AwsWorker) DetachDefaultPolicyFromDefaultRole

func (w *AwsWorker) DetachDefaultPolicyFromDefaultRole() error

func (*AwsWorker) DetachManagedPolicies

func (w *AwsWorker) DetachManagedPolicies(name string, managedPolicies []string) error

func (*AwsWorker) DisableMetrics

func (w *AwsWorker) DisableMetrics(asgName string, metrics []string) error

func (*AwsWorker) EnableMetrics

func (w *AwsWorker) EnableMetrics(asgName string, metrics []string) error

func (*AwsWorker) GetAutoScalingBasicBlockDevice

func (w *AwsWorker) GetAutoScalingBasicBlockDevice(name, volType, snapshot string, volSize, iops int64, throughput int64, delete, encrypt *bool) *autoscaling.BlockDeviceMapping

func (*AwsWorker) GetDNSClusterIP

func (w *AwsWorker) GetDNSClusterIP(cluster *eks.Cluster) string

func (*AwsWorker) GetDefaultFargateRole

func (w *AwsWorker) GetDefaultFargateRole() (*iam.Role, error)

func (*AwsWorker) GetEksLatestAmi

func (w *AwsWorker) GetEksLatestAmi(OSFamily string, arch string, kubernetesVersion string) (string, error)

func (*AwsWorker) GetEksSsmAmi

func (w *AwsWorker) GetEksSsmAmi(OSFamily string, arch string, kubernetesVersion string, ssmId string) (string, error)

func (*AwsWorker) GetLabelsUpdatePayload

func (w *AwsWorker) GetLabelsUpdatePayload(existing, new map[string]string) (*eks.UpdateLabelsPayload, bool)

func (*AwsWorker) GetLaunchTemplateBlockDevice

func (w *AwsWorker) GetLaunchTemplateBlockDevice(name, volType, snapshot string, volSize, iops int64, throughput int64, delete, encrypt *bool) *ec2.LaunchTemplateBlockDeviceMapping

func (*AwsWorker) GetLaunchTemplateBlockDeviceRequest

func (w *AwsWorker) GetLaunchTemplateBlockDeviceRequest(name, volType, snapshot string, volSize, iops int64, throughput int64, delete, encrypt *bool) *ec2.LaunchTemplateBlockDeviceMappingRequest

func (*AwsWorker) GetRole

func (w *AwsWorker) GetRole(roleName string) (*iam.Role, error)

func (*AwsWorker) GetSelfNodeGroup

func (w *AwsWorker) GetSelfNodeGroup() (error, *eks.Nodegroup)

TODO: Rename - GetNodeGroup

func (*AwsWorker) InstanceProfileExist

func (w *AwsWorker) InstanceProfileExist(name string) (*iam.InstanceProfile, bool)

func (*AwsWorker) IsNodeGroupExist

func (w *AwsWorker) IsNodeGroupExist() bool

TODO: Move logic to provisioner

func (*AwsWorker) LaunchTemplateLicenseConfiguration

func (w *AwsWorker) LaunchTemplateLicenseConfiguration(input []string) []*ec2.LaunchTemplateLicenseConfiguration

func (*AwsWorker) LaunchTemplateLicenseConfigurationRequest

func (w *AwsWorker) LaunchTemplateLicenseConfigurationRequest(input []string) []*ec2.LaunchTemplateLicenseConfigurationRequest

func (*AwsWorker) LaunchTemplatePlacement

func (w *AwsWorker) LaunchTemplatePlacement(availabilityZone, hostResourceGroupArn, tenancy string) *ec2.LaunchTemplatePlacement

func (*AwsWorker) LaunchTemplatePlacementRequest

func (w *AwsWorker) LaunchTemplatePlacementRequest(availabilityZone, hostResourceGroupArn, tenancy string) *ec2.LaunchTemplatePlacementRequest

func (*AwsWorker) ListRolePolicies

func (w *AwsWorker) ListRolePolicies(name string) ([]*iam.AttachedPolicy, error)

func (*AwsWorker) NewTag

func (w *AwsWorker) NewTag(key, val, resource string) *autoscaling.Tag

func (*AwsWorker) RoleExist

func (w *AwsWorker) RoleExist(name string) (*iam.Role, bool)

func (*AwsWorker) SecurityGroupByName

func (w *AwsWorker) SecurityGroupByName(name, vpc string) (*ec2.SecurityGroup, error)

func (*AwsWorker) SetResumeProcesses

func (w *AwsWorker) SetResumeProcesses(name string, processesToResume []string) error

func (*AwsWorker) SetSuspendProcesses

func (w *AwsWorker) SetSuspendProcesses(name string, processesToSuspend []string) error

func (*AwsWorker) SubnetByName

func (w *AwsWorker) SubnetByName(name, vpc string) (*ec2.Subnet, error)

func (*AwsWorker) TerminateScalingInstances

func (w *AwsWorker) TerminateScalingInstances(instanceIds []string) error

func (*AwsWorker) UpdateLaunchTemplateDefaultVersion

func (w *AwsWorker) UpdateLaunchTemplateDefaultVersion(name, defaultVersion string) (*ec2.LaunchTemplate, error)

func (*AwsWorker) UpdateManagedNodeGroup

func (w *AwsWorker) UpdateManagedNodeGroup(nodeGroup *eks.Nodegroup, desired int64, nodeLabels map[string]string) error

func (*AwsWorker) UpdateScalingGroup

func (w *AwsWorker) UpdateScalingGroup(input *autoscaling.UpdateAutoScalingGroupInput) error

func (*AwsWorker) UpdateScalingGroupTags

func (w *AwsWorker) UpdateScalingGroupTags(add []*autoscaling.Tag, remove []*autoscaling.Tag) error

func (*AwsWorker) UpdateWarmPool

func (w *AwsWorker) UpdateWarmPool(asgName string, min, max int64) error

func (*AwsWorker) WithRetries

func (w *AwsWorker) WithRetries(f func() bool) error

type CloudResourceReconcileState

type CloudResourceReconcileState struct {
	OngoingState             bool
	FiniteState              bool
	FiniteDeleted            bool
	UpdateRecoverableError   bool
	UnrecoverableError       bool
	UnrecoverableDeleteError bool
}

type ManagedNodeGroupReconcileState

type ManagedNodeGroupReconcileState struct {
	OngoingState             bool
	FiniteState              bool
	UnrecoverableError       bool
	UnrecoverableDeleteError bool
}

type RetryLogger

type RetryLogger struct {
	client.DefaultRetryer
	// contains filtered or unexported fields
}

func NewRetryLogger

func NewRetryLogger(maxRetries int, metrics *common.MetricsCollector) *RetryLogger

func (RetryLogger) RetryRules

func (l RetryLogger) RetryRules(r *request.Request) time.Duration

Jump to

Keyboard shortcuts

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