Skip to content
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
5 changes: 3 additions & 2 deletions pkg/cloud/services/autoscaling/lifecyclehook.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ func lifecycleHookNeedsUpdate(existing *expinfrav1.AWSLifecycleHook, expected *e
return ptr.Deref(existing.DefaultResult, expinfrav1.LifecycleHookDefaultResultAbandon) != ptr.Deref(expected.DefaultResult, expinfrav1.LifecycleHookDefaultResultAbandon) ||
ptr.Deref(existing.HeartbeatTimeout, metav1.Duration{Duration: 3600 * time.Second}) != ptr.Deref(expected.HeartbeatTimeout, metav1.Duration{Duration: 3600 * time.Second}) ||
existing.LifecycleTransition != expected.LifecycleTransition ||
existing.NotificationTargetARN != expected.NotificationTargetARN ||
existing.NotificationMetadata != expected.NotificationMetadata
ptr.Deref(existing.NotificationTargetARN, "") != ptr.Deref(expected.NotificationTargetARN, "") ||
ptr.Deref(existing.RoleARN, "") != ptr.Deref(expected.RoleARN, "") ||
ptr.Deref(existing.NotificationMetadata, "") != ptr.Deref(expected.NotificationMetadata, "")
}

func reconcileLifecycleHook(ctx context.Context, asgService services.ASGInterface, asgName string, wantedHook *expinfrav1.AWSLifecycleHook, existingHooks []*expinfrav1.AWSLifecycleHook, storeConditionsOnObject deprecatedv1beta1conditions.Setter, log logger.Wrapper) error {
Expand Down
108 changes: 108 additions & 0 deletions pkg/cloud/services/autoscaling/lifecyclehook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
)
Expand Down Expand Up @@ -53,6 +54,29 @@ func TestLifecycleHookNeedsUpdate(t *testing.T) {
wantUpdate: false,
},

{
name: "exactly equal (all fields filled)",
existing: expinfrav1.AWSLifecycleHook{
Name: "test",
NotificationTargetARN: ptr.To("arn:aws:sqs:eu-west-1:123456789012:mycluster-nth"),
RoleARN: ptr.To("arn:aws:iam::123456789012:role/mycluster-nth-notification"),
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: nil,
},
expected: expinfrav1.AWSLifecycleHook{
Name: "test",
NotificationTargetARN: ptr.To("arn:aws:sqs:eu-west-1:123456789012:mycluster-nth"),
RoleARN: ptr.To("arn:aws:iam::123456789012:role/mycluster-nth-notification"),
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: nil,
},
wantUpdate: false,
},

{
name: "heartbeatTimeout and defaultResult not set in manifest, but set to defaults by AWS",
existing: expinfrav1.AWSLifecycleHook{
Expand Down Expand Up @@ -119,6 +143,90 @@ func TestLifecycleHookNeedsUpdate(t *testing.T) {
},
wantUpdate: true,
},

{
name: "role ARN differs",
existing: expinfrav1.AWSLifecycleHook{
Name: "test",
NotificationTargetARN: ptr.To("arn:aws:sqs:eu-west-1:123456789012:mycluster-nth"),
RoleARN: ptr.To("arn:aws:iam::123456789012:role/mycluster-nth-notification"),
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: nil,
},
expected: expinfrav1.AWSLifecycleHook{
Name: "test",
NotificationTargetARN: ptr.To("arn:aws:sqs:eu-west-1:123456789012:mycluster-nth"),
RoleARN: ptr.To("arn:aws:iam::123456789012:role/mycluster-nth-notification2"),
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: nil,
},
wantUpdate: true,
},

{
name: "notification target ARN differs",
existing: expinfrav1.AWSLifecycleHook{
Name: "test",
NotificationTargetARN: ptr.To("arn:aws:sqs:eu-west-1:123456789012:mycluster-nth"),
RoleARN: ptr.To("arn:aws:iam::123456789012:role/mycluster-nth-notification"),
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: nil,
},
expected: expinfrav1.AWSLifecycleHook{
Name: "test",
NotificationTargetARN: ptr.To("arn:aws:sqs:eu-west-1:123456789012:mycluster-nth2"),
RoleARN: ptr.To("arn:aws:iam::123456789012:role/mycluster-nth-notification"),
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: nil,
},
wantUpdate: true,
},

{
name: "notification metadata both empty",
existing: expinfrav1.AWSLifecycleHook{
Name: "test",
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: nil,
},
expected: expinfrav1.AWSLifecycleHook{
Name: "test",
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: ptr.To(""),
},
wantUpdate: false,
},

{
name: "notification metadata differs",
existing: expinfrav1.AWSLifecycleHook{
Name: "test",
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: ptr.To("abc"),
},
expected: expinfrav1.AWSLifecycleHook{
Name: "test",
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING",
HeartbeatTimeout: &metav1.Duration{Duration: 3600 * time.Second},
DefaultResult: &defaultResultAbandon,
NotificationMetadata: ptr.To("xyz"),
},
wantUpdate: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down