controller

package
Version: v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultNodeGroup = "default"

DefaultNodeGroup is used for any pods that don't have a node selector defined

View Source
const (
	// NodeEscalatorIgnoreAnnotation is the key of an annotation on a node that signifies it should be ignored from ASG deletion
	// value does not matter, can be used for reason, as long as not empty
	// if set, the node wil not be deleted. However it still can be tainted and factored into calculations
	NodeEscalatorIgnoreAnnotation = "atlassian.com/no-delete"
)

Variables

This section is empty.

Functions

func BuildNodeGroupsState

func BuildNodeGroupsState(opts nodeGroupsStateOpts) map[string]*NodeGroupState

BuildNodeGroupsState builds a node group state

func NewNodeLabelFilterFunc

func NewNodeLabelFilterFunc(labelKey, labelValue string) k8s.NodeFilterFunc

NewNodeLabelFilterFunc creates a new NodeFilterFunc based on filtering by node labels

func NewPodAffinityFilterFunc

func NewPodAffinityFilterFunc(labelKey, labelValue string) k8s.PodFilterFunc

NewPodAffinityFilterFunc creates a new PodFilterFunc based on filtering by label selectors

func NewPodDefaultFilterFunc

func NewPodDefaultFilterFunc() k8s.PodFilterFunc

NewPodDefaultFilterFunc creates a new PodFilterFunc that includes pods that do not have a selector

func ValidateNodeGroup

func ValidateNodeGroup(nodegroup NodeGroupOptions) []error

ValidateNodeGroup is a safety check to validate that a nodegroup has valid options

Types

type AWSNodeGroupOptions added in v1.7.0

type AWSNodeGroupOptions struct {
	LaunchTemplateID          string   `json:"launch_template_id,omitempty" yaml:"launch_template_id,omitempty"`
	LaunchTemplateVersion     string   `json:"launch_template_version,omitempty" yaml:"launch_template_version,omitempty"`
	FleetInstanceReadyTimeout string   `json:"fleet_instance_ready_timeout,omitempty" yaml:"fleet_instance_ready_timeout,omitempty"`
	Lifecycle                 string   `json:"lifecycle,omitempty" yaml:"lifecycle,omitempty"`
	InstanceTypeOverrides     []string `json:"instance_type_overrides,omitempty" yaml:"instance_type_overrides,omitempty"`
	ResourceTagging           bool     `json:"resource_tagging,omitempty" yaml:"resource_tagging,omitempty"`
	// contains filtered or unexported fields
}

AWSNodeGroupOptions represents a nodegroup running on a cluster that is using the AWS cloud provider

func (*AWSNodeGroupOptions) FleetInstanceReadyTimeoutDuration added in v1.7.0

func (n *AWSNodeGroupOptions) FleetInstanceReadyTimeoutDuration() time.Duration

FleetInstanceReadyTimeoutDuration lazily returns/parses the fleetInstanceReadyTimeout string into a duration

type Client

type Client struct {
	kubernetes.Interface
	Listers map[string]*NodeGroupLister
	// contains filtered or unexported fields
}

Client provides a wrapper around a k8s client that includes anything needed by the controller for listing nodegroup pods and nodes based on a filter

func NewClient

func NewClient(k8sClient kubernetes.Interface, nodegroups []NodeGroupOptions, stopCache <-chan struct{}) (*Client, error)

NewClient creates a new client wrapper over the k8sclient with some pod and node listers It will wait for the cache to sync before returning

type Controller

type Controller struct {
	Client *Client
	Opts   Opts
	// contains filtered or unexported fields
}

Controller contains the core logic of the Autoscaler

func NewController

func NewController(opts Opts, stopChan <-chan struct{}) (*Controller, error)

NewController creates a new controller with the specified options

func (*Controller) RunForever

func (c *Controller) RunForever(runImmediately bool) error

RunForever starts the autoscaler process and runs once every ScanInterval. blocks thread it always returns a non-nil error

func (*Controller) RunOnce

func (c *Controller) RunOnce() error

RunOnce performs the main autoscaler logic once

func (*Controller) ScaleDown

func (c *Controller) ScaleDown(opts scaleOpts) (int, error)

ScaleDown performs the taint and remove node logic

func (*Controller) ScaleUp

func (c *Controller) ScaleUp(opts scaleOpts) (int, error)

ScaleUp performs the untaint and increase cloud provider node group logic

func (*Controller) TryRemoveTaintedNodes

func (c *Controller) TryRemoveTaintedNodes(opts scaleOpts) (int, error)

TryRemoveTaintedNodes attempts to remove nodes are * tainted and empty * have passed their grace period

type NodeGroupLister

type NodeGroupLister struct {
	// Pod lister
	Pods k8s.PodLister
	// Node lister
	Nodes k8s.NodeLister
}

