Skip to content

Commit 1f2f7d6

Browse files
authored
Merge pull request #3837 from telepresenceio/thallgren/informer-reuse
Recreating namespaces impossible with dynamically namespaced manager
2 parents 3d7f416 + bd22210 commit 1f2f7d6

File tree

7 files changed

+68
-5
lines changed

7 files changed

+68
-5
lines changed

CHANGELOG.yml

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
#
2525
# For older changes, see CHANGELOG.OLD.md
2626
items:
27+
- version: 2.22.3
28+
date: (TBD)
29+
notes:
30+
- type: bugfix
31+
title: Recreating namespaces was not possible when using a dynamically namespaced Traffic Manager
32+
body: >-
33+
A shared informer was sometimes reused when namespaces were removed and then later added again, leading
34+
to errors like "handler ... was not added to shared informer because it has stopped already".
35+
docs: https://github.com/telepresenceio/telepresence/issues/3831
2736
- version: 2.22.2
2837
date: 2025-03-28
2938
notes:

cmd/traffic/cmd/manager/mutator/watcher.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ func (c *configWatcher) namespacesChangeWatcher(ctx context.Context) error {
442442
dlog.Debugf(ctx, "Adding watchers for namespace %s", ns)
443443
iwc, err := c.startInformers(ctx, ns)
444444
if err != nil {
445-
dlog.Errorf(ctx, "Failed to create watchers namespace %s: %v", ns, err)
445+
dlog.Errorf(ctx, "Failed to create watchers for namespace %s: %v", ns, err)
446446
return nil, true
447447
}
448448
if err = c.startWatchers(ctx, iwc); err != nil {
449-
dlog.Errorf(ctx, "Failed to start watchers namespace %s: %v", ns, err)
449+
dlog.Errorf(ctx, "Failed to start watchers for namespace %s: %v", ns, err)
450450
return nil, true
451451
}
452452
return iwc, false
@@ -475,7 +475,10 @@ func (c *configWatcher) DeleteMapsAndRolloutAll(ctx context.Context) {
475475
}
476476

477477
func (c *configWatcher) deleteMapsAndRolloutNS(ctx context.Context, ns string, iwc *informersWithCancel) {
478-
defer c.informers.Delete(ns)
478+
defer func() {
479+
c.informers.Delete(ns)
480+
informer.DropFactory(ctx, ns)
481+
}()
479482

480483
dlog.Debugf(ctx, "Cancelling watchers for namespace %s", ns)
481484
for i := 0; i < watcherMax; i++ {

docs/release-notes.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11

22
[comment]: # (Code generated by relnotesgen. DO NOT EDIT.)
33
# <img src="images/logo.png" height="64px"/> Telepresence Release Notes
4+
## Version 2.22.3
5+
## <div style="display:flex;"><img src="images/bugfix.png" alt="bugfix" style="width:30px;height:fit-content;"/><div style="display:flex;margin-left:7px;">[Recreating namespaces was not possible when using a dynamically namespaced Traffic Manager](https://github.com/telepresenceio/telepresence/issues/3831)</div></div>
6+
<div style="margin-left: 15px">
7+
8+
A shared informer was sometimes reused when namespaces were removed and then later added again, leading to errors like "handler ... was not added to shared informer because it has stopped already".
9+
</div>
10+
411
## Version 2.22.2 <span style="font-size: 16px;">(March 28)</span>
512
## <div style="display:flex;"><img src="images/bugfix.png" alt="bugfix" style="width:30px;height:fit-content;"/><div style="display:flex;margin-left:7px;">[Panic when using telepresence replace in a IPv6-only cluster](https://github.com/telepresenceio/telepresence/issues/3828)</div></div>
613
<div style="margin-left: 15px">

docs/release-notes.mdx

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import { Note, Title, Body } from '@site/src/components/ReleaseNotes'
77
[comment]: # (Code generated by relnotesgen. DO NOT EDIT.)
88

99
# Telepresence Release Notes
10+
## Version 2.22.3
11+
<Note>
12+
<Title type="bugfix" docs="https://github.com/telepresenceio/telepresence/issues/3831">Recreating namespaces was not possible when using a dynamically namespaced Traffic Manager</Title>
13+
<Body>
14+
A shared informer was sometimes reused when namespaces were removed and then later added again, leading to errors like "handler ... was not added to shared informer because it has stopped already".
15+
</Body>
16+
</Note>
1017
## Version 2.22.2 <span style={{fontSize:'16px'}}>(March 28)</span>
1118
<Note>
1219
<Title type="bugfix" docs="https://github.com/telepresenceio/telepresence/issues/3828">Panic when using telepresence replace in a IPv6-only cluster</Title>

docs/variables.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version: "2.22.2"
2-
dlVersion: "v2.22.2"
1+
version: "2.22.3"
2+
dlVersion: "v2.22.3"

integration_test/namespaces_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,37 @@ func (s *nsSuite) Test_NamespacesDynamic() {
233233

234234
// Upgrade, to ensure that the proper roles and rolebindings are installed.
235235
s.TelepresenceHelmInstallOK(ctx, true)
236+
rq.Equal(0, restartCount())
237+
238+
itest.TelepresenceOk(ctx, "connect", "--manager-namespace", s.managerNamespace(), "--namespace", "delta")
239+
st = itest.TelepresenceStatusOk(ctx)
240+
rq.Len(st.UserDaemon.MappedNamespaces, 4)
241+
242+
itest.ApplyEchoService(ctx, "echo", "delta", 80)
243+
244+
// Check that list output includes the service from "delta"
245+
lst := itest.TelepresenceOk(ctx, "list")
246+
rq.Contains(lst, "deployment echo:")
247+
itest.TelepresenceDisconnectOk(ctx)
248+
249+
// Delete and recreate the namespace
250+
s.NoError(itest.Kubectl(ctx, "", "delete", "namespace", "delta"))
251+
rq.NoError(itest.Kubectl(dos.WithStdin(ctx, bytes.NewReader(data)), "", "apply", "-f", "-"))
252+
253+
// Upgrade, to ensure that the proper roles and rolebindings are installed.
254+
s.TelepresenceHelmInstallOK(ctx, true)
255+
rq.Equal(0, restartCount())
256+
236257
itest.TelepresenceOk(ctx, "connect", "--manager-namespace", s.managerNamespace(), "--namespace", "delta")
237258
st = itest.TelepresenceStatusOk(ctx)
238259
rq.Len(st.UserDaemon.MappedNamespaces, 4)
260+
261+
itest.ApplyEchoService(ctx, "echo", "delta", 80)
262+
263+
// Check that list output still includes the service from "delta"
264+
lst = itest.TelepresenceOk(ctx, "list")
265+
rq.Contains(lst, "deployment echo:")
266+
itest.TelepresenceDisconnectOk(ctx)
239267
}
240268

241269
func (s *nsSuite) Test_NamespacesStatic() {

pkg/informer/context.go

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ func GetFactory(ctx context.Context, ns string) GlobalFactory {
5454
return gf
5555
}
5656

57+
func DropFactory(ctx context.Context, ns string) {
58+
if ns == "" {
59+
return
60+
}
61+
if fm, ok := ctx.Value(factoryKey{}).(*xsync.MapOf[string, GlobalFactory]); ok {
62+
fm.Delete(ns)
63+
}
64+
}
65+
5766
func GetK8sFactory(ctx context.Context, ns string) informers.SharedInformerFactory {
5867
f := GetFactory(ctx, ns)
5968
if f != nil {

0 commit comments

Comments
 (0)