k8s

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnotationRollingUpdateStartedTimestamp    = "aws-eks-asg-rolling-update-handler.twin.sh/started-at"
	AnnotationRollingUpdateDrainedTimestamp    = "aws-eks-asg-rolling-update-handler.twin.sh/drained-at"
	AnnotationRollingUpdateTerminatedTimestamp = "aws-eks-asg-rolling-update-handler.twin.sh/terminated-at"

	LabelExcludeFromExternalLoadBalancers = "node.kubernetes.io/exclude-from-external-load-balancers"
)

Variables

This section is empty.

Functions

func AnnotateNodeByAutoScalingInstance added in v1.5.0

func AnnotateNodeByAutoScalingInstance(client ClientAPI, instance *autoscaling.Instance, key, value string) error

AnnotateNodeByAutoScalingInstance adds an annotation to the Kubernetes node represented by a given AWS instance

func CheckIfNodeHasEnoughResourcesToTransferAllPodsInNodes

func CheckIfNodeHasEnoughResourcesToTransferAllPodsInNodes(client ClientAPI, oldNode *v1.Node, targetNodes []*v1.Node) bool

CheckIfNodeHasEnoughResourcesToTransferAllPodsInNodes calculates the resources available in the target nodes and compares them with the resources that would be required if the old node were to be drained

This is not fool proof: 2 targetNodes with 1G available in each would cause the assumption that you can fit a 2G pod in the targetNodes when you obviously can't (you'd need 1 node with 2G available, not 2 with 1G) That's alright, because the purpose is to provide a smooth rolling upgrade, not a flawless experience, and while the latter is definitely possible, it would slow down the process by quite a bit. In a way, this is the beauty of co-existing with the cluster autoscaler; an extra node will be spun up to handle the leftovers, if any.

func CreateClientSet

func CreateClientSet() (*kubernetes.Clientset, error)

CreateClientSet Creates a Kubernetes ClientSet for authenticating with a cluster If the current environment is dev, use the user's kubeconfig If it isn't, then it means that the application is inside the cluster, which means we'll use the service account token

func LabelNodeByAutoScalingInstance added in v1.8.2

func LabelNodeByAutoScalingInstance(client ClientAPI, instance *autoscaling.Instance, key, value string) error

Label Node adds an Label to the Kubernetes node represented by a given AWS instance

Types

type Client added in v1.5.0

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

func NewClient added in v1.5.0

func NewClient(client kubernetes.Interface) *Client

NewClient creates a new Client

func (*Client) Cordon added in v1.7.0

func (k *Client) Cordon(nodeName string) error

Cordon disables scheduling new pods onto the given node

func (*Client) Drain added in v1.5.0

func (k *Client) Drain(nodeName string, ignoreDaemonSets, deleteEmptyDirData bool, podTerminationGracePeriod int) error

Drain gracefully deletes all pods from a given node

func (*Client) FilterNodeByAutoScalingInstance added in v1.5.0

func (k *Client) FilterNodeByAutoScalingInstance(nodes []v1.Node, instance *autoscaling.Instance) (*v1.Node, error)

FilterNodeByAutoScalingInstance extracts the Kubernetes node belonging to a given AWS instance from a list of nodes

func (*Client) GetNodeByAutoScalingInstance added in v1.5.0

func (k *Client) GetNodeByAutoScalingInstance(instance *autoscaling.Instance) (*v1.Node, error)

GetNodeByAutoScalingInstance gets the Kubernetes node matching an AWS AutoScaling instance Because we cannot filter by spec.providerID, the entire list of nodes is fetched every time this function is called

func (*Client) GetNodes added in v1.5.0

func (k *Client) GetNodes() ([]v1.Node, error)

GetNodes retrieves all nodes from the cluster

func (*Client) GetPodsInNode added in v1.5.0

func (k *Client) GetPodsInNode(node string) ([]v1.Pod, error)

GetPodsInNode retrieves all pods from a given node

func (*Client) UpdateNode added in v1.5.0

func (k *Client) UpdateNode(node *v1.Node) error

UpdateNode updates a node

type ClientAPI added in v1.5.0

type ClientAPI interface {
	GetNodes() ([]v1.Node, error)
	GetPodsInNode(nodeName string) ([]v1.Pod, error)
	GetNodeByAutoScalingInstance(instance *autoscaling.Instance) (*v1.Node, error)
	FilterNodeByAutoScalingInstance(nodes []v1.Node, instance *autoscaling.Instance) (*v1.Node, error)
	UpdateNode(node *v1.Node) error
	Cordon(nodeName string) error
	Drain(nodeName string, ignoreDaemonSets, deleteEmptyDirData bool, podTerminationGracePeriod int) error
}

Jump to

Keyboard shortcuts

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