Documentation ¶
Overview ¶
package aws implements autoscaling integration for AWS cloud provider
Design ------
+-------------------------+ +--------------------------+ | | | | | | | | | Gravity Master Node | | Auto Scaling Group +---------------------------------+ | | | | | | | | | | ++-----+------------------+ +--------------------------+ | | | +---------------+ | | | | | | | | Publish Gravity ELB address | | | | | Publish Encrypted Join Token | AWS Instance | |
Read SQS notifications | | | | | Remove deleted nodes | | | | |
| | +--------+------+ | Push Scale Up/Scale Down Events | | | | to SQS service | | +--------------------------+ | Discover Gravity ELB | | | | | | Read Join Token | | +--------------> SSM Parameter Store <--------------+ Join the cluster | | | | | | +--------------------------+ | | | | +-------------------------------------------+ | | | | | | | AWS Lifecycle Hooks/SQS notifications | | +-------------------> <---------------------------------+ | | +-------------------------------------------+
- Autoscaler runs on master nodes
- Autoscaler publishes the Gravity load balancer service and encrypted join token to the SSM (AWS systems manager) parameter store
- Instances started up as a part of auto scaling group discover the cluster by reading SSM parameters from the parameter store.
- Whenever ASG scales down it sends a notification to the SQS (Amazon Simple Queue Service)
queue associated with the cluster. * Autoscaler receives the notification on the scale down and removes the node from the cluster in forced mode (as the instance is offline by the time notification is received)
Index ¶
- Constants
- func ConvertError(err error, args ...interface{}) error
- type Autoscaler
- func (a *Autoscaler) DeleteEvent(ctx context.Context, event HookEvent) error
- func (a *Autoscaler) DescribeInstance(ctx context.Context, instanceID string) (*ec2.Instance, error)
- func (a *Autoscaler) DescribeInstancesWithSourceDestinationCheck(ctx context.Context, instanceIDs []string) (result []*ec2.Instance, err error)
- func (a *Autoscaler) GetQueueURL(ctx context.Context) (string, error)
- func (a *Autoscaler) GetServiceURLAndJoinToken(ctx context.Context) (responseURL string, responseToken string, err error)
- func (a *Autoscaler) ProcessEvents(ctx context.Context, queueURL string, operator Operator)
- func (a *Autoscaler) PublishDiscovery(ctx context.Context, operator ops.Operator)
- func (a *Autoscaler) TurnOffSourceDestinationCheck(ctx context.Context, instanceID string) error
- func (a *Autoscaler) WaitUntilInstanceTerminated(ctx context.Context, instanceID string) error
- type Config
- type EC2
- type HookEvent
- type NewLocalInstance
- type Operator
- type SQS
- type SSM
Constants ¶
const ( // InstanceLaunching is AWS instance launching lifecycle autoscaling event InstanceLaunching = "autoscaling:EC2_INSTANCE_LAUNCHING" // InstanceTerminating is AWS instance terminating lifecycle autoscaling event InstanceTerminating = "autoscaling:EC2_INSTANCE_TERMINATING" )
Variables ¶
This section is empty.
Functions ¶
func ConvertError ¶
ConvertError converts errors specific to AWS to trace-compatible error
Types ¶
type Autoscaler ¶
type Autoscaler struct { // Config is Autoscaler config Config // QueueURL is SQS queue name with notifications QueueURL string *log.Entry // contains filtered or unexported fields }
Autoscaler is AWS autoscaler server, it enables nodes to discover cluster information via AWS Systems Manager (SSM) Parameter Store and Masters to add/remove nodes from the cluster as they join via discovery group
func (*Autoscaler) DeleteEvent ¶
func (a *Autoscaler) DeleteEvent(ctx context.Context, event HookEvent) error
DeleteEvent deletes SQS message associated with event
func (*Autoscaler) DescribeInstance ¶
func (a *Autoscaler) DescribeInstance(ctx context.Context, instanceID string) (*ec2.Instance, error)
DescribeInstance returns information about instance with the specified ID.
func (*Autoscaler) DescribeInstancesWithSourceDestinationCheck ¶
func (a *Autoscaler) DescribeInstancesWithSourceDestinationCheck(ctx context.Context, instanceIDs []string) (result []*ec2.Instance, err error)
DescribeInstancesWithSourceDestinationCheck returns all instances from the specified list that have source/destination check enabled.
func (*Autoscaler) GetQueueURL ¶
func (a *Autoscaler) GetQueueURL(ctx context.Context) (string, error)
GetQueueURL returns queue URL associated with this cluster
func (*Autoscaler) GetServiceURLAndJoinToken ¶
func (a *Autoscaler) GetServiceURLAndJoinToken(ctx context.Context) (responseURL string, responseToken string, err error)
GetServiceURLAndJoinToken fetches and decrypts cluster service URL and join token from SSM parameter
func (*Autoscaler) ProcessEvents ¶
func (a *Autoscaler) ProcessEvents(ctx context.Context, queueURL string, operator Operator)
ProcessEvents listens for events on SQS queue that are sent by the auto scaling group lifecycle hooks.
func (*Autoscaler) PublishDiscovery ¶
func (a *Autoscaler) PublishDiscovery(ctx context.Context, operator ops.Operator)
PublishDiscovery periodically updates discovery information
func (*Autoscaler) TurnOffSourceDestinationCheck ¶
func (a *Autoscaler) TurnOffSourceDestinationCheck(ctx context.Context, instanceID string) error
TurnOffSourceDestinationCheck check turns off source destination check on the instance that is necessary for K8s to function properly
func (*Autoscaler) WaitUntilInstanceTerminated ¶
func (a *Autoscaler) WaitUntilInstanceTerminated(ctx context.Context, instanceID string) error
WaitUntilInstanceTerminated blocks until the instance with the specified ID is terminated.
Note: If an incorrect or non-existent ID is provided, the method will block indefinitely (or until timeout has been reached) so it is advised to query the instance using DescribeInstance method prior to calling it.
type Config ¶
type Config struct { // ClusterName is a Telekube cluster name, // used to discover configuration in the cluster ClusterName string // Client is an optional kubernetes client Client *kubernetes.Clientset // SSM is AWS systems manager parameter store, // metadata store used to store configuration SystemsManager SSM // Queue is Simple Queue Service, AWS pub/sub queue Queue SQS // Cloud is Elastic Compute Cloud, AWS cloud service Cloud EC2 // AutoScaling is a client for the AWS AutoScaling service AutoScaling *autoscaling.AutoScaling // NewLocalInstance is used to retrieve local instance metadata NewLocalInstance NewLocalInstance // Region specifies the AWS region the gravity controllers are running in Region string }
Config is autoscaler config
func (*Config) CheckAndSetDefaults ¶
CheckAndSetDefaults checks and sets default values
type EC2 ¶
type EC2 interface { ModifyInstanceAttributeWithContext(aws.Context, *ec2.ModifyInstanceAttributeInput, ...request.Option) (*ec2.ModifyInstanceAttributeOutput, error) DescribeInstancesWithContext(aws.Context, *ec2.DescribeInstancesInput, ...request.Option) (*ec2.DescribeInstancesOutput, error) WaitUntilInstanceTerminatedWithContext(aws.Context, *ec2.DescribeInstancesInput, ...request.WaiterOption) error }
EC2 is an interface representing AWS Elastic Compute cloud
type HookEvent ¶
type HookEvent struct { // QueueURL is a queue this event belongs to QueueURL string `json:"-"` // ReceiptHandle is SQS receipt handle ReceiptHandle string `json:"-"` // InstanceID is AWS instance ID InstanceID string `json:"EC2InstanceId"` // Type is event type Type string `json:"LifecycleTransition"` // Token is the token to use when interacting with the lifecycle event Token string `json:"LifecycleActionToken"` // AutoScalingGroupName is the name of the AWS ASG AutoScalingGroupName string `json:"AutoScalingGroupName"` // LifecycleHookName is the name of the AWS Lifecycle hook LifecycleHookName string `json:"LifecycleHookName"` }
HookEvent is a lifecycle hook event posted by autoscaling group
type NewLocalInstance ¶
type Operator ¶
type Operator interface { GetLocalSite(context.Context) (*ops.Site, error) CreateSiteShrinkOperation(context.Context, ops.CreateSiteShrinkOperationRequest) (*ops.SiteOperationKey, error) GetSiteOperationProgress(ops.SiteOperationKey) (*ops.ProgressEntry, error) }
Operator is a simplified operator interface to mock in tests
type SQS ¶
type SQS interface { DeleteMessageWithContext(aws.Context, *sqs.DeleteMessageInput, ...request.Option) (*sqs.DeleteMessageOutput, error) ReceiveMessageWithContext(aws.Context, *sqs.ReceiveMessageInput, ...request.Option) (*sqs.ReceiveMessageOutput, error) GetQueueUrlWithContext(aws.Context, *sqs.GetQueueUrlInput, ...request.Option) (*sqs.GetQueueUrlOutput, error) }
SQS is an interface representing AWS Queue Service
type SSM ¶
type SSM interface { GetParametersWithContext(aws.Context, *ssm.GetParametersInput, ...request.Option) (*ssm.GetParametersOutput, error) PutParameterWithContext(aws.Context, *ssm.PutParameterInput, ...request.Option) (*ssm.PutParameterOutput, error) }
SSM is an interface representing AWS Systems Manager