Skip to content

Commit 2d17d36

Browse files
committed
Remove unnecessary goroutines
1 parent 5922b7e commit 2d17d36

File tree

1 file changed

+44
-70
lines changed

1 file changed

+44
-70
lines changed

internal/framework/status/updater.go

Lines changed: 44 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -153,29 +153,16 @@ func (upd *UpdaterImpl) updateNginxGateway(ctx context.Context, status *NginxGat
153153
upd.cfg.Logger.Info("Updating Nginx Gateway status")
154154

155155
if status != nil {
156-
statusUpdatedCh := make(chan struct{})
157-
158-
go func() {
159-
upd.writeStatuses(ctx, status.NsName, &ngfAPI.NginxGateway{}, func(object client.Object) {
160-
ng := object.(*ngfAPI.NginxGateway)
161-
ng.Status = ngfAPI.NginxGatewayStatus{
162-
Conditions: convertConditions(
163-
status.Conditions,
164-
status.ObservedGeneration,
165-
upd.cfg.Clock.Now(),
166-
),
167-
}
168-
})
169-
statusUpdatedCh <- struct{}{}
170-
}()
171-
// Block here as the above goroutine runs. If the context gets canceled, we unblock and the method
172-
// returns. The goroutine continues but is canceled when the controller exits. If the goroutine
173-
// finishes and writes to the channel "statusUpdatedCh", we know that it is done updating
174-
// and this method exits.
175-
select {
176-
case <-ctx.Done():
177-
case <-statusUpdatedCh:
178-
}
156+
upd.writeStatuses(ctx, status.NsName, &ngfAPI.NginxGateway{}, func(object client.Object) {
157+
ng := object.(*ngfAPI.NginxGateway)
158+
ng.Status = ngfAPI.NginxGatewayStatus{
159+
Conditions: convertConditions(
160+
status.Conditions,
161+
status.ObservedGeneration,
162+
upd.cfg.Clock.Now(),
163+
),
164+
}
165+
})
179166
}
180167
}
181168

@@ -189,61 +176,48 @@ func (upd *UpdaterImpl) updateGatewayAPI(ctx context.Context, statuses GatewayAP
189176

190177
upd.cfg.Logger.Info("Updating Gateway API statuses")
191178

192-
statusUpdatedCh := make(chan struct{})
193-
194-
go func() {
195-
if upd.cfg.UpdateGatewayClassStatus {
196-
for nsname, gcs := range statuses.GatewayClassStatuses {
197-
select {
198-
case <-ctx.Done():
199-
return
200-
default:
201-
}
202-
upd.writeStatuses(ctx, nsname, &v1beta1.GatewayClass{}, func(object client.Object) {
203-
gc := object.(*v1beta1.GatewayClass)
204-
gc.Status = prepareGatewayClassStatus(gcs, upd.cfg.Clock.Now())
205-
},
206-
)
207-
}
208-
}
209-
210-
for nsname, gs := range statuses.GatewayStatuses {
179+
if upd.cfg.UpdateGatewayClassStatus {
180+
for nsname, gcs := range statuses.GatewayClassStatuses {
211181
select {
212182
case <-ctx.Done():
213183
return
214184
default:
215185
}
216-
upd.writeStatuses(ctx, nsname, &v1beta1.Gateway{}, func(object client.Object) {
217-
gw := object.(*v1beta1.Gateway)
218-
gw.Status = prepareGatewayStatus(gs, upd.cfg.PodIP, upd.cfg.Clock.Now())
219-
})
186+
upd.writeStatuses(ctx, nsname, &v1beta1.GatewayClass{}, func(object client.Object) {
187+
gc := object.(*v1beta1.GatewayClass)
188+
gc.Status = prepareGatewayClassStatus(gcs, upd.cfg.Clock.Now())
189+
},
190+
)
220191
}
192+
}
221193

222-
for nsname, rs := range statuses.HTTPRouteStatuses {
223-
select {
224-
case <-ctx.Done():
225-
return
226-
default:
227-
}
228-
upd.writeStatuses(ctx, nsname, &v1beta1.HTTPRoute{}, func(object client.Object) {
229-
hr := object.(*v1beta1.HTTPRoute)
230-
// statuses.GatewayStatus is never nil when len(statuses.HTTPRouteStatuses) > 0
231-
hr.Status = prepareHTTPRouteStatus(
232-
rs,
233-
upd.cfg.GatewayCtlrName,
234-
upd.cfg.Clock.Now(),
235-
)
236-
})
194+
for nsname, gs := range statuses.GatewayStatuses {
195+
select {
196+
case <-ctx.Done():
197+
return
198+
default:
199+
}
200+
upd.writeStatuses(ctx, nsname, &v1beta1.Gateway{}, func(object client.Object) {
201+
gw := object.(*v1beta1.Gateway)
202+
gw.Status = prepareGatewayStatus(gs, upd.cfg.PodIP, upd.cfg.Clock.Now())
203+
})
204+
}
205+
206+
for nsname, rs := range statuses.HTTPRouteStatuses {
207+
select {
208+
case <-ctx.Done():
209+
return
210+
default:
237211
}
238-
statusUpdatedCh <- struct{}{}
239-
}()
240-
// Block here as the above goroutine runs. If the context gets canceled, we unblock and the method
241-
// returns. The goroutine continues but is canceled when the controller exits. If the goroutine
242-
// finishes and writes to the channel "statusUpdatedCh", we know that it is done updating
243-
// and this method exits.
244-
select {
245-
case <-ctx.Done():
246-
case <-statusUpdatedCh:
212+
upd.writeStatuses(ctx, nsname, &v1beta1.HTTPRoute{}, func(object client.Object) {
213+
hr := object.(*v1beta1.HTTPRoute)
214+
// statuses.GatewayStatus is never nil when len(statuses.HTTPRouteStatuses) > 0
215+
hr.Status = prepareHTTPRouteStatus(
216+
rs,
217+
upd.cfg.GatewayCtlrName,
218+
upd.cfg.Clock.Now(),
219+
)
220+
})
247221
}
248222
}
249223

0 commit comments

Comments
 (0)