@@ -68,6 +68,7 @@ type ingressValue struct {
68
68
// IngressWatcher watches for changes in Kubernetes Ingress resources and updates the ingress cache accordingly
69
69
type IngressWatcher struct {
70
70
ctx context.Context
71
+ cancel context.CancelFunc
71
72
logger logger.Logger
72
73
cache ingresscache.IngressHostCache
73
74
factory informers.SharedInformerFactory
@@ -76,23 +77,24 @@ type IngressWatcher struct {
76
77
}
77
78
78
79
func NewIngressWatcher (
79
- ctx context.Context ,
80
+ dlxCtx context.Context ,
80
81
dlxLogger logger.Logger ,
81
82
kubeClient kubernetes.Interface ,
82
- ingressCache ingresscache.IngressCache ,
83
+ ingressCache ingresscache.IngressHostCache ,
83
84
resolveTargetsCallback ResolveTargetsFromIngressCallback ,
84
- resyncTimeout * time.Duration ,
85
+ resyncTimeout time.Duration ,
85
86
namespace string ,
86
87
labelSelector string ,
87
88
) (* IngressWatcher , error ) {
88
- if resyncTimeout == nil {
89
- defaultTimeout := defaultResyncInterval
90
- resyncTimeout = & defaultTimeout
89
+ if resyncTimeout == 0 {
90
+ resyncTimeout = defaultResyncInterval
91
91
}
92
92
93
+ ctx , cancel := context .WithCancel (dlxCtx )
94
+
93
95
factory := informers .NewSharedInformerFactoryWithOptions (
94
96
kubeClient ,
95
- * resyncTimeout ,
97
+ resyncTimeout ,
96
98
informers .WithNamespace (namespace ),
97
99
informers .WithTweakListOptions (func (options * metav1.ListOptions ) {
98
100
options .LabelSelector = labelSelector
@@ -102,8 +104,9 @@ func NewIngressWatcher(
102
104
103
105
ingressWatcher := & IngressWatcher {
104
106
ctx : ctx ,
107
+ cancel : cancel ,
105
108
logger : dlxLogger .GetChild ("watcher" ),
106
- cache : & ingressCache ,
109
+ cache : ingressCache ,
107
110
factory : factory ,
108
111
informer : ingressInformer ,
109
112
resolveTargetsCallback : resolveTargetsCallback ,
@@ -136,6 +139,7 @@ func (iw *IngressWatcher) Start() error {
136
139
func (iw * IngressWatcher ) Stop () {
137
140
iw .logger .Info ("Stopping ingress watcher" )
138
141
iw .factory .Shutdown ()
142
+ iw .cancel ()
139
143
}
140
144
141
145
// --- ResourceEventHandler methods ---
0 commit comments