service

package
v0.6.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// EventLevelNormal is the level of a normal event
	EventLevelNormal = "Normal"
	// EventLevelWarning is the level of a warning event
	EventLevelWarning = "Warning"
	// EventReasonLifecycleHookReceived is the reason for a lifecycle received event
	EventReasonLifecycleHookReceived EventReason = "LifecycleHookReceived"
	// EventMessageLifecycleHookReceived is the message for a lifecycle received event
	EventMessageLifecycleHookReceived = "lifecycle hook for event %v was received, instance %v will begin processing"
	// EventReasonLifecycleHookProcessed is the reason for a lifecycle successful processing event
	EventReasonLifecycleHookProcessed EventReason = "LifecycleHookProcessed"
	//EventMessageLifecycleHookProcessed is the message for a lifecycle successful processing event
	EventMessageLifecycleHookProcessed = "lifecycle hook for event %v has completed processing, instance %v gracefully terminated after %vs"
	// EventReasonLifecycleHookFailed is the reason for a lifecycle failed event
	EventReasonLifecycleHookFailed EventReason = "LifecycleHookFailed"
	// EventMessageLifecycleHookFailed is the message for a lifecycle failed event
	EventMessageLifecycleHookFailed = "lifecycle hook for event %v has failed processing after %vs: %v"
	// EventReasonNodeDrainSucceeded is the reason for a successful drain event
	EventReasonNodeDrainSucceeded EventReason = "NodeDrainSucceeded"
	// EventMessageNodeDrainSucceeded is the message for a successful drain event
	EventMessageNodeDrainSucceeded = "node %v has been drained successfully as a response to a termination event"
	// EventReasonNodeDrainFailed is the reason for a failed drain event
	EventReasonNodeDrainFailed EventReason = "NodeDrainFailed"
	// EventMessageNodeDrainFailed is the message for a failed drain event
	EventMessageNodeDrainFailed = "node %v draining has failed: %v"
	// EventReasonNodeDeleteSucceeded is the reason for a successful node delete event
	EventReasonNodeDeleteSucceeded EventReason = "NodeDeleteSucceeded"
	// EventMessageNodeDeleteSucceeded is the message for a successful node delete event
	EventMessageNodeDeleteSucceeded = "node %v has been deleted successfully as a response to a termination event"
	// EventReasonNodeDeletenFailed is the reason for a failed node delete event
	EventReasonNodeDeleteFailed EventReason = "NodeDeleteFailed"
	// EventMessageNodeDeleteFailed is the message for a failed node delete event
	EventMessageNodeDeleteFailed = "node %v deletion has failed: %v"
	// EventReasonTargetDeregisterSucceeded is the reason for a successful target group deregister event
	EventReasonTargetDeregisterSucceeded EventReason = "TargetDeregisterSucceeded"
	// EventMessageTargetDeregisterSucceeded is the message for a successful target group deregister event
	EventMessageTargetDeregisterSucceeded = "target %v:%v has successfully deregistered from target group %v"
	// EventReasonTargetDeregisterFailed is the reason for a successful drain event
	EventReasonTargetDeregisterFailed EventReason = "TargetDeregisterFailed"
	// EventMessageTargetDeregisterFailed is the message for a successful drain event
	EventMessageTargetDeregisterFailed = "target %v has failed to deregistered from target group %v: %v"
	// EventReasonInstanceDeregisterSucceeded is the reason for a successful target group deregister event
	EventReasonInstanceDeregisterSucceeded EventReason = "InstanceDeregisterSucceeded"
	// EventMessageInstanceDeregisterSucceeded is the message for a successful target group deregister event
	EventMessageInstanceDeregisterSucceeded = "instance %v has successfully deregistered from classic-elb %v"
	// EventReasonInstanceDeregisterFailed is the reason for a successful classic elb deregister event
	EventReasonInstanceDeregisterFailed EventReason = "InstanceDeregisterFailed"
	// EventMessageInstanceDeregisterFailed is the message for a successful classic elb deregister event
	EventMessageInstanceDeregisterFailed = "instance %v has failed to deregister from classic-elb %v: %v"
)
View Source
const (
	ActiveGoroutinesMetric            = "active_goroutines"
	TerminatingInstancesCountMetric   = "terminating_instances_count"
	DrainingInstancesCountMetric      = "draining_instances_count"
	DeregisteringInstancesCountMetric = "deregistering_instances_count"
	AverageDurationSecondsMetric      = "average_duration_seconds"
	SuccessfulEventsTotalMetric       = "successful_events_total"
	SuccessfulLBDeregisterTotalMetric = "successful_lb_deregister_total"
	SuccessfulNodeDrainTotalMetric    = "successful_node_drain_total"
	SuccessfulNodeDeleteTotalMetric   = "successful_node_delete_total"
	FailedEventsTotalMetric           = "failed_events_total"
	FailedLBDeregisterTotalMetric     = "failed_lb_deregister_total"
	FailedNodeDrainTotalMetric        = "failed_node_drain_total"
	FailedNodeDeleteTotalMetric       = "failed_node_delete_total"
	RejectedEventsTotalMetric         = "rejected_events_total"
)

