Skip to content

Commit b95757c

Browse files
committed
Always update DefaultResult/HeartbeatTimeout settings if they drifted
1 parent 66ad8a8 commit b95757c

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

exp/api/v1beta2/types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ const (
268268
LifecycleHookTransitionInstanceTerminating LifecycleTransition = "autoscaling:EC2_INSTANCE_TERMINATING"
269269
)
270270

271-
func (l *LifecycleTransition) String() string {
272-
return string(*l)
271+
func (l LifecycleTransition) String() string {
272+
return string(l)
273273
}
274274

275275
// LifecycleHookDefaultResult is the default result for the lifecycle hook.
@@ -282,8 +282,8 @@ const (
282282
LifecycleHookDefaultResultAbandon LifecycleHookDefaultResult = "ABANDON"
283283
)
284284

285-
func (d *LifecycleHookDefaultResult) String() string {
286-
return string(*d)
285+
func (d LifecycleHookDefaultResult) String() string {
286+
return string(d)
287287
}
288288

289289
// ASGStatus is a status string returned by the autoscaling API.

pkg/cloud/services/autoscaling/lifecyclehook.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
// DescribeLifecycleHooks returns the lifecycle hooks for the given AutoScalingGroup after retrieving them from the AWS API.
3737
func (s *Service) DescribeLifecycleHooks(asgName string) ([]*expinfrav1.AWSLifecycleHook, error) {
3838
input := &autoscaling.DescribeLifecycleHooksInput{
39-
AutoScalingGroupName: aws.String(asgName),
39+
AutoScalingGroupName: ptr.To(asgName),
4040
}
4141

4242
out, err := s.ASGClient.DescribeLifecycleHooksWithContext(context.TODO(), input)
@@ -54,25 +54,21 @@ func (s *Service) DescribeLifecycleHooks(asgName string) ([]*expinfrav1.AWSLifec
5454

5555
func getPutLifecycleHookInput(asgName string, hook *expinfrav1.AWSLifecycleHook) (ret *autoscaling.PutLifecycleHookInput) {
5656
ret = &autoscaling.PutLifecycleHookInput{
57-
AutoScalingGroupName: aws.String(asgName),
58-
LifecycleHookName: aws.String(hook.Name),
59-
LifecycleTransition: aws.String(hook.LifecycleTransition.String()),
57+
AutoScalingGroupName: ptr.To(asgName),
58+
LifecycleHookName: ptr.To(hook.Name),
59+
LifecycleTransition: ptr.To(hook.LifecycleTransition.String()),
6060

6161
// Optional
6262
RoleARN: hook.RoleARN,
6363
NotificationTargetARN: hook.NotificationTargetARN,
6464
NotificationMetadata: hook.NotificationMetadata,
6565
}
6666

67-
// Optional parameters
68-
if hook.DefaultResult != nil {
69-
ret.DefaultResult = aws.String(hook.DefaultResult.String())
70-
}
71-
72-
if hook.HeartbeatTimeout != nil {
73-
timeoutSeconds := hook.HeartbeatTimeout.Duration.Seconds()
74-
ret.HeartbeatTimeout = aws.Int64(int64(timeoutSeconds))
75-
}
67+
// For optional fields in the manifest, still fill in the AWS request parameters so any drifted lifecycle hook
68+
// settings are reconciled to the desired state on update. Using AWS default values here.
69+
ret.DefaultResult = ptr.To(ptr.Deref(hook.DefaultResult, expinfrav1.LifecycleHookDefaultResultAbandon).String())
70+
timeoutSeconds := ptr.Deref(hook.HeartbeatTimeout, metav1.Duration{Duration: 3600 * time.Second}).Duration.Seconds()
71+
ret.HeartbeatTimeout = aws.Int64(int64(timeoutSeconds))
7672

7773
return
7874
}
@@ -102,8 +98,8 @@ func (s *Service) UpdateLifecycleHook(ctx context.Context, asgName string, hook
10298
// DeleteLifecycleHook deletes a lifecycle hook for the given AutoScalingGroup.
10399
func (s *Service) DeleteLifecycleHook(ctx context.Context, asgName string, hook *expinfrav1.AWSLifecycleHook) error {
104100
input := &autoscaling.DeleteLifecycleHookInput{
105-
AutoScalingGroupName: aws.String(asgName),
106-
LifecycleHookName: aws.String(hook.Name),
101+
AutoScalingGroupName: ptr.To(asgName),
102+
LifecycleHookName: ptr.To(hook.Name),
107103
}
108104

109105
if _, err := s.ASGClient.DeleteLifecycleHookWithContext(ctx, input); err != nil {
@@ -134,8 +130,8 @@ func (s *Service) SDKToLifecycleHook(hook *autoscaling.LifecycleHook) *expinfrav
134130
func getLifecycleHookSpecificationList(lifecycleHooks []expinfrav1.AWSLifecycleHook) (ret []*autoscaling.LifecycleHookSpecification) {
135131
for _, hook := range lifecycleHooks {
136132
spec := &autoscaling.LifecycleHookSpecification{
137-
LifecycleHookName: aws.String(hook.Name),
138-
LifecycleTransition: aws.String(hook.LifecycleTransition.String()),
133+
LifecycleHookName: ptr.To(hook.Name),
134+
LifecycleTransition: ptr.To(hook.LifecycleTransition.String()),
139135

140136
// Optional
141137
RoleARN: hook.RoleARN,
@@ -145,7 +141,7 @@ func getLifecycleHookSpecificationList(lifecycleHooks []expinfrav1.AWSLifecycleH
145141

146142
// Optional parameters
147143
if hook.DefaultResult != nil {
148-
spec.DefaultResult = aws.String(hook.DefaultResult.String())
144+
spec.DefaultResult = ptr.To(hook.DefaultResult.String())
149145
}
150146

151147
if hook.HeartbeatTimeout != nil {

0 commit comments

Comments
 (0)