Skip to content

Latest commit

 

History

History
51 lines (41 loc) · 3.6 KB

0005-graduation of EventBridge.md

File metadata and controls

51 lines (41 loc) · 3.6 KB

5. Graduation of EventBridge in CAPA

  • Status: accepted
  • Date: 2022-07-29
  • Authors: @Ankitasw
  • Deciders: @richardcase @sedefsavas

Context

EventBridge is an eventbus provided by AWS to watch for the events generated by any SaaS application running on AWS, or any of the AWS services, that could be used by any other services.

With respect to CAPA, the AWSMachine controller uses EC2 instance state change events via EventBridge to trigger reconciliation so that it can handle the lifecycle of the EC2 instances.

In the future, there are other CloudWatch events that CAPA controllers might want to take action on based on the event (e.g. ASG Scale-in events, Spot Instance Termination Notices, Scheduled Maintenance events).

Current Design

EventBridge looks for EC2 state change events for all the AWSMachine based on InstanceID found in the SQS queue, and loads the state to ec2-instance-state label in that AWSMachine in processMessage() func.

Currently, EventBridge handles messages only from source aws.ec2.

Decision

We will graduate the EventBridge support out of experimental so that it is GA and enabled by default in CAPA because we want to be able to use the different event types in the future.

Consequences

  • We would define EventBridgeEvent struct in awsinstancestate_controller.go to capture EventBridge event details:
type EventBridgeEvent struct {
Version    string          `json:"version"`
ID         string          `json:"id"`
DetailType string          `json:"detail-type"`
Source     string          `json:"source"`
Account    string          `json:"account"`
Time       string          `json:"time"`
Region     string          `json:"region"`
Resources  []string        `json:"resources"`
Detail     json.RawMessage `json:"detail"`
}
  • There would be a long polling mechanism in the AWSInstanceState controller that reads the messages from SQS queue with the interval of 10 seconds.
  • EventBridgeEvent would be populated based on the unmarshalled message received above.
  • While processing the message in processMessage(), AWSInstanceState controller processes below listed events based on the Source captured in above struct:
    • Check EC2 state change events from aws.ec2 source.
    • Check ASG lifecycle hook events from aws.autoscaling source.
    • Check spot instance termination notice events from aws.ec2 source.
    • Check scheduled events from aws.health source.
  • Based on the type of event, AWSInstanceState controller updates the label ec2-instance-state with the correct instance state.
  • The logic for ec2-instance-state label already exists in AWSMachine object, similarly we would add label asg-instance-state in the AWSMachinePool object to keep track of change events.
  • Below helper functions in pkg/cloud/services/instancestate would be used by CAPA controllers:
    • GetEventFromSQS(): This fetches the EventBridgeEvent details to act upon that event in the respective controller based on the use-case. As soon as the labels ec2-instance-state and asg-instance-state is patched on the AWSMachine and AWSMachinePool respectively (we would need a watcher for this functionality), this func would be called by the respective controllers to get the event details.
    • IsEventProcessed(): This func returns true/false based on event processing completion thereby sending the confirmation of deleting the event from the queue. This would be the responsibility of the controller to trigger after the events are acted upon.