Variables

View Source
var (
	// EventName is the default name for service events
	EventName = "lifecycle-manager.%v"
	// EventNamespace is the default namespace in which events will be published in
	EventNamespace = "default"

	// EventLevels is a map of event reasons and their event level
	EventLevels = map[EventReason]string{
		EventReasonLifecycleHookReceived:       EventLevelNormal,
		EventReasonLifecycleHookProcessed:      EventLevelNormal,
		EventReasonLifecycleHookFailed:         EventLevelWarning,
		EventReasonNodeDrainSucceeded:          EventLevelNormal,
		EventReasonNodeDrainFailed:             EventLevelWarning,
		EventReasonTargetDeregisterSucceeded:   EventLevelNormal,
		EventReasonTargetDeregisterFailed:      EventLevelWarning,
		EventReasonInstanceDeregisterSucceeded: EventLevelNormal,
		EventReasonInstanceDeregisterFailed:    EventLevelWarning,
	}
)
View Source
var (
	// MetricsNamespace is the namespace of prometheus metrics
	MetricsNamespace = "lifecycle_manager"
	// MetricsPort is the port used to serve metrics
	MetricsPort = ":8080"
	// MetricsEndpoint is the endpoint to expose for metrics
	MetricsEndpoint = "/metrics"
)
View Source
var (
	// TerminationEventName is the event name of a terminating lifecycle hook
	TerminationEventName = "autoscaling:EC2_INSTANCE_TERMINATING"
	// ContinueAction is the name of the action in case we are successful in draining
	ContinueAction = "CONTINUE"
	// AbandonAction is the name of the action in case we are unsuccessful in draining
	AbandonAction = "ABANDON"
	// AlphaExcludeLabelKey is the alb-ingress-controller exclude label key
	AlphaExcludeLabelKey = "alpha.service-controller.kubernetes.io/exclude-balancer"
	// AlphaExcludeLabelValue is the alb-ingress-controller exclude label value
	AlphaExcludeLabelValue = "true"
	// ExcludeLabelKey is the ServiceNodeExclusion feature exclude label key
	ExcludeLabelKey = "node.kubernetes.io/exclude-from-external-load-balancers"
	// ExcludeLabelKey is the ServiceNodeExclusion feature exclude label value
	ExcludeLabelValue = "true"
	// InProgressAnnotationKey is the annotation key for setting the state of a node to in-progress
	InProgressAnnotationKey = "lifecycle-manager.keikoproj.io/in-progress"
	// QueueNameAnnotationKey is the annotation key for saving the queue name for a node
	QueueNameAnnotationKey = "lifecycle-manager.keikoproj.io/queue-name"
	// ThreadJitterRangeSeconds configures the jitter range in seconds 0 to N per handler goroutine
	ThreadJitterRangeSeconds = 30.0
	// IterationJitterRangeSeconds configures the jitter range in seconds 0 to N per call iteration goroutine
	IterationJitterRangeSeconds = 1.5
	// NodeAgeCacheTTL defines a node age in minutes for which all caches are flushed
	NodeAgeCacheTTL = 90
	// WaiterMinDelay defines the minimum delay of the IEB waiter
	WaiterMinDelay time.Duration = 10 * time.Second
	// WaiterMaxDelay defines the maximum delay of the IEB waiter
	WaiterMaxDelay time.Duration = 90 * time.Second
	// WaiterMaxAttempts defines the maximum attempts of the IEB waiter
	WaiterMaxAttempts uint32 = 120
)

