Skip to content

Commit 38a06d3

Browse files
committed
Ingress watcher init - include context and fix duration init
1 parent 842731f commit 38a06d3

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

pkg/kube/ingress.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type ingressValue struct {
6868
// IngressWatcher watches for changes in Kubernetes Ingress resources and updates the ingress cache accordingly
6969
type IngressWatcher struct {
7070
ctx context.Context
71+
cancel context.CancelFunc
7172
logger logger.Logger
7273
cache ingresscache.IngressHostCache
7374
factory informers.SharedInformerFactory
@@ -76,23 +77,24 @@ type IngressWatcher struct {
7677
}
7778

7879
func NewIngressWatcher(
79-
ctx context.Context,
80+
dlxCtx context.Context,
8081
dlxLogger logger.Logger,
8182
kubeClient kubernetes.Interface,
82-
ingressCache ingresscache.IngressCache,
83+
ingressCache ingresscache.IngressHostCache,
8384
resolveTargetsCallback ResolveTargetsFromIngressCallback,
84-
resyncTimeout *time.Duration,
85+
resyncTimeout time.Duration,
8586
namespace string,
8687
labelSelector string,
8788
) (*IngressWatcher, error) {
88-
if resyncTimeout == nil {
89-
defaultTimeout := defaultResyncInterval
90-
resyncTimeout = &defaultTimeout
89+
if resyncTimeout == 0 {
90+
resyncTimeout = defaultResyncInterval
9191
}
9292

93+
ctx, cancel := context.WithCancel(dlxCtx)
94+
9395
factory := informers.NewSharedInformerFactoryWithOptions(
9496
kubeClient,
95-
*resyncTimeout,
97+
resyncTimeout,
9698
informers.WithNamespace(namespace),
9799
informers.WithTweakListOptions(func(options *metav1.ListOptions) {
98100
options.LabelSelector = labelSelector
@@ -102,8 +104,9 @@ func NewIngressWatcher(
102104

103105
ingressWatcher := &IngressWatcher{
104106
ctx: ctx,
107+
cancel: cancel,
105108
logger: dlxLogger.GetChild("watcher"),
106-
cache: &ingressCache,
109+
cache: ingressCache,
107110
factory: factory,
108111
informer: ingressInformer,
109112
resolveTargetsCallback: resolveTargetsCallback,
@@ -136,6 +139,7 @@ func (iw *IngressWatcher) Start() error {
136139
func (iw *IngressWatcher) Stop() {
137140
iw.logger.Info("Stopping ingress watcher")
138141
iw.factory.Shutdown()
142+
iw.cancel()
139143
}
140144

141145
// --- ResourceEventHandler methods ---

0 commit comments

Comments
 (0)