@@ -21,6 +21,7 @@ import (
2121	"fmt" 
2222	"time" 
2323
24+ 	apierrors "k8s.io/apimachinery/pkg/api/errors" 
2425	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
2526	"k8s.io/apimachinery/pkg/labels" 
2627	utilruntime "k8s.io/apimachinery/pkg/util/runtime" 
@@ -55,23 +56,23 @@ func NewLeaseCandidateGC(clientset kubernetes.Interface, gcCheckPeriod time.Dura
5556}
5657
5758// Run starts one worker. 
58- func  (c  * LeaseCandidateGCController ) Run (stopCh   <- chan   struct {} ) {
59+ func  (c  * LeaseCandidateGCController ) Run (ctx  context. Context ) {
5960	defer  utilruntime .HandleCrash ()
6061	defer  klog .Infof ("Shutting down apiserver leasecandidate garbage collector" )
6162
6263	klog .Infof ("Starting apiserver leasecandidate garbage collector" )
6364
64- 	if  ! cache .WaitForCacheSync (stopCh , c .leaseCandidatesSynced ) {
65+ 	if  ! cache .WaitForCacheSync (ctx . Done () , c .leaseCandidatesSynced ) {
6566		utilruntime .HandleError (fmt .Errorf ("timed out waiting for caches to sync" ))
6667		return 
6768	}
6869
69- 	go  wait .Until ( c .gc , c .gcCheckPeriod ,  stopCh )
70+ 	go  wait .UntilWithContext ( ctx ,  c .gc , c .gcCheckPeriod )
7071
71- 	<- stopCh 
72+ 	<- ctx . Done () 
7273}
7374
74- func  (c  * LeaseCandidateGCController ) gc () {
75+ func  (c  * LeaseCandidateGCController ) gc (ctx  context. Context ) {
7576	lcs , err  :=  c .leaseCandidateLister .List (labels .Everything ())
7677	if  err  !=  nil  {
7778		klog .ErrorS (err , "Error while listing lease candidates" )
@@ -92,7 +93,7 @@ func (c *LeaseCandidateGCController) gc() {
9293			continue 
9394		}
9495		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 )  {
9697			klog .ErrorS (err , "Error deleting lease" )
9798		}
9899	}
0 commit comments