NodeGroupLister is just a light wrapper around a pod lister and node lister Used for grouping a nodegroup and their listers

func NewDefaultNodeGroupLister

func NewDefaultNodeGroupLister(allPodsLister v1lister.PodLister, allNodesLister v1lister.NodeLister, nodeGroup NodeGroupOptions) *NodeGroupLister

NewDefaultNodeGroupLister creates a new group from the backing lister and nodegroup filter with the default filter

func NewNodeGroupLister

func NewNodeGroupLister(allPodsLister v1lister.PodLister, allNodesLister v1lister.NodeLister, nodeGroup NodeGroupOptions) *NodeGroupLister

NewNodeGroupLister creates a new group from the backing lister and nodegroup filter

type NodeGroupOptions

type NodeGroupOptions struct {
	Name                   string `json:"name,omitempty" yaml:"name,omitempty"`
	LabelKey               string `json:"label_key,omitempty" yaml:"label_key,omitempty"`
	LabelValue             string `json:"label_value,omitempty" yaml:"label_value,omitempty"`
	CloudProviderGroupName string `json:"cloud_provider_group_name,omitempty" yaml:"cloud_provider_group_name,omitempty"`

	MinNodes int `json:"min_nodes,omitempty" yaml:"min_nodes,omitempty"`
	MaxNodes int `json:"max_nodes,omitempty" yaml:"max_nodes,omitempty"`

	DryMode bool `json:"dry_mode,omitempty" yaml:"dry_mode,omitempty"`

	TaintUpperCapacityThresholdPercent int `json:"taint_upper_capacity_threshold_percent,omitempty" yaml:"taint_upper_capacity_threshold_percent,omitempty"`
	TaintLowerCapacityThresholdPercent int `json:"taint_lower_capacity_threshold_percent,omitempty" yaml:"taint_lower_capacity_threshold_percent,omitempty"`

	ScaleUpThresholdPercent int `json:"scale_up_threshold_percent,omitempty" yaml:"scale_up_threshold_percent,omitempty"`

	SlowNodeRemovalRate int `json:"slow_node_removal_rate,omitempty" yaml:"slow_node_removal_rate,omitempty"`
	FastNodeRemovalRate int `json:"fast_node_removal_rate,omitempty" yaml:"fast_node_removal_rate,omitempty"`

	SoftDeleteGracePeriod string `json:"soft_delete_grace_period,omitempty" yaml:"soft_delete_grace_period,omitempty"`
	HardDeleteGracePeriod string `json:"hard_delete_grace_period,omitempty" yaml:"soft_delete_grace_period,omitempty"`

	ScaleUpCoolDownPeriod string `json:"scale_up_cool_down_period,omitempty" yaml:"scale_up_cool_down_period,omitempty"`

	TaintEffect v1.TaintEffect `json:"taint_effect,omitempty" yaml:"taint_effect,omitempty"`

	AWS AWSNodeGroupOptions `json:"aws" yaml:"aws"`
	// contains filtered or unexported fields
}

NodeGroupOptions represents a nodegroup running on our cluster We differentiate nodegroups by their node label

func UnmarshalNodeGroupOptions

func UnmarshalNodeGroupOptions(reader io.Reader) ([]NodeGroupOptions, error)

UnmarshalNodeGroupOptions decodes the yaml or json reader into a struct

func (*NodeGroupOptions) HardDeleteGracePeriodDuration

func (n *NodeGroupOptions) HardDeleteGracePeriodDuration() time.Duration

HardDeleteGracePeriodDuration lazily returns/parses the hardDeleteGracePeriodDuration string into a duration

func (*NodeGroupOptions) ScaleUpCoolDownPeriodDuration

func (n *NodeGroupOptions) ScaleUpCoolDownPeriodDuration() time.Duration

ScaleUpCoolDownPeriodDuration lazily returns/parses the scaleUpCoolDownPeriod string into a duration

func (*NodeGroupOptions) SoftDeleteGracePeriodDuration

func (n *NodeGroupOptions) SoftDeleteGracePeriodDuration() time.Duration

SoftDeleteGracePeriodDuration lazily returns/parses the softDeleteGracePeriod string into a duration

type NodeGroupState

type NodeGroupState struct {
	*NodeGroupLister
	Opts        NodeGroupOptions
	NodeInfoMap map[string]*k8s.NodeInfo
	// contains filtered or unexported fields
}

NodeGroupState contains everything about a node group in the current state of the application

type Opts

type Opts struct {
	K8SClient            kubernetes.Interface
	NodeGroups           []NodeGroupOptions
	CloudProviderBuilder cloudprovider.Builder
	ScanInterval         time.Duration
	DryMode              bool
}

Opts provide the Controller with config for runtime

Jump to

Keyboard shortcuts

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