@@ -21,7 +21,6 @@ import (
21
21
22
22
"github.com/aws/aws-sdk-go/aws"
23
23
"github.com/aws/aws-sdk-go/service/autoscaling"
24
- "github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface"
25
24
"github.com/pkg/errors"
26
25
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
27
26
@@ -36,16 +35,35 @@ func (s *Service) LifecycleHookNeedsUpdate(scope scope.LifecycleHookScope, exist
36
35
existing .NotificationMetadata != expected .NotificationMetadata
37
36
}
38
37
38
+ func (s * Service ) GetLifecycleHooks (scope scope.LifecycleHookScope ) ([]* expinfrav1.AWSLifecycleHook , error ) {
39
+ asgName := scope .GetASGName ()
40
+ input := & autoscaling.DescribeLifecycleHooksInput {
41
+ AutoScalingGroupName : aws .String (asgName ),
42
+ }
43
+
44
+ out , err := s .ASGClient .DescribeLifecycleHooksWithContext (context .TODO (), input )
45
+ if err != nil {
46
+ return nil , errors .Wrapf (err , "failed to describe lifecycle hooks for AutoScalingGroup: %q" , scope .GetASGName ())
47
+ }
48
+
49
+ hooks := make ([]* expinfrav1.AWSLifecycleHook , len (out .LifecycleHooks ))
50
+ for i , hook := range out .LifecycleHooks {
51
+ hooks [i ] = s .SDKToLifecycleHook (hook )
52
+ }
53
+
54
+ return hooks , nil
55
+ }
56
+
39
57
func (s * Service ) GetLifecycleHook (scope scope.LifecycleHookScope , hook * expinfrav1.AWSLifecycleHook ) (* expinfrav1.AWSLifecycleHook , error ) {
40
- asgName := scope .GetMachinePool (). Name
58
+ asgName := scope .GetASGName ()
41
59
input := & autoscaling.DescribeLifecycleHooksInput {
42
60
AutoScalingGroupName : aws .String (asgName ),
43
61
LifecycleHookNames : []* string {aws .String (hook .Name )},
44
62
}
45
63
46
64
out , err := s .ASGClient .DescribeLifecycleHooksWithContext (context .TODO (), input )
47
65
if err != nil {
48
- return nil , errors .Wrapf (err , "failed to describe lifecycle hook %q for AutoScalingGroup: %q" , hook .Name , scope .GetMachinePool (). Name )
66
+ return nil , errors .Wrapf (err , "failed to describe lifecycle hook %q for AutoScalingGroup: %q" , hook .Name , scope .GetASGName () )
49
67
}
50
68
51
69
if len (out .LifecycleHooks ) == 0 {
@@ -56,7 +74,7 @@ func (s *Service) GetLifecycleHook(scope scope.LifecycleHookScope, hook *expinfr
56
74
}
57
75
58
76
func (s * Service ) CreateLifecycleHook (scope scope.LifecycleHookScope , hook * expinfrav1.AWSLifecycleHook ) error {
59
- asgName := scope .GetMachinePool (). Name
77
+ asgName := scope .GetASGName ()
60
78
61
79
lifecycleHookName := hook .Name
62
80
if lifecycleHookName == "" {
@@ -96,14 +114,14 @@ func (s *Service) CreateLifecycleHook(scope scope.LifecycleHookScope, hook *expi
96
114
}
97
115
98
116
if _ , err := s .ASGClient .PutLifecycleHookWithContext (context .TODO (), input ); err != nil {
99
- return errors .Wrapf (err , "failed to create lifecycle hook %q for AutoScalingGroup: %q" , lifecycleHookName , scope .GetMachinePool (). Name )
117
+ return errors .Wrapf (err , "failed to create lifecycle hook %q for AutoScalingGroup: %q" , lifecycleHookName , scope .GetASGName () )
100
118
}
101
119
102
120
return nil
103
121
}
104
122
105
123
func (s * Service ) UpdateLifecycleHook (scope scope.LifecycleHookScope , hook * expinfrav1.AWSLifecycleHook ) error {
106
- asgName := scope .GetMachinePool (). Name
124
+ asgName := scope .GetASGName ()
107
125
108
126
lifecycleHookName := hook .Name
109
127
if lifecycleHookName == "" {
@@ -143,23 +161,22 @@ func (s *Service) UpdateLifecycleHook(scope scope.LifecycleHookScope, hook *expi
143
161
}
144
162
145
163
if _ , err := s .ASGClient .PutLifecycleHookWithContext (context .TODO (), input ); err != nil {
146
- return errors .Wrapf (err , "failed to update lifecycle hook %q for AutoScalingGroup: %q" , lifecycleHookName , scope .GetMachinePool (). Name )
164
+ return errors .Wrapf (err , "failed to update lifecycle hook %q for AutoScalingGroup: %q" , lifecycleHookName , scope .GetASGName () )
147
165
}
148
166
149
167
return nil
150
168
}
151
169
152
170
func (s * Service ) DeleteLifecycleHook (
153
- scope * scope.MachinePoolScope ,
154
- asgClient autoscalingiface.AutoScalingAPI ,
155
- hook expinfrav1.AWSLifecycleHook ) error {
171
+ scope scope.LifecycleHookScope ,
172
+ hook * expinfrav1.AWSLifecycleHook ) error {
156
173
input := & autoscaling.DeleteLifecycleHookInput {
157
- AutoScalingGroupName : aws .String (scope .Name ()),
174
+ AutoScalingGroupName : aws .String (scope .GetASGName ()),
158
175
LifecycleHookName : aws .String (hook .Name ),
159
176
}
160
177
161
- if _ , err := asgClient .DeleteLifecycleHookWithContext (context .TODO (), input ); err != nil {
162
- return errors .Wrapf (err , "failed to delete lifecycle hook %q for AutoScalingGroup: %q" , hook .Name , scope .Name ())
178
+ if _ , err := s . ASGClient .DeleteLifecycleHookWithContext (context .TODO (), input ); err != nil {
179
+ return errors .Wrapf (err , "failed to delete lifecycle hook %q for AutoScalingGroup: %q" , hook .Name , scope .GetASGName ())
163
180
}
164
181
165
182
return nil
0 commit comments