@@ -25,116 +25,114 @@ import (
25
25
"k8s.io/apimachinery/pkg/fields"
26
26
"sigs.k8s.io/controller-runtime/pkg/cache"
27
27
"sigs.k8s.io/controller-runtime/pkg/client"
28
- "sigs.k8s.io/controller-runtime/pkg/kcp"
29
- "sigs.k8s.io/controller-runtime/pkg/kontext"
30
28
)
31
29
32
- var _ = Describe ("KCP cluster-unaware informer cache" , func () {
33
- // Test whether we can have a cluster-unaware informer cache against a single workspace.
34
- // I.e. every object has a kcp.io/cluster annotation, but it should not be taken
35
- // into consideration by the cache to compute the key.
36
- It ("should be able to get the default namespace despite kcp.io/cluster annotation" , func () {
37
- ctx , cancel := context .WithCancel (context .Background ())
38
- defer cancel ()
39
-
40
- c , err := cache .New (cfg , cache.Options {})
41
- Expect (err ).NotTo (HaveOccurred ())
42
-
30
+ var _ = Describe ("informer cache against a kube cluster" , func () {
31
+ BeforeEach (func () {
43
32
By ("Annotating the default namespace with kcp.io/cluster" )
44
33
cl , err := client .New (cfg , client.Options {})
45
34
Expect (err ).NotTo (HaveOccurred ())
46
35
ns := & corev1.Namespace {}
47
- err = cl .Get (ctx , client.ObjectKey {Name : "default" }, ns )
36
+ err = cl .Get (context . Background () , client.ObjectKey {Name : "default" }, ns )
48
37
Expect (err ).NotTo (HaveOccurred ())
49
38
ns .Annotations = map [string ]string {"kcp.io/cluster" : "cluster1" }
50
- err = cl .Update (ctx , ns )
51
- Expect (err ).NotTo (HaveOccurred ())
52
-
53
- go c .Start (ctx ) //nolint:errcheck // Start is blocking, and error not relevant here.
54
- c .WaitForCacheSync (ctx )
55
-
56
- By ("By getting the default namespace with the informer" )
57
- err = c .Get (ctx , client.ObjectKey {Name : "default" }, ns )
39
+ err = cl .Update (context .Background (), ns )
58
40
Expect (err ).NotTo (HaveOccurred ())
59
41
})
60
42
61
- It ("should support indexes with cluster-less keys" , func () {
62
- ctx , cancel := context .WithCancel (context .Background ())
63
- defer cancel ()
64
-
65
- c , err := cache .New (cfg , cache.Options {})
66
- Expect (err ).NotTo (HaveOccurred ())
43
+ Describe ("KCP cluster-unaware informer cache" , func () {
44
+ // Test whether we can have a cluster-unaware informer cache against a single workspace.
45
+ // I.e. every object has a kcp.io/cluster annotation, but it should not be taken
46
+ // into consideration by the cache to compute the key.
47
+ It ("should be able to get the default namespace despite kcp.io/cluster annotation" , func () {
48
+ ctx , cancel := context .WithCancel (context .Background ())
49
+ defer cancel ()
67
50
68
- By ("Indexing the default namespace by name" )
69
- err = c .IndexField (ctx , & corev1.Namespace {}, "my-name" , func (obj client.Object ) []string {
70
- return []string {"my-key-" + obj .GetName ()}
71
- })
72
- Expect (err ).NotTo (HaveOccurred ())
51
+ c , err := cache .New (cfg , cache.Options {})
52
+ Expect (err ).NotTo (HaveOccurred ())
73
53
74
- go c .Start (ctx ) //nolint:errcheck // Start is blocking, and error not relevant here.
75
- c .WaitForCacheSync (ctx )
54
+ go c .Start (ctx ) //nolint:errcheck // Start is blocking, and error not relevant here.
55
+ c .WaitForCacheSync (ctx )
76
56
77
- By ("By getting the default namespace via the custom index " )
78
- nss := & corev1.NamespaceList {}
79
- err = c .List (ctx , nss , client.MatchingFieldsSelector {
80
- Selector : fields . OneTermEqualSelector ( "my-name" , "my-key-default" ),
57
+ By ("By getting the default namespace with the informer " )
58
+ ns := & corev1.Namespace {}
59
+ err = c .Get (ctx , client.ObjectKey { Name : "default" }, ns )
60
+ Expect ( err ). NotTo ( HaveOccurred ())
81
61
})
82
- Expect (err ).NotTo (HaveOccurred ())
83
- Expect (nss .Items ).To (HaveLen (1 ))
84
- })
85
- })
86
-
87
- var _ = Describe ("KCP cluster-aware informer cache" , func () {
88
- It ("should be able to get the default namespace with kcp.io/cluster annotation" , func () {
89
- ctx , cancel := context .WithCancel (context .Background ())
90
- defer cancel ()
91
-
92
- c , err := kcp .NewClusterAwareCache (cfg , cache.Options {})
93
- Expect (err ).NotTo (HaveOccurred ())
94
-
95
- By ("Annotating the default namespace with kcp.io/cluster" )
96
- cl , err := client .New (cfg , client.Options {})
97
- Expect (err ).NotTo (HaveOccurred ())
98
- ns := & corev1.Namespace {}
99
- err = cl .Get (ctx , client.ObjectKey {Name : "default" }, ns )
100
- Expect (err ).NotTo (HaveOccurred ())
101
- ns .Annotations = map [string ]string {"kcp.io/cluster" : "cluster1" }
102
- err = cl .Update (ctx , ns )
103
- Expect (err ).NotTo (HaveOccurred ())
104
-
105
- go c .Start (ctx ) //nolint:errcheck // Start is blocking, and error not relevant here.
106
- c .WaitForCacheSync (ctx )
107
-
108
- By ("By getting the default namespace with the informer, but cluster-less key should fail" )
109
- err = c .Get (ctx , client.ObjectKey {Name : "default" }, ns )
110
- Expect (err ).To (HaveOccurred ())
111
-
112
- By ("By getting the default namespace with the informer, but cluster-aware key should succeed" )
113
- err = c .Get (kontext .WithCluster (ctx , "cluster1" ), client.ObjectKey {Name : "default" , Namespace : "cluster1" }, ns )
114
- })
115
-
116
- It ("should support indexes with cluster-aware keys" , func () {
117
- ctx , cancel := context .WithCancel (context .Background ())
118
- defer cancel ()
119
62
120
- c , err := cache .New (cfg , cache.Options {})
121
- Expect (err ).NotTo (HaveOccurred ())
122
-
123
- By ("Indexing the default namespace by name" )
124
- err = c .IndexField (ctx , & corev1.Namespace {}, "my-name" , func (obj client.Object ) []string {
125
- return []string {"my-key-" + obj .GetName ()}
63
+ It ("should support indexes with cluster-less keys" , func () {
64
+ ctx , cancel := context .WithCancel (context .Background ())
65
+ defer cancel ()
66
+
67
+ c , err := cache .New (cfg , cache.Options {})
68
+ Expect (err ).NotTo (HaveOccurred ())
69
+
70
+ By ("Indexing the default namespace by name" )
71
+ err = c .IndexField (ctx , & corev1.Namespace {}, "name-clusterless" , func (obj client.Object ) []string {
72
+ return []string {"key-" + obj .GetName ()}
73
+ })
74
+ Expect (err ).NotTo (HaveOccurred ())
75
+
76
+ go c .Start (ctx ) //nolint:errcheck // Start is blocking, and error not relevant here.
77
+ c .WaitForCacheSync (ctx )
78
+
79
+ By ("By getting the default namespace via the custom index" )
80
+ nss := & corev1.NamespaceList {}
81
+ err = c .List (ctx , nss , client.MatchingFieldsSelector {
82
+ Selector : fields .OneTermEqualSelector ("name-clusterless" , "key-default" ),
83
+ })
84
+ Expect (err ).NotTo (HaveOccurred ())
85
+ Expect (nss .Items ).To (HaveLen (1 ))
126
86
})
127
- Expect (err ).NotTo (HaveOccurred ())
128
-
129
- go c .Start (ctx ) //nolint:errcheck // Start is blocking, and error not relevant here.
130
- c .WaitForCacheSync (ctx )
87
+ })
131
88
132
- By ("By getting the default namespace via the custom index" )
133
- nss := & corev1.NamespaceList {}
134
- err = c .List (ctx , nss , client.MatchingFieldsSelector {
135
- Selector : fields .OneTermEqualSelector ("my-name" , "my-key-default" ),
89
+ // TODO: get envtest in place with kcp
90
+ /*
91
+ Describe("KCP cluster-aware informer cache", func() {
92
+ It("should be able to get the default namespace with kcp.io/cluster annotation", func() {
93
+ ctx, cancel := context.WithCancel(context.Background())
94
+ defer cancel()
95
+
96
+ c, err := kcp.NewClusterAwareCache(cfg, cache.Options{})
97
+ Expect(err).NotTo(HaveOccurred())
98
+
99
+ go c.Start(ctx) //nolint:errcheck // Start is blocking, and error not relevant here.
100
+ c.WaitForCacheSync(ctx)
101
+
102
+ By("By getting the default namespace with the informer, but cluster-less key should fail")
103
+ ns := &corev1.Namespace{}
104
+ err = c.Get(ctx, client.ObjectKey{Name: "default"}, ns)
105
+ Expect(err).To(HaveOccurred())
106
+
107
+ By("By getting the default namespace with the informer, but cluster-aware key should succeed")
108
+ err = c.Get(kontext.WithCluster(ctx, "cluster1"), client.ObjectKey{Name: "default", Namespace: "cluster1"}, ns)
109
+ Expect(err).NotTo(HaveOccurred())
110
+ })
111
+
112
+ It("should support indexes with cluster-aware keys", func() {
113
+ ctx, cancel := context.WithCancel(context.Background())
114
+ defer cancel()
115
+
116
+ c, err := kcp.NewClusterAwareCache(cfg, cache.Options{})
117
+ Expect(err).NotTo(HaveOccurred())
118
+
119
+ By("Indexing the default namespace by name")
120
+ err = c.IndexField(ctx, &corev1.Namespace{}, "name-clusteraware", func(obj client.Object) []string {
121
+ return []string{"key-" + obj.GetName()}
122
+ })
123
+ Expect(err).NotTo(HaveOccurred())
124
+
125
+ go c.Start(ctx) //nolint:errcheck // Start is blocking, and error not relevant here.
126
+ c.WaitForCacheSync(ctx)
127
+
128
+ By("By getting the default namespace via the custom index")
129
+ nss := &corev1.NamespaceList{}
130
+ err = c.List(ctx, nss, client.MatchingFieldsSelector{
131
+ Selector: fields.OneTermEqualSelector("name-clusteraware", "key-default"),
132
+ })
133
+ Expect(err).NotTo(HaveOccurred())
134
+ Expect(nss.Items).To(HaveLen(1))
135
+ })
136
136
})
137
- Expect (err ).NotTo (HaveOccurred ())
138
- Expect (nss .Items ).To (HaveLen (1 ))
139
- })
137
+ */
140
138
})
0 commit comments