@@ -88,12 +88,22 @@ func assignAddress(c context.Context, log *logrus.Entry, assigner address.Assign
88
88
defer ticker .Stop ()
89
89
90
90
for retryCounter := 0 ; retryCounter <= cfg .RetryAttempts ; retryCounter ++ {
91
+ log .WithFields (logrus.Fields {
92
+ "node" : node .Name ,
93
+ "instance" : node .Instance ,
94
+ "filter" : cfg .Filter ,
95
+ "retry-counter" : retryCounter ,
96
+ "retry-attempts" : cfg .RetryAttempts ,
97
+ }).Debug ("assigning static public IP address to node" )
91
98
err := assigner .Assign (ctx , node .Instance , node .Zone , cfg .Filter , cfg .OrderBy )
92
99
if err == nil || errors .Is (err , address .ErrStaticIPAlreadyAssigned ) {
93
100
return nil
94
101
}
95
102
96
- log .WithError (err ).Errorf ("failed to assign static public IP address to node %s" , node .Name )
103
+ log .WithError (err ).WithFields (logrus.Fields {
104
+ "node" : node .Name ,
105
+ "instance" : node .Instance ,
106
+ }).Error ("failed to assign static public IP address to node" )
97
107
log .Infof ("retrying after %v" , cfg .RetryInterval )
98
108
99
109
select {
@@ -148,26 +158,33 @@ func run(c context.Context, log *logrus.Entry, cfg *config.Config) error {
148
158
}
149
159
}()
150
160
151
- select {
152
- case err = <- errorCh :
153
- if err != nil {
154
- return errors .Wrap (err , "assigning static public IP address" )
155
- }
156
- case <- ctx .Done ():
157
- log .Infof ("kubeip agent gracefully stopped" )
158
- if cfg .ReleaseOnExit {
159
- log .Infof ("releasing static public IP address" )
160
- releaseCtx , releaseCancel := context .WithTimeout (context .Background (), unassignTimeout ) // release the static public IP address within 5 minutes
161
- defer releaseCancel ()
162
- // use a different context for releasing the static public IP address since the main context is canceled
163
- if err = assigner .Unassign (releaseCtx , n .Instance , n .Zone ); err != nil { //nolint:contextcheck
164
- return errors .Wrap (err , "failed to release static public IP address" )
161
+ for {
162
+ select {
163
+ case err = <- errorCh :
164
+ if err != nil {
165
+ return errors .Wrap (err , "assigning static public IP address" )
166
+ }
167
+ case <- ctx .Done ():
168
+ log .Infof ("kubeip agent gracefully stopped" )
169
+ if cfg .ReleaseOnExit {
170
+ log .Infof ("releasing static public IP address" )
171
+ err = func () error {
172
+ releaseCtx , releaseCancel := context .WithTimeout (context .Background (), unassignTimeout ) // release the static public IP address within 5 minutes
173
+ defer releaseCancel ()
174
+ // use a different context for releasing the static public IP address since the main context is canceled
175
+ if err = assigner .Unassign (releaseCtx , n .Instance , n .Zone ); err != nil {
176
+ return errors .Wrap (err , "failed to release static public IP address" )
177
+ }
178
+ return nil
179
+ }()
180
+ if err != nil {
181
+ return err //nolint:wrapcheck
182
+ }
183
+ log .Infof ("static public IP address released" )
165
184
}
166
- log . Infof ( "static public IP address released" )
185
+ return nil
167
186
}
168
187
}
169
-
170
- return nil
171
188
}
172
189
173
190
func runCmd (c * cli.Context ) error {
0 commit comments