DRA client: fix conversion of watch channel

When the input channel gets closed (for example, because the apiserver got shut
down), then the output channel also needs to get closed because that triggers
the next round of List+Watch.

Also, the channel is used to transmit errors, so it can happen that non-data
items need to be forwarded. That is not an error that needs to be logged.
This commit is contained in:
Patrick Ohly
2025-07-19 11:30:31 +02:00
parent f77ce8951e
commit d0fc938a07

View File

@@ -303,6 +303,8 @@ func (w *watchSomething[NP, N, OP]) ResultChan() <-chan watch.Event {
}
func (w *watchSomething[NP, N, OP]) run() {
defer utilruntime.HandleCrash()
defer close(w.resultChan)
resultChan := w.upstream.ResultChan()
for {
e, ok := <-resultChan
@@ -320,9 +322,6 @@ func (w *watchSomething[NP, N, OP]) run() {
Type: e.Type,
Object: NP(out),
}
} else {
//nolint:logcheck // Shouldn't happen.
klog.Errorf("unexpected object with type %T received from watch", e.Object)
}
// This must not get blocked when the consumer stops reading,
// hence the stopChan.