Skip to content

Commit 1d10150

Browse files
Fix copyright year to 2026 in new files; add e2e resync test
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
1 parent 6e39732 commit 1d10150

File tree

6 files changed

+46
-6
lines changed

6 files changed

+46
-6
lines changed

examples/informer_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 The Kubernetes Authors.
1+
# Copyright 2026 The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

kubernetes/e2e_test/test_informer.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 The Kubernetes Authors.
1+
# Copyright 2026 The Kubernetes Authors.
22
# Licensed under the Apache License, Version 2.0 (the "License").
33
# End-to-end tests for kubernetes.informer.SharedInformer.
44

@@ -181,5 +181,45 @@ def test_resource_version_advances(self):
181181
self.assertGreater(int(inf._resource_version), rv_before)
182182

183183

184+
def test_resync_fires_modified_for_existing_objects(self):
185+
"""Periodic resync re-lists from the API server and fires MODIFIED for cached objects.
186+
187+
A short resync_period (5 s) is used so the test completes quickly.
188+
After the informer has cached the ConfigMap via the initial list, we
189+
wait for a MODIFIED event that is fired by the resync, verifying that
190+
the resync actually contacts the API server and triggers callbacks.
191+
"""
192+
name = "inf-rsync-" + _uid()
193+
self.api.create_namespaced_config_map(body=_cm(name), namespace="default")
194+
self.addCleanup(self._drop, name)
195+
196+
added = threading.Event()
197+
resynced = threading.Event()
198+
199+
inf = SharedInformer(
200+
list_func=self.api.list_namespaced_config_map,
201+
namespace="default",
202+
label_selector="inf-e2e=1",
203+
resync_period=5,
204+
)
205+
inf.add_event_handler(ADDED, lambda o: added.set() if _name_of(o) == name else None)
206+
# The resync fires MODIFIED for existing cached objects; wait for it.
207+
inf.add_event_handler(MODIFIED, lambda o: resynced.set() if _name_of(o) == name else None)
208+
inf.start()
209+
self.addCleanup(inf.stop)
210+
211+
# First, wait for the object to be added to the cache.
212+
self._expect(added, "ADDED/" + name)
213+
# Then wait for the resync to fire MODIFIED (allow up to 3× resync_period).
214+
if not resynced.wait(timeout=15):
215+
self.fail("Timeout waiting for resync MODIFIED/" + name)
216+
217+
# Verify the cached object still holds the expected data.
218+
cached = inf.cache.get_by_key("default/" + name)
219+
self.assertIsNotNone(cached)
220+
data = cached.data if hasattr(cached, "data") else (cached.get("data") or {})
221+
self.assertEqual(data.get("k"), "v")
222+
223+
184224
if __name__ == "__main__":
185225
unittest.main()

kubernetes/informer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 The Kubernetes Authors.
1+
# Copyright 2026 The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

kubernetes/informer/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 The Kubernetes Authors.
1+
# Copyright 2026 The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

kubernetes/informer/informer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 The Kubernetes Authors.
1+
# Copyright 2026 The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

kubernetes/test/test_informer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 The Kubernetes Authors.
1+
# Copyright 2026 The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)