Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process drain-failure nodes at the end #394

Merged
merged 7 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions controllers/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
var (
instanceStateTagKey = "upgrademgr.keikoproj.io/state"
inProgressTagValue = "in-progress"
failedDrainTagValue = "failed-drain"
)

type DiscoveredState struct {
Expand Down
26 changes: 22 additions & 4 deletions controllers/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
}

func (r *RollingUpgradeContext) RotateNodes() error {
failedDrainInstances, err := r.Auth.DescribeTaggedInstanceIDs(instanceStateTagKey, failedDrainTagValue)
if err != nil {
r.Error(err, "failed to discover ec2 instances with drain-failed tag", "name", r.RollingUpgrade.NamespacedName())
}

// set status to running
r.RollingUpgrade.SetCurrentStatus(v1alpha1.StatusRunning)
r.RollingUpgrade.SetLabel(v1alpha1.LabelKeyRollingUpgradeCurrentStatus, v1alpha1.StatusRunning)
Expand Down Expand Up @@ -112,7 +117,14 @@
return nil
}

rotationTargets := r.SelectTargets(scalingGroup)
rotationTargets := r.SelectTargets(scalingGroup, failedDrainInstances)

if len(rotationTargets) == 0 && len(failedDrainInstances) > 0 {
// If there are failed instances, but no rotation targets, then select failed instances anyway
r.Info("selecting from failed instances since there are no rotation targets", "failedDrainInstances", failedDrainInstances, "name", r.RollingUpgrade.NamespacedName())
rotationTargets = r.SelectTargets(scalingGroup, []string{})
}

if ok, err := r.ReplaceNodeBatch(rotationTargets); !ok {
return err
}
Expand Down Expand Up @@ -308,6 +320,9 @@
if err := r.Auth.DrainNode(node, time.Duration(r.RollingUpgrade.PostDrainDelaySeconds()), drainTimeout, r.Auth.Kubernetes); err != nil {
// ignore drain failures if either of spec or controller args have set ignoreDrainFailures to true.
if !ignoreDrainFailures {
if err := r.Auth.TagEC2instances([]string{instanceID}, instanceStateTagKey, failedDrainTagValue); err != nil {
r.Error(err, "failed to set instances to drain-failed", "batch", instanceID, "name", r.RollingUpgrade.NamespacedName())
}

Check warning on line 325 in controllers/upgrade.go

View check run for this annotation

Codecov / codecov/patch

controllers/upgrade.go#L323-L325

Added lines #L323 - L325 were not covered by tests
r.DrainManager.DrainErrors <- errors.Errorf("DrainNode failed: instanceID - %v, %v", instanceID, err.Error())
return
}
Expand Down Expand Up @@ -418,7 +433,7 @@
return true, nil
}

func (r *RollingUpgradeContext) SelectTargets(scalingGroup *autoscaling.Group) []*autoscaling.Instance {
func (r *RollingUpgradeContext) SelectTargets(scalingGroup *autoscaling.Group, excludedInstances []string) []*autoscaling.Instance {
var (
batchSize = r.RollingUpgrade.MaxUnavailable()
totalNodes = int(aws.Int64Value(scalingGroup.DesiredCapacity))
Expand All @@ -428,6 +443,9 @@

// first process all in progress instances
r.Info("selecting batch for rotation", "batch size", unavailableInt, "name", r.RollingUpgrade.NamespacedName())
if len(excludedInstances) > 0 {
r.Info("ignoring failed drain instances", "instances", excludedInstances, "name", r.RollingUpgrade.NamespacedName())

Check warning on line 447 in controllers/upgrade.go

View check run for this annotation

Codecov / codecov/patch

controllers/upgrade.go#L446-L447

Added lines #L446 - L447 were not covered by tests
}
for _, instance := range r.Cloud.InProgressInstances {
if selectedInstance := awsprovider.SelectScalingGroupInstance(instance, scalingGroup); !reflect.DeepEqual(selectedInstance, &autoscaling.Instance{}) {
//In-progress instances shouldn't be considered if they are in terminating state.
Expand All @@ -444,7 +462,7 @@
// select via strategy if there are no in-progress instances
if r.RollingUpgrade.UpdateStrategyType() == v1alpha1.RandomUpdateStrategy {
for _, instance := range scalingGroup.Instances {
if r.IsInstanceDrifted(instance) && !common.ContainsEqualFold(awsprovider.GetInstanceIDs(targets), aws.StringValue(instance.InstanceId)) {
if r.IsInstanceDrifted(instance) && !common.ContainsEqualFold(awsprovider.GetInstanceIDs(targets), aws.StringValue(instance.InstanceId)) && !common.ContainsEqualFold(excludedInstances, aws.StringValue(instance.InstanceId)) {
targets = append(targets, instance)
}
}
Expand All @@ -455,7 +473,7 @@

} else if r.RollingUpgrade.UpdateStrategyType() == v1alpha1.UniformAcrossAzUpdateStrategy {
for _, instance := range scalingGroup.Instances {
if r.IsInstanceDrifted(instance) && !common.ContainsEqualFold(awsprovider.GetInstanceIDs(targets), aws.StringValue(instance.InstanceId)) {
if r.IsInstanceDrifted(instance) && !common.ContainsEqualFold(awsprovider.GetInstanceIDs(targets), aws.StringValue(instance.InstanceId)) && !common.ContainsEqualFold(excludedInstances, aws.StringValue(instance.InstanceId)) {
targets = append(targets, instance)
}
}
Expand Down