@@ -104,8 +104,7 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
104104 }
105105
106106 // watch update engine for status updates
107- watchUpdateStatusStop := make (chan struct {})
108- go k .watchUpdateStatus (k .updateStatusCallback , watchUpdateStatusStop )
107+ go k .watchUpdateStatus (k .updateStatusCallback , stop )
109108
110109 // block until constants.AnnotationOkToReboot is set
111110 for {
@@ -118,9 +117,6 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
118117 glog .Warningf ("error waiting for an ok-to-reboot: %v" , err )
119118 }
120119
121- // stop watching the update status by closing the channel
122- close (watchUpdateStatusStop )
123-
124120 // set constants.AnnotationRebootInProgress and drain self
125121 anno = map [string ]string {
126122 constants .AnnotationRebootInProgress : constants .True ,
@@ -168,8 +164,7 @@ func (k *Klocksmith) process(stop <-chan struct{}) error {
168164 k .lc .Reboot (false )
169165
170166 // cross fingers
171- time .Sleep (24 * 7 * time .Hour )
172-
167+ sleepOrDone (24 * 7 * time .Hour , stop )
173168 return nil
174169}
175170
@@ -351,3 +346,17 @@ func (k *Klocksmith) getPodsForDeletion() ([]v1.Pod, error) {
351346
352347 return pods , nil
353348}
349+
350+ // sleepOrDone pauses the current goroutine until the done channel receives
351+ // or until at least the duration d has elapsed, whichever comes first. This
352+ // is similar to time.Sleep(d), except it can be interrupted.
353+ func sleepOrDone (d time.Duration , done <- chan struct {}) {
354+ sleep := time .NewTimer (d )
355+ defer sleep .Stop ()
356+ select {
357+ case <- sleep .C :
358+ return
359+ case <- done :
360+ return
361+ }
362+ }
0 commit comments