Functions

This section is empty.

Types

type Authenticator

type Authenticator struct {
	ScalingGroupClient autoscalingiface.AutoScalingAPI
	SQSClient          sqsiface.SQSAPI
	ELBv2Client        elbv2iface.ELBV2API
	ELBClient          elbiface.ELBAPI
	KubernetesClient   kubernetes.Interface
}

Authenticator holds clients for all required APIs

type DeregistrationError

type DeregistrationError struct {
	Error     error
	Target    string
	Instances []string
	Type      TargetType
}

type Deregistrator

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

func (*Deregistrator) AddClassicDeregistration

func (d *Deregistrator) AddClassicDeregistration(val int)

func (*Deregistrator) AddTargetGroupDeregistration

func (d *Deregistrator) AddTargetGroupDeregistration(val int)

type EventLevel

type EventLevel string

EventLevel defines the level of an event

type EventReason

type EventReason string

EventReason defines the reason of an event

type LifecycleEvent

type LifecycleEvent struct {
	LifecycleHookName    string `json:"LifecycleHookName"`
	AccountID            string `json:"AccountId"`
	RequestID            string `json:"RequestId"`
	LifecycleTransition  string `json:"LifecycleTransition"`
	AutoScalingGroupName string `json:"AutoScalingGroupName"`
	EC2InstanceID        string `json:"EC2InstanceId"`
	LifecycleActionToken string `json:"LifecycleActionToken"`
	// contains filtered or unexported fields
}

func (*LifecycleEvent) SetDeregisterCompleted

func (e *LifecycleEvent) SetDeregisterCompleted(val bool)

SetDeregisterCompleted is a setter method for status of the drain operation

func (*LifecycleEvent) SetDrainCompleted

func (e *LifecycleEvent) SetDrainCompleted(val bool)

SetDrainCompleted is a setter method for status of the drain operation

func (*LifecycleEvent) SetEventCompleted

func (e *LifecycleEvent) SetEventCompleted(val bool)

SetEventCompleted is a setter method for status of the drain operation

func (*LifecycleEvent) SetEventTimeStarted

func (e *LifecycleEvent) SetEventTimeStarted(t time.Time)

SetEventTimeStarted is a setter method for the time an event started

func (*LifecycleEvent) SetHeartbeatInterval

func (e *LifecycleEvent) SetHeartbeatInterval(interval int64)

SetHeartbeatInterval is a setter method for heartbeat interval of the event

func (*LifecycleEvent) SetMessage

func (e *LifecycleEvent) SetMessage(message *sqs.Message)

SetMessage is a setter method for the sqs message body

func (*LifecycleEvent) SetNodeDeleted

func (e *LifecycleEvent) SetNodeDeleted(val bool)

SetNodeDeleted is a setter method for status of the node deletion operation

func (*LifecycleEvent) SetQueueURL

func (e *LifecycleEvent) SetQueueURL(url string)

SetQueueURL is a setter method for the url of the SQS queue

func (*LifecycleEvent) SetReceiptHandle

func (e *LifecycleEvent) SetReceiptHandle(receipt string)

SetReceiptHandle is a setter method for the receipt handle of the event

func (*LifecycleEvent) SetReferencedNode

func (e *LifecycleEvent) SetReferencedNode(node v1.Node)

SetReferencedNode is a setter method for the event referenced node

type Manager

type Manager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Manager is the main object for lifecycle-manager and holds the state

func New

func New(auth Authenticator, ctx ManagerContext) *Manager

func (*Manager) AddEvent

func (mgr *Manager) AddEvent(event *LifecycleEvent)

func (*Manager) AddTargetByInstance

func (m *Manager) AddTargetByInstance(key interface{}, add *Target)

AddTargetByInstance adds a target by it's instance ID

func (*Manager) CompleteEvent

func (mgr *Manager) CompleteEvent(event *LifecycleEvent)

func (*Manager) DeregisterTargets

