@@ -119,6 +119,8 @@ func (cs *commandService) CreateConnection(
119
119
// If any connection or unrecoverable errors occur, return and agent should re-establish a subscription.
120
120
// If errors occur with applying the config, log and put those errors into the status queue to be written
121
121
// to the Gateway status.
122
+ //
123
+ //nolint:gocyclo // could be room for improvement here
122
124
func (cs * commandService ) Subscribe (in pb.CommandService_SubscribeServer ) error {
123
125
ctx := in .Context ()
124
126
@@ -179,6 +181,7 @@ func (cs *commandService) Subscribe(in pb.CommandService_SubscribeServer) error
179
181
panic (fmt .Sprintf ("unknown request type %d" , msg .Type ))
180
182
}
181
183
184
+ cs .logger .V (1 ).Info ("Sending configuration to agent" , "requestType" , msg .Type )
182
185
if err := msgr .Send (ctx , req ); err != nil {
183
186
cs .logger .Error (err , "error sending request to agent" )
184
187
deployment .SetPodErrorStatus (conn .PodName , err )
@@ -189,7 +192,10 @@ func (cs *commandService) Subscribe(in pb.CommandService_SubscribeServer) error
189
192
case err = <- msgr .Errors ():
190
193
cs .logger .Error (err , "connection error" , "pod" , conn .PodName )
191
194
deployment .SetPodErrorStatus (conn .PodName , err )
192
- channels .ResponseCh <- struct {}{}
195
+ select {
196
+ case channels .ResponseCh <- struct {}{}:
197
+ default :
198
+ }
193
199
194
200
if errors .Is (err , io .EOF ) {
195
201
return grpcStatus .Error (codes .Aborted , err .Error ())
@@ -198,7 +204,11 @@ func (cs *commandService) Subscribe(in pb.CommandService_SubscribeServer) error
198
204
case msg := <- msgr .Messages ():
199
205
res := msg .GetCommandResponse ()
200
206
if res .GetStatus () != pb .CommandResponse_COMMAND_STATUS_OK {
201
- err := fmt .Errorf ("bad response from agent: msg: %s; error: %s" , res .GetMessage (), res .GetError ())
207
+ if isRollbackMessage (res .GetMessage ()) {
208
+ // we don't care about these messages, so ignore them
209
+ continue
210
+ }
211
+ err := fmt .Errorf ("msg: %s; error: %s" , res .GetMessage (), res .GetError ())
202
212
deployment .SetPodErrorStatus (conn .PodName , err )
203
213
} else {
204
214
deployment .SetPodErrorStatus (conn .PodName , nil )
@@ -268,6 +278,8 @@ func (cs *commandService) setInitialConfig(
268
278
for _ , action := range deployment .GetNGINXPlusActions () {
269
279
// retry the API update request because sometimes nginx isn't quite ready after the config apply reload
270
280
timeoutCtx , cancel := context .WithTimeout (ctx , 5 * time .Second )
281
+ var overallUpstreamApplyErr error
282
+
271
283
if err := wait .PollUntilContextCancel (
272
284
timeoutCtx ,
273
285
500 * time .Millisecond ,
@@ -287,13 +299,14 @@ func (cs *commandService) setInitialConfig(
287
299
}
288
300
289
301
if upstreamApplyErr != nil {
290
- return false , nil //nolint:nilerr // this error is collected at the end
302
+ overallUpstreamApplyErr = errors .Join (overallUpstreamApplyErr , upstreamApplyErr )
303
+ return false , nil
291
304
}
292
305
return true , nil
293
306
},
294
307
); err != nil {
295
- if strings . Contains ( err . Error (), "bad response from agent" ) {
296
- errs = append (errs , err )
308
+ if overallUpstreamApplyErr != nil {
309
+ errs = append (errs , overallUpstreamApplyErr )
297
310
} else {
298
311
cancel ()
299
312
return err
@@ -330,7 +343,7 @@ func (cs *commandService) waitForInitialConfigApply(
330
343
case msg := <- msgr .Messages ():
331
344
res := msg .GetCommandResponse ()
332
345
if res .GetStatus () != pb .CommandResponse_COMMAND_STATUS_OK {
333
- applyErr := fmt .Errorf ("bad response from agent: msg: %s; error: %s" , res .GetMessage (), res .GetError ())
346
+ applyErr := fmt .Errorf ("msg: %s; error: %s" , res .GetMessage (), res .GetError ())
334
347
return applyErr , nil
335
348
}
336
349
@@ -379,6 +392,12 @@ func buildRequest(fileOverviews []*pb.File, instanceID, version string) *pb.Mana
379
392
}
380
393
}
381
394
395
+ func isRollbackMessage (msg string ) bool {
396
+ msgToLower := strings .ToLower (msg )
397
+ return strings .Contains (msgToLower , "rollback successful" ) ||
398
+ strings .Contains (msgToLower , "rollback failed" )
399
+ }
400
+
382
401
func buildPlusAPIRequest (action * pb.NGINXPlusAction , instanceID string ) * pb.ManagementPlaneRequest {
383
402
return & pb.ManagementPlaneRequest {
384
403
MessageMeta : & pb.MessageMeta {
0 commit comments