Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion k8s/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"

"github.com/aws/aws-sdk-go/service/autoscaling"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
)

// CheckIfNodeHasEnoughResourcesToTransferAllPodsInNodes calculates the resources available in the target nodes
Expand Down Expand Up @@ -103,3 +103,21 @@ func AnnotateNodeByAutoScalingInstance(client ClientAPI, instance *autoscaling.I
}
return nil
}

// Label Node adds an Label to the Kubernetes node represented by a given AWS instance
func LabelNodeByAutoScalingInstance(client ClientAPI, instance *autoscaling.Instance, key, value string) error {
node, err := client.GetNodeByAutoScalingInstance(instance)
if err != nil {
return err
}
labels := node.GetLabels()
if currentValue := labels[key]; currentValue != value {
labels[key] = value
node.SetLabels(labels)
err = client.UpdateNode(node)
if err != nil {
return err
}
}
return nil
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ func DoHandleRollingUpgrade(client k8s.ClientAPI, ec2Service ec2iface.EC2API, au
if hasEnoughResources {
log.Printf("[%s][%s] Updated nodes have enough resources available", aws.StringValue(autoScalingGroup.AutoScalingGroupName), aws.StringValue(outdatedInstance.InstanceId))
if minutesSinceDrained == -1 {
log.Printf("[%s][%s] Label node to exlude from external load balancers", aws.StringValue(autoScalingGroup.AutoScalingGroupName), aws.StringValue(outdatedInstance.InstanceId))
k8s.LabelNodeByAutoScalingInstance(client, outdatedInstance, "node.kubernetes.io/exclude-from-external-load-balancers", "twin")
log.Printf("[%s][%s] Draining node", aws.StringValue(autoScalingGroup.AutoScalingGroupName), aws.StringValue(outdatedInstance.InstanceId))
err := client.Drain(node.Name, config.Get().IgnoreDaemonSets, config.Get().DeleteEmptyDirData, config.Get().PodTerminationGracePeriod)
if err != nil {
Expand Down