@@ -61,7 +61,6 @@ func (s *PollerEngine) Poll(ctx context.Context, identifiers object.ObjMetadataS
61
61
}
62
62
63
63
runner := & statusPollerRunner {
64
- ctx : ctx ,
65
64
clusterReader : clusterReader ,
66
65
statusReaders : s .StatusReaders ,
67
66
defaultStatusReader : s .DefaultStatusReader ,
@@ -70,7 +69,7 @@ func (s *PollerEngine) Poll(ctx context.Context, identifiers object.ObjMetadataS
70
69
eventChannel : eventChannel ,
71
70
pollingInterval : options .PollInterval ,
72
71
}
73
- runner .Run ()
72
+ runner .Run (ctx )
74
73
}()
75
74
76
75
return eventChannel
@@ -123,10 +122,6 @@ type Options struct {
123
122
// with LIST calls before each polling loop, or the normal ClusterReader that just forwards each call
124
123
// to the client.Reader from controller-runtime.
125
124
type statusPollerRunner struct {
126
- // ctx is the context for the runner. It will be used by the caller of Poll to cancel
127
- // polling resources.
128
- ctx context.Context
129
-
130
125
// clusterReader is the interface for fetching and listing resources from the cluster. It can be implemented
131
126
// to make call directly to the cluster or use caching to reduce the number of calls to the cluster.
132
127
clusterReader ClusterReader
@@ -159,26 +154,26 @@ type statusPollerRunner struct {
159
154
}
160
155
161
156
// Run starts the polling loop of the statusReaders.
162
- func (r * statusPollerRunner ) Run () {
157
+ func (r * statusPollerRunner ) Run (ctx context. Context ) {
163
158
// Sets up ticker that will trigger the regular polling loop at a regular interval.
164
159
ticker := time .NewTicker (r .pollingInterval )
165
160
defer func () {
166
161
ticker .Stop ()
167
162
}()
168
163
169
- err := r .syncAndPoll ()
164
+ err := r .syncAndPoll (ctx )
170
165
if err != nil {
171
166
r .handleSyncAndPollErr (err )
172
167
return
173
168
}
174
169
175
170
for {
176
171
select {
177
- case <- r . ctx .Done ():
172
+ case <- ctx .Done ():
178
173
return
179
174
case <- ticker .C :
180
175
// First sync and then compute status for all resources.
181
- err := r .syncAndPoll ()
176
+ err := r .syncAndPoll (ctx )
182
177
if err != nil {
183
178
r .handleSyncAndPollErr (err )
184
179
return
@@ -202,34 +197,34 @@ func (r *statusPollerRunner) handleSyncAndPollErr(err error) {
202
197
}
203
198
}
204
199
205
- func (r * statusPollerRunner ) syncAndPoll () error {
200
+ func (r * statusPollerRunner ) syncAndPoll (ctx context. Context ) error {
206
201
// First trigger a sync of the ClusterReader. This may or may not actually
207
202
// result in calls to the cluster, depending on the implementation.
208
203
// If this call fails, there is no clean way to recover, so we just return an ErrorEvent
209
204
// and shut down.
210
- err := r .clusterReader .Sync (r . ctx )
205
+ err := r .clusterReader .Sync (ctx )
211
206
if err != nil {
212
207
return err
213
208
}
214
209
// Poll all resources and compute status. If the polling of resources has completed (based
215
210
// on information from the StatusAggregator and the value of pollUntilCancelled), we send
216
211
// a CompletedEvent and return.
217
- return r .pollStatusForAllResources ()
212
+ return r .pollStatusForAllResources (ctx )
218
213
}
219
214
220
215
// pollStatusForAllResources iterates over all the resources in the set and delegates
221
216
// to the appropriate engine to compute the status.
222
- func (r * statusPollerRunner ) pollStatusForAllResources () error {
217
+ func (r * statusPollerRunner ) pollStatusForAllResources (ctx context. Context ) error {
223
218
for _ , id := range r .identifiers {
224
219
// Check if the context has been cancelled on every iteration.
225
220
select {
226
- case <- r . ctx .Done ():
227
- return r . ctx .Err ()
221
+ case <- ctx .Done ():
222
+ return ctx .Err ()
228
223
default :
229
224
}
230
225
gk := id .GroupKind
231
226
statusReader := r .statusReaderForGroupKind (gk )
232
- resourceStatus , err := statusReader .ReadStatus (r . ctx , r .clusterReader , id )
227
+ resourceStatus , err := statusReader .ReadStatus (ctx , r .clusterReader , id )
233
228
if err != nil {
234
229
return err
235
230
}
0 commit comments