@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"time"
23
23
24
+ apierrors "k8s.io/apimachinery/pkg/api/errors"
24
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
26
"k8s.io/apimachinery/pkg/labels"
26
27
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -55,23 +56,23 @@ func NewLeaseCandidateGC(clientset kubernetes.Interface, gcCheckPeriod time.Dura
55
56
}
56
57
57
58
// Run starts one worker.
58
- func (c * LeaseCandidateGCController ) Run (stopCh <- chan struct {} ) {
59
+ func (c * LeaseCandidateGCController ) Run (ctx context. Context ) {
59
60
defer utilruntime .HandleCrash ()
60
61
defer klog .Infof ("Shutting down apiserver leasecandidate garbage collector" )
61
62
62
63
klog .Infof ("Starting apiserver leasecandidate garbage collector" )
63
64
64
- if ! cache .WaitForCacheSync (stopCh , c .leaseCandidatesSynced ) {
65
+ if ! cache .WaitForCacheSync (ctx . Done () , c .leaseCandidatesSynced ) {
65
66
utilruntime .HandleError (fmt .Errorf ("timed out waiting for caches to sync" ))
66
67
return
67
68
}
68
69
69
- go wait .Until ( c .gc , c .gcCheckPeriod , stopCh )
70
+ go wait .UntilWithContext ( ctx , c .gc , c .gcCheckPeriod )
70
71
71
- <- stopCh
72
+ <- ctx . Done ()
72
73
}
73
74
74
- func (c * LeaseCandidateGCController ) gc () {
75
+ func (c * LeaseCandidateGCController ) gc (ctx context. Context ) {
75
76
lcs , err := c .leaseCandidateLister .List (labels .Everything ())
76
77
if err != nil {
77
78
klog .ErrorS (err , "Error while listing lease candidates" )
@@ -92,7 +93,7 @@ func (c *LeaseCandidateGCController) gc() {
92
93
continue
93
94
}
94
95
if err := c .kubeclientset .CoordinationV1alpha1 ().LeaseCandidates (lc .Namespace ).Delete (
95
- context . TODO () , lc .Name , metav1.DeleteOptions {}); err != nil {
96
+ ctx , lc .Name , metav1.DeleteOptions {}); err != nil && ! apierrors . IsNotFound ( err ) {
96
97
klog .ErrorS (err , "Error deleting lease" )
97
98
}
98
99
}
0 commit comments