func (m *Manager) DeregisterTargets(targets []*Target, d *Deregistrator)

func (*Manager) EventInQueue

func (mgr *Manager) EventInQueue(e *LifecycleEvent) bool

func (*Manager) FailEvent

func (mgr *Manager) FailEvent(err error, event *LifecycleEvent, abandon bool)

func (*Manager) GetTargetInstanceIds

func (m *Manager) GetTargetInstanceIds(key interface{}) []string

GetTargetInstanceIds gets instance ids for a specific key

func (*Manager) GetTargetMapping

func (m *Manager) GetTargetMapping(key interface{}) map[string]int64

GetTargetMapping gets instanceID>port mapping for a specific key

func (*Manager) LoadTargets

func (m *Manager) LoadTargets(key interface{}) []*Target

LoadTargets loads a list of targets by key

func (*Manager) NewTarget

func (m *Manager) NewTarget(targetId, instanceId string, port int64, targetType TargetType) *Target

func (*Manager) Process

func (mgr *Manager) Process(event *LifecycleEvent)

Process processes a received event

func (*Manager) RejectEvent

func (mgr *Manager) RejectEvent(err error, event *LifecycleEvent)

func (*Manager) RemoveFromQueue

func (mgr *Manager) RemoveFromQueue(event *LifecycleEvent)

func (*Manager) RemoveTargetByInstance

func (m *Manager) RemoveTargetByInstance(key interface{}, instanceID string)

RemoveTargetByInstance removes a target by it's instance ID

func (*Manager) SetTargets

func (m *Manager) SetTargets(key interface{}, targets []*Target)

SetTargets sets targets to a specific key

func (*Manager) Start

func (mgr *Manager) Start()

Start starts the lifecycle-manager service

type ManagerContext

type ManagerContext struct {
	CacheConfig                *cache.Config
	KubectlLocalPath           string
	QueueName                  string
	Region                     string
	DrainTimeoutUnknownSeconds int64
	DrainTimeoutSeconds        int64
	DrainRetryIntervalSeconds  int64
	DrainRetryAttempts         uint
	PollingIntervalSeconds     int64
	WithDeregister             bool
	MaxDrainConcurrency        *semaphore.Weighted
	MaxTimeToProcessSeconds    int64
}

ManagerContext contain the user input parameters on the current context

type MetricsServer

type MetricsServer struct {
	Counters map[string]prometheus.Counter
	Gauges   map[string]prometheus.Gauge
}

func (*MetricsServer) AddCounter

func (m *MetricsServer) AddCounter(idx string, value float64)

func (*MetricsServer) DecGauge

func (m *MetricsServer) DecGauge(idx string)

func (*MetricsServer) IncGauge

func (m *MetricsServer) IncGauge(idx string)

func (*MetricsServer) SetGauge

func (m *MetricsServer) SetGauge(idx string, value float64)

func (*MetricsServer) Start

func (m *MetricsServer) Start()

type ScanResult

type ScanResult struct {
	ActiveLoadBalancers []string
	ActiveTargetGroups  map[string]int64
}

ScanResult contains a list of found load balancers and target groups

type Target

type Target struct {
	Type       TargetType
	TargetId   string
	InstanceId string
	Port       int64
}

Target defines a deregistration target

type TargetType

type TargetType string
const (
	// TargetTypeClassicELB defines a target type of classic elb
	TargetTypeClassicELB TargetType = "classic-elb"
	// TargetTypeTargetGroup defines a target type of target-group
	TargetTypeTargetGroup TargetType = "target-group"
)

func (TargetType) String

func (t TargetType) String() string

type Waiter

type Waiter struct {
	sync.WaitGroup
	// contains filtered or unexported fields
}

func (*Waiter) DecClassicWaiter

func (w *Waiter) DecClassicWaiter()

func (*Waiter) DecTargetGroupWaiter

func (w *Waiter) DecTargetGroupWaiter()

func (*Waiter) IncClassicWaiter

func (w *Waiter) IncClassicWaiter()

func (*Waiter) IncTargetGroupWaiter

func (w *Waiter) IncTargetGroupWaiter()

type WaiterError

type WaiterError struct {
	Error error
	Type  TargetType
}

Jump to

Keyboard shortcuts

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