@@ -59,6 +59,37 @@ func NewCheckpointCleanupManager(s *DeviceState, client *draclient.Client) *Chec
5959 }
6060}
6161
62+ func (m * CheckpointCleanupManager ) Start (ctx context.Context , unprepfunc TypeUnprepCallable ) error {
63+ ctx , cancel := context .WithCancel (ctx )
64+ m .cancelContext = cancel
65+ m .unprepfunc = unprepfunc
66+
67+ m .waitGroup .Add (1 )
68+ go func () {
69+ defer m .waitGroup .Done ()
70+ // Start producer: periodically submit cleanup task.
71+ m .triggerPeriodically (ctx )
72+ }()
73+
74+ m .waitGroup .Add (1 )
75+ go func () {
76+ defer m .waitGroup .Done ()
77+ // Start consumer
78+ m .worker (ctx )
79+ }()
80+
81+ klog .V (6 ).Infof ("CheckpointCleanupManager started" )
82+ return nil
83+ }
84+
85+ func (m * CheckpointCleanupManager ) Stop () error {
86+ if m .cancelContext != nil {
87+ m .cancelContext ()
88+ }
89+ m .waitGroup .Wait ()
90+ return nil
91+ }
92+
6293// cleanup() is the high-level cleanup routine run once upon plugin startup and
6394// then periodically. It gets all claims in PrepareStarted state from the
6495// current checkpoint, and runs `unprepareIfStale()` for each of them. Each
@@ -186,37 +217,6 @@ func (m *CheckpointCleanupManager) getClaimByName(ctx context.Context, name stri
186217 return claim , nil
187218}
188219
189- func (m * CheckpointCleanupManager ) Start (ctx context.Context , unprepfunc TypeUnprepCallable ) error {
190- ctx , cancel := context .WithCancel (ctx )
191- m .cancelContext = cancel
192- m .unprepfunc = unprepfunc
193-
194- m .waitGroup .Add (1 )
195- go func () {
196- defer m .waitGroup .Done ()
197- // Start producer: periodically submit cleanup task.
198- m .triggerPeriodically (ctx )
199- }()
200-
201- m .waitGroup .Add (1 )
202- go func () {
203- defer m .waitGroup .Done ()
204- // Start consumer
205- m .worker (ctx )
206- }()
207-
208- klog .V (6 ).Infof ("CheckpointCleanupManager started" )
209- return nil
210- }
211-
212- func (m * CheckpointCleanupManager ) Stop () error {
213- if m .cancelContext != nil {
214- m .cancelContext ()
215- }
216- m .waitGroup .Wait ()
217- return nil
218- }
219-
220220// enqueueCleanup() submits a cleanup task if the queue is currently empty.
221221// Return a Boolean indicating whether the task was submitted or not.
222222func (m * CheckpointCleanupManager ) enqueueCleanup () bool {
0 commit comments