@@ -1543,6 +1543,9 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
15431543 }
15441544 return obtainedPodNames
15451545 }, ConsistOf (tc .expectedPods )))
1546+ for _ , pod := range obtainedStructuredPodList .Items {
1547+ Expect (informer .Get (context .Background (), client .ObjectKeyFromObject (& pod ), & pod )).To (Succeed ()) //nolint:gosec // We don't retain the pointer
1548+ }
15461549
15471550 By ("Checking with unstructured" )
15481551 obtainedUnstructuredPodList := unstructured.UnstructuredList {}
@@ -1560,6 +1563,9 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
15601563 }
15611564 return obtainedPodNames
15621565 }, ConsistOf (tc .expectedPods )))
1566+ for _ , pod := range obtainedUnstructuredPodList .Items {
1567+ Expect (informer .Get (context .Background (), client .ObjectKeyFromObject (& pod ), & pod )).To (Succeed ()) //nolint:gosec // We don't retain the pointer
1568+ }
15631569
15641570 By ("Checking with metadata" )
15651571 obtainedMetadataPodList := metav1.PartialObjectMetadataList {}
@@ -1577,6 +1583,9 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
15771583 }
15781584 return obtainedPodNames
15791585 }, ConsistOf (tc .expectedPods )))
1586+ for _ , pod := range obtainedMetadataPodList .Items {
1587+ Expect (informer .Get (context .Background (), client .ObjectKeyFromObject (& pod ), & pod )).To (Succeed ()) //nolint:gosec // We don't retain the pointer
1588+ }
15801589 },
15811590 Entry ("when selectors are empty it has to inform about all the pods" , selectorsTestCase {
15821591 expectedPods : []string {"test-pod-1" , "test-pod-2" , "test-pod-3" , "test-pod-4" , "test-pod-5" , "test-pod-6" },
@@ -1789,6 +1798,54 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
17891798 },
17901799 expectedPods : []string {},
17911800 }),
1801+ Entry ("Only NamespaceAll in DefaultNamespaces returns all pods" , selectorsTestCase {
1802+ options : cache.Options {
1803+ DefaultNamespaces : map [string ]cache.Config {
1804+ metav1 .NamespaceAll : {},
1805+ },
1806+ },
1807+ expectedPods : []string {"test-pod-1" , "test-pod-2" , "test-pod-3" , "test-pod-4" , "test-pod-5" , "test-pod-6" },
1808+ }),
1809+ Entry ("Only NamespaceAll in ByObject.Namespaces returns all pods" , selectorsTestCase {
1810+ options : cache.Options {
1811+ ByObject : map [client.Object ]cache.ByObject {
1812+ & corev1.Pod {}: {
1813+ Namespaces : map [string ]cache.Config {
1814+ metav1 .NamespaceAll : {},
1815+ },
1816+ },
1817+ },
1818+ },
1819+ expectedPods : []string {"test-pod-1" , "test-pod-2" , "test-pod-3" , "test-pod-4" , "test-pod-5" , "test-pod-6" },
1820+ }),
1821+ Entry ("NamespaceAll in DefaultNamespaces creates a cache for all Namespaces that are not in DefaultNamespaces" , selectorsTestCase {
1822+ options : cache.Options {
1823+ DefaultNamespaces : map [string ]cache.Config {
1824+ metav1 .NamespaceAll : {},
1825+ testNamespaceOne : {
1826+ // labels.Nothing when serialized matches everything, so we have to construct our own "match nothing" selector
1827+ LabelSelector : labels .SelectorFromSet (labels.Set {"no-present" : "not-present" })},
1828+ },
1829+ },
1830+ // All pods that are not in NamespaceOne
1831+ expectedPods : []string {"test-pod-2" , "test-pod-3" , "test-pod-4" , "test-pod-6" },
1832+ }),
1833+ Entry ("NamespaceAll in ByObject.Namespaces creates a cache for all Namespaces that are not in ByObject.Namespaces" , selectorsTestCase {
1834+ options : cache.Options {
1835+ ByObject : map [client.Object ]cache.ByObject {
1836+ & corev1.Pod {}: {
1837+ Namespaces : map [string ]cache.Config {
1838+ metav1 .NamespaceAll : {},
1839+ testNamespaceOne : {
1840+ // labels.Nothing when serialized matches everything, so we have to construct our own "match nothing" selector
1841+ LabelSelector : labels .SelectorFromSet (labels.Set {"no-present" : "not-present" })},
1842+ },
1843+ },
1844+ },
1845+ },
1846+ // All pods that are not in NamespaceOne
1847+ expectedPods : []string {"test-pod-2" , "test-pod-3" , "test-pod-4" , "test-pod-6" },
1848+ }),
17921849 )
17931850 })
17941851 Describe ("as an Informer" , func () {
0 commit comments