@@ -15,6 +15,9 @@ import (
15
15
fakekube "k8s.io/client-go/kubernetes/fake"
16
16
kubefake "k8s.io/client-go/kubernetes/fake"
17
17
clienttesting "k8s.io/client-go/testing"
18
+ aboutv1alpha1 "sigs.k8s.io/about-api/pkg/apis/v1alpha1"
19
+ aboutclusterfake "sigs.k8s.io/about-api/pkg/generated/clientset/versioned/fake"
20
+ aboutinformers "sigs.k8s.io/about-api/pkg/generated/informers/externalversions"
18
21
19
22
clusterfake "open-cluster-management.io/api/client/cluster/clientset/versioned/fake"
20
23
clusterscheme "open-cluster-management.io/api/client/cluster/clientset/versioned/scheme"
@@ -34,6 +37,7 @@ func TestSync(t *testing.T) {
34
37
cases := []struct {
35
38
name string
36
39
cluster runtime.Object
40
+ properties []runtime.Object
37
41
claims []runtime.Object
38
42
validateActions func (t * testing.T , actions []clienttesting.Action )
39
43
expectedErr string
@@ -52,6 +56,16 @@ func TestSync(t *testing.T) {
52
56
{
53
57
name : "sync a joined managed cluster" ,
54
58
cluster : testinghelpers .NewJoinedManagedCluster (),
59
+ properties : []runtime.Object {
60
+ & aboutv1alpha1.ClusterProperty {
61
+ ObjectMeta : metav1.ObjectMeta {
62
+ Name : "name" ,
63
+ },
64
+ Spec : aboutv1alpha1.ClusterPropertySpec {
65
+ Value : "test" ,
66
+ },
67
+ },
68
+ },
55
69
claims : []runtime.Object {
56
70
& clusterv1alpha1.ClusterClaim {
57
71
ObjectMeta : metav1.ObjectMeta {
@@ -71,6 +85,10 @@ func TestSync(t *testing.T) {
71
85
t .Fatal (err )
72
86
}
73
87
expected := []clusterv1.ManagedClusterClaim {
88
+ {
89
+ Name : "name" ,
90
+ Value : "tests" ,
91
+ },
74
92
{
75
93
Name : "a" ,
76
94
Value : "b" ,
@@ -97,11 +115,16 @@ func TestSync(t *testing.T) {
97
115
}
98
116
99
117
clusterClient := clusterfake .NewSimpleClientset (objects ... )
118
+ aboutClusterClient := aboutclusterfake .NewSimpleClientset (objects ... )
119
+ clusterPropertyInformerFactory := aboutinformers .NewSharedInformerFactory (aboutClusterClient , time .Minute * 10 )
100
120
clusterInformerFactory := clusterinformers .NewSharedInformerFactory (clusterClient , time .Minute * 10 )
101
121
if c .cluster != nil {
102
122
if err := clusterInformerFactory .Cluster ().V1 ().ManagedClusters ().Informer ().GetStore ().Add (c .cluster ); err != nil {
103
123
t .Fatal (err )
104
124
}
125
+ if err := clusterPropertyInformerFactory .About ().V1alpha1 ().ClusterProperties ().Informer ().GetStore ().Add (c .cluster ); err != nil {
126
+ t .Fatal (err )
127
+ }
105
128
}
106
129
107
130
for _ , claim := range c .claims {
@@ -110,6 +133,12 @@ func TestSync(t *testing.T) {
110
133
}
111
134
}
112
135
136
+ for _ , property := range c .properties {
137
+ if err := clusterPropertyInformerFactory .About ().V1alpha1 ().ClusterProperties ().Informer ().GetStore ().Add (property ); err != nil {
138
+ t .Fatal (err )
139
+ }
140
+ }
141
+
113
142
fakeHubClient := fakekube .NewSimpleClientset ()
114
143
ctx := context .TODO ()
115
144
hubEventRecorder , err := helpers .NewEventRecorder (ctx ,
@@ -123,6 +152,7 @@ func TestSync(t *testing.T) {
123
152
clusterInformerFactory .Cluster ().V1 ().ManagedClusters (),
124
153
discoveryClient ,
125
154
clusterInformerFactory .Cluster ().V1alpha1 ().ClusterClaims (),
155
+ clusterPropertyInformerFactory .About ().V1alpha1 ().ClusterProperties (),
126
156
kubeInformerFactory .Core ().V1 ().Nodes (),
127
157
20 ,
128
158
eventstesting .NewTestingEventRecorder (t ),
@@ -141,6 +171,7 @@ func TestExposeClaims(t *testing.T) {
141
171
cases := []struct {
142
172
name string
143
173
cluster * clusterv1.ManagedCluster
174
+ properties []* aboutv1alpha1.ClusterProperty
144
175
claims []* clusterv1alpha1.ClusterClaim
145
176
maxCustomClusterClaims int
146
177
validateActions func (t * testing.T , actions []clienttesting.Action )
@@ -179,6 +210,39 @@ func TestExposeClaims(t *testing.T) {
179
210
}
180
211
},
181
212
},
213
+ {
214
+ name : "sync properties into status of the managed cluster" ,
215
+ cluster : testinghelpers .NewJoinedManagedCluster (),
216
+ properties : []* aboutv1alpha1.ClusterProperty {
217
+ {
218
+ ObjectMeta : metav1.ObjectMeta {
219
+ Name : "a" ,
220
+ },
221
+ Spec : aboutv1alpha1.ClusterPropertySpec {
222
+ Value : "b" ,
223
+ },
224
+ },
225
+ },
226
+ validateActions : func (t * testing.T , actions []clienttesting.Action ) {
227
+ testingcommon .AssertActions (t , actions , "patch" )
228
+ patch := actions [0 ].(clienttesting.PatchAction ).GetPatch ()
229
+ cluster := & clusterv1.ManagedCluster {}
230
+ err := json .Unmarshal (patch , cluster )
231
+ if err != nil {
232
+ t .Fatal (err )
233
+ }
234
+ expected := []clusterv1.ManagedClusterClaim {
235
+ {
236
+ Name : "a" ,
237
+ Value : "b" ,
238
+ },
239
+ }
240
+ actual := cluster .Status .ClusterClaims
241
+ if ! reflect .DeepEqual (actual , expected ) {
242
+ t .Errorf ("expected cluster claim %v but got: %v" , expected , actual )
243
+ }
244
+ },
245
+ },
182
246
{
183
247
name : "truncate custom cluster claims" ,
184
248
cluster : testinghelpers .NewJoinedManagedCluster (),
@@ -324,11 +388,16 @@ func TestExposeClaims(t *testing.T) {
324
388
}
325
389
326
390
clusterClient := clusterfake .NewSimpleClientset (objects ... )
391
+ aboutClusterClient := aboutclusterfake .NewSimpleClientset (objects ... )
392
+ clusterPropertyInformerFactory := aboutinformers .NewSharedInformerFactory (aboutClusterClient , time .Minute * 10 )
327
393
clusterInformerFactory := clusterinformers .NewSharedInformerFactory (clusterClient , time .Minute * 10 )
328
394
if c .cluster != nil {
329
395
if err := clusterInformerFactory .Cluster ().V1 ().ManagedClusters ().Informer ().GetStore ().Add (c .cluster ); err != nil {
330
396
t .Fatal (err )
331
397
}
398
+ if err := clusterPropertyInformerFactory .About ().V1alpha1 ().ClusterProperties ().Informer ().GetStore ().Add (c .cluster ); err != nil {
399
+ t .Fatal (err )
400
+ }
332
401
}
333
402
334
403
for _ , claim := range c .claims {
@@ -337,6 +406,12 @@ func TestExposeClaims(t *testing.T) {
337
406
}
338
407
}
339
408
409
+ for _ , property := range c .properties {
410
+ if err := clusterPropertyInformerFactory .About ().V1alpha1 ().ClusterProperties ().Informer ().GetStore ().Add (property ); err != nil {
411
+ t .Fatal (err )
412
+ }
413
+ }
414
+
340
415
if c .maxCustomClusterClaims == 0 {
341
416
c .maxCustomClusterClaims = 20
342
417
}
@@ -354,6 +429,7 @@ func TestExposeClaims(t *testing.T) {
354
429
clusterInformerFactory .Cluster ().V1 ().ManagedClusters (),
355
430
discoveryClient ,
356
431
clusterInformerFactory .Cluster ().V1alpha1 ().ClusterClaims (),
432
+ clusterPropertyInformerFactory .About ().V1alpha1 ().ClusterProperties (),
357
433
kubeInformerFactory .Core ().V1 ().Nodes (),
358
434
c .maxCustomClusterClaims ,
359
435
eventstesting .NewTestingEventRecorder (t ),
0 commit comments