@@ -210,8 +210,9 @@ func Test_whichMCP(t *testing.T) {
210
210
211
211
c := & nodeInformerController {machineConfigs : mcLister , machineConfigPools : mcpLister }
212
212
213
- if err := initializeCaches (c ); err != nil {
214
- t .Errorf ("Failed to initialize caches: %v" , err )
213
+ // This is to initialize the caches
214
+ if err := syncOnceWithAnUnrecognizableKey (c ); err == nil {
215
+ t .Fatalf ("Expected sync error did not occur" )
215
216
}
216
217
217
218
if diff := cmp .Diff (tc .expected , c .mcpSelectors .whichMCP (tc .labels )); diff != "" {
@@ -222,11 +223,9 @@ func Test_whichMCP(t *testing.T) {
222
223
}
223
224
}
224
225
225
- func initializeCaches (c * nodeInformerController ) error {
226
- if err := c .initializeMachineConfigVersions (); err != nil {
227
- return err
228
- }
229
- return c .initializeMachineConfigPools ()
226
+ func syncOnceWithAnUnrecognizableKey (c * nodeInformerController ) error {
227
+ syncOnceContext := newTestSyncContext ("sync/once" )
228
+ return c .sync (context .TODO (), syncOnceContext )
230
229
}
231
230
232
231
func Test_assessNode (t * testing.T ) {
@@ -1078,10 +1077,6 @@ func Test_sync_with_node(t *testing.T) {
1078
1077
now : func () metav1.Time { return now },
1079
1078
}
1080
1079
1081
- if err := initializeCaches (controller ); err != nil {
1082
- t .Errorf ("Failed to initialize caches: %v" , err )
1083
- }
1084
-
1085
1080
queueKey := nodeInformerControllerQueueKeys (tc .node )[0 ]
1086
1081
1087
1082
actualErr := controller .sync (context .TODO (), newTestSyncContext (queueKey ))
@@ -1136,6 +1131,12 @@ func Test_sync_with_event(t *testing.T) {
1136
1131
}
1137
1132
nodeLister := corelistersv1 .NewNodeLister (nodeIndexer )
1138
1133
1134
+ mcIndexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {})
1135
+ mcLister := machineconfigv1listers .NewMachineConfigLister (mcIndexer )
1136
+
1137
+ mcpIndexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {})
1138
+ mcpLister := machineconfigv1listers .NewMachineConfigPoolLister (mcpIndexer )
1139
+
1139
1140
testCases := []struct {
1140
1141
name string
1141
1142
@@ -1172,8 +1173,10 @@ func Test_sync_with_event(t *testing.T) {
1172
1173
}
1173
1174
1174
1175
controller := & nodeInformerController {
1175
- nodes : nodeLister ,
1176
- sendInsight : sendInsight ,
1176
+ nodes : nodeLister ,
1177
+ machineConfigs : mcLister ,
1178
+ machineConfigPools : mcpLister ,
1179
+ sendInsight : sendInsight ,
1177
1180
}
1178
1181
queueKey := nodeInformerControllerQueueKeys (tc .object )[0 ]
1179
1182
@@ -1205,11 +1208,6 @@ func Test_sync_with_mcp(t *testing.T) {
1205
1208
now := metav1 .Now ()
1206
1209
1207
1210
mcIndexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {})
1208
- for _ , o := range []metav1.Object {} {
1209
- if err := mcIndexer .Add (o ); err != nil {
1210
- t .Fatalf ("Failed to add object to indexer: %v" , err )
1211
- }
1212
- }
1213
1211
mcLister := machineconfigv1listers .NewMachineConfigLister (mcIndexer )
1214
1212
1215
1213
nodeIndexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {})
@@ -1297,8 +1295,11 @@ func Test_sync_with_mcp(t *testing.T) {
1297
1295
now : func () metav1.Time { return now },
1298
1296
}
1299
1297
1300
- if err := initializeCaches (controller ); err != nil {
1301
- t .Errorf ("Failed to initialize caches: %v" , err )
1298
+ if tc .mcpToRemove != "" || tc .mcpToAdd != "" {
1299
+ // This is to initialize the caches
1300
+ if err := syncOnceWithAnUnrecognizableKey (controller ); err == nil {
1301
+ t .Fatalf ("Expected sync error did not occur" )
1302
+ }
1302
1303
}
1303
1304
1304
1305
if tc .mcpToRemove != "" {
0 commit comments