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

Add a mock for test and update version in Makefile #262

Merged
merged 1 commit into from
Jun 22, 2021
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

VERSION=1.0.0-RC1
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
Expand Down
15 changes: 15 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions controllers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"sync"
"testing"
"time"

"k8s.io/client-go/kubernetes/fake"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -197,3 +198,18 @@ func createAmazonClient(t *testing.T) *awsprovider.AmazonClientSet {
Ec2Client: createEc2Client(),
}
}

func (mockAutoscalingGroup MockAutoscalingGroup) TerminateInstanceInAutoScalingGroup(input *autoscaling.TerminateInstanceInAutoScalingGroupInput) (*autoscaling.TerminateInstanceInAutoScalingGroupOutput, error) {
output := &autoscaling.TerminateInstanceInAutoScalingGroupOutput{}
if mockAutoscalingGroup.errorFlag {
if mockAutoscalingGroup.awsErr != nil {
if len(mockAutoscalingGroup.errorInstanceId) <= 0 ||
mockAutoscalingGroup.errorInstanceId == *input.InstanceId {
return output, mockAutoscalingGroup.awsErr
}
}
}
asgChange := autoscaling.Activity{ActivityId: aws.String("xxx"), AutoScalingGroupName: aws.String("sss"), Cause: aws.String("xxx"), StartTime: aws.Time(time.Now()), StatusCode: aws.String("200"), StatusMessage: aws.String("success")}
output.Activity = &asgChange
return output, nil
}
5 changes: 5 additions & 0 deletions controllers/providers/aws/autoscaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ var (
autoscaling.LifecycleStateTerminating,
autoscaling.LifecycleStateTerminatingWait,
autoscaling.LifecycleStateTerminatingProceed,
autoscaling.LifecycleStateTerminated,
autoscaling.LifecycleStateWarmedTerminating,
autoscaling.LifecycleStateWarmedTerminatingWait,
autoscaling.LifecycleStateWarmedTerminatingProceed,
autoscaling.LifecycleStateWarmedTerminated,
}
)

Expand Down
9 changes: 5 additions & 4 deletions controllers/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ func (r *RollingUpgradeContext) SelectTargets(scalingGroup *autoscaling.Group) [
if r.RollingUpgrade.UpdateStrategyType() == v1alpha1.RandomUpdateStrategy {
for _, instance := range scalingGroup.Instances {
if r.IsInstanceDrifted(instance) && !common.ContainsEqualFold(awsprovider.GetInstanceIDs(targets), aws.StringValue(instance.InstanceId)) {
targets = append(targets, instance)
//In-progress instances shouldn't be considered if they are in terminating state.
if !common.ContainsEqualFold(awsprovider.TerminatingInstanceStates, aws.StringValue(instance.LifecycleState)) {
targets = append(targets, instance)
}
}
}
if unavailableInt > len(targets) {
Expand All @@ -368,9 +371,7 @@ func (r *RollingUpgradeContext) SelectTargets(scalingGroup *autoscaling.Group) [
} 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 !common.ContainsEqualFold(awsprovider.TerminatingInstanceStates, aws.StringValue(instance.LifecycleState)) {
targets = append(targets, instance)
}
targets = append(targets, instance)
}
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func TestRotateNodes(t *testing.T) {
v1alpha1.StatusRunning,
},
{
"All instances have different launch config as the ASG, RotateNodes() will mark CR complete",
"All instances have same launch config as the ASG, RotateNodes() will mark CR complete",
createRollingUpgradeReconciler(t),
createASGClient(),
false,
Expand All @@ -305,7 +305,7 @@ func TestRotateNodes(t *testing.T) {

err := rollupCtx.RotateNodes()
if err != nil {
t.Errorf("Test Description: \n expected value: nil, actual value: %v", err)
t.Errorf("Test Description: %s \n error: %v", test.TestDescription, err)
}
if rollupCtx.RollingUpgrade.CurrentStatus() != test.ExpectedStatusValue {
t.Errorf("Test Description: %s \n expected value: %s, actual value: %s", test.TestDescription, test.ExpectedStatusValue, rollupCtx.RollingUpgrade.CurrentStatus())
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/keikoproj/upgrade-manager
go 1.15

require (
github.com/aws/aws-sdk-go v1.36.24
github.com/aws/aws-sdk-go v1.38.24
github.com/go-logr/logr v0.3.0
github.com/keikoproj/aws-sdk-go-cache v0.0.0-20201118182730-f6f418a4e2df
github.com/onsi/gomega v1.10.2
Expand All @@ -16,4 +16,5 @@ require (
k8s.io/client-go v0.20.4
k8s.io/kubectl v0.20.4
sigs.k8s.io/controller-runtime v0.7.0

)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:l
github.com/aws/aws-sdk-go v1.35.7/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
github.com/aws/aws-sdk-go v1.36.24 h1:uVuio0zA5ideP3DGZDpIoExQJd0WcoNUVlNZaKwBnf8=
github.com/aws/aws-sdk-go v1.36.24/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go v1.38.24 h1:zbKHDxFepE77ihVMZ+wZ62Ci646zkorN8rB5s4fj4kU=
github.com/aws/aws-sdk-go v1.38.24/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down