@@ -444,7 +444,6 @@ var _ = Describe("Test NUMAResourcesOperator Reconcile", func() {
444
444
By (fmt .Sprintf ("Check that container %s image did not change" , cnt .Name ))
445
445
Expect (cnt .Image ).To (Equal ("madeup-image:1" ))
446
446
})
447
-
448
447
})
449
448
})
450
449
@@ -1122,6 +1121,180 @@ var _ = Describe("Test NUMAResourcesOperator Reconcile", func() {
1122
1121
Expect (nro ).To (BeDegradedWithReason (validation .NodeGroupsError ))
1123
1122
})
1124
1123
})
1124
+
1125
+ When ("the NRT API definition annotation is provided" , Label ("feature:nrtcrdanns" ), func () {
1126
+ var nro * nropv1.NUMAResourcesOperator
1127
+ var mcp1 * machineconfigv1.MachineConfigPool
1128
+ var mcp1Selector * metav1.LabelSelector
1129
+ var nroKey client.ObjectKey
1130
+
1131
+ var reconciler * NUMAResourcesOperatorReconciler
1132
+ var ng1 nropv1.NodeGroup
1133
+
1134
+ pn1 := "test1"
1135
+
1136
+ BeforeEach (func () {
1137
+ mcp1Selector = & metav1.LabelSelector {
1138
+ MatchLabels : map [string ]string {
1139
+ pn1 : pn1 ,
1140
+ },
1141
+ }
1142
+ ng1 = nropv1.NodeGroup {
1143
+ PoolName : & pn1 ,
1144
+ }
1145
+
1146
+ nro = testobjs .NewNUMAResourcesOperator (objectnames .DefaultNUMAResourcesOperatorCrName , ng1 )
1147
+ nroKey = client .ObjectKeyFromObject (nro )
1148
+
1149
+ mcp1 = testobjs .NewMachineConfigPool (pn1 , mcp1Selector .MatchLabels , mcp1Selector , mcp1Selector )
1150
+
1151
+ var err error
1152
+ reconciler , err = NewFakeNUMAResourcesOperatorReconciler (platf , defaultOCPVersion , nro , mcp1 )
1153
+ Expect (err ).ToNot (HaveOccurred ())
1154
+ })
1155
+
1156
+ It ("should be NOT create the CRD object while the annotation is present" , func () {
1157
+ Eventually (func () error {
1158
+ nroUpdated := & nropv1.NUMAResourcesOperator {}
1159
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , nroUpdated )).To (Succeed ())
1160
+ if nroUpdated .Annotations == nil {
1161
+ nroUpdated .Annotations = make (map [string ]string )
1162
+ }
1163
+ nroUpdated .Annotations [annotations .NRTAPIDefinitionAnnotation ] = annotations .NRTAPIFromCluster
1164
+ return reconciler .Client .Update (context .TODO (), nroUpdated )
1165
+ }).WithPolling (1 * time .Second ).WithTimeout (30 * time .Second ).Should (Succeed ())
1166
+
1167
+ Expect (reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : nroKey })).ToNot (CauseRequeue ())
1168
+
1169
+ nroUpdated := & nropv1.NUMAResourcesOperator {}
1170
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , nroUpdated )).To (Succeed ())
1171
+
1172
+ availableCondition := getConditionByType (nroUpdated .Status .Conditions , status .ConditionAvailable )
1173
+ Expect (availableCondition ).ToNot (BeNil ())
1174
+ Expect (availableCondition .Status ).To (Equal (metav1 .ConditionTrue ))
1175
+
1176
+ crd := & apiextensionsv1.CustomResourceDefinition {}
1177
+ crdKey := client.ObjectKey {
1178
+ Name : "noderesourcetopologies.topology.node.k8s.io" ,
1179
+ }
1180
+ err := reconciler .Client .Get (context .TODO (), crdKey , crd )
1181
+ Expect (apierrors .IsNotFound (err )).To (BeTrue (), "unexpected error: %v" , err )
1182
+ })
1183
+
1184
+ It ("should stop reconciling the CRD object while the annotation is present" , func () {
1185
+ // ensure no annotations. Just to be sure
1186
+ Eventually (func () error {
1187
+ nroUpdated := & nropv1.NUMAResourcesOperator {}
1188
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , nroUpdated )).To (Succeed ())
1189
+ nroUpdated .Annotations = nil
1190
+ return reconciler .Client .Update (context .TODO (), nroUpdated )
1191
+ }).WithPolling (1 * time .Second ).WithTimeout (30 * time .Second ).Should (Succeed ())
1192
+
1193
+ Expect (reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : nroKey })).ToNot (CauseRequeue ())
1194
+
1195
+ var nroUpdated nropv1.NUMAResourcesOperator
1196
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , & nroUpdated )).To (Succeed ())
1197
+
1198
+ availableCondition := getConditionByType (nroUpdated .Status .Conditions , status .ConditionAvailable )
1199
+ Expect (availableCondition ).ToNot (BeNil ())
1200
+ Expect (availableCondition .Status ).To (Equal (metav1 .ConditionTrue ))
1201
+
1202
+ var crd apiextensionsv1.CustomResourceDefinition
1203
+ crdKey := client.ObjectKey {
1204
+ Name : "noderesourcetopologies.topology.node.k8s.io" ,
1205
+ }
1206
+ Expect (reconciler .Client .Get (context .TODO (), crdKey , & crd )).To (Succeed ())
1207
+
1208
+ Eventually (func () error {
1209
+ nroUpdated := & nropv1.NUMAResourcesOperator {}
1210
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , nroUpdated )).To (Succeed ())
1211
+ if nroUpdated .Annotations == nil {
1212
+ nroUpdated .Annotations = make (map [string ]string )
1213
+ }
1214
+ nroUpdated .Annotations [annotations .NRTAPIDefinitionAnnotation ] = annotations .NRTAPIFromCluster
1215
+ return reconciler .Client .Update (context .TODO (), nroUpdated )
1216
+ }).WithPolling (1 * time .Second ).WithTimeout (30 * time .Second ).Should (Succeed ())
1217
+
1218
+ Expect (reconciler .Client .Delete (context .TODO (), & crd )).To (Succeed ())
1219
+
1220
+ Expect (reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : nroKey })).ToNot (CauseRequeue ())
1221
+
1222
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , & nroUpdated )).To (Succeed ())
1223
+
1224
+ availableCondition = getConditionByType (nroUpdated .Status .Conditions , status .ConditionAvailable )
1225
+ Expect (availableCondition ).ToNot (BeNil ())
1226
+ Expect (availableCondition .Status ).To (Equal (metav1 .ConditionTrue ))
1227
+
1228
+ err := reconciler .Client .Get (context .TODO (), crdKey , & crd )
1229
+ Expect (apierrors .IsNotFound (err )).To (BeTrue (), "unexpected error: %v" , err )
1230
+ })
1231
+
1232
+ It ("should reconcile again the CRD object when the annotation is removed" , func () {
1233
+ // ensure no annotations. Just to be sure
1234
+ Eventually (func () error {
1235
+ nroUpdated := & nropv1.NUMAResourcesOperator {}
1236
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , nroUpdated )).To (Succeed ())
1237
+ nroUpdated .Annotations = nil
1238
+ return reconciler .Client .Update (context .TODO (), nroUpdated )
1239
+ }).WithPolling (1 * time .Second ).WithTimeout (30 * time .Second ).Should (Succeed ())
1240
+
1241
+ Expect (reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : nroKey })).ToNot (CauseRequeue ())
1242
+
1243
+ var nroUpdated nropv1.NUMAResourcesOperator
1244
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , & nroUpdated )).To (Succeed ())
1245
+
1246
+ availableCondition := getConditionByType (nroUpdated .Status .Conditions , status .ConditionAvailable )
1247
+ Expect (availableCondition ).ToNot (BeNil ())
1248
+ Expect (availableCondition .Status ).To (Equal (metav1 .ConditionTrue ))
1249
+
1250
+ var crd apiextensionsv1.CustomResourceDefinition
1251
+ crdKey := client.ObjectKey {
1252
+ Name : "noderesourcetopologies.topology.node.k8s.io" ,
1253
+ }
1254
+ Expect (reconciler .Client .Get (context .TODO (), crdKey , & crd )).To (Succeed ())
1255
+
1256
+ Eventually (func () error {
1257
+ nroUpdated := & nropv1.NUMAResourcesOperator {}
1258
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , nroUpdated )).To (Succeed ())
1259
+ if nroUpdated .Annotations == nil {
1260
+ nroUpdated .Annotations = make (map [string ]string )
1261
+ }
1262
+ nroUpdated .Annotations [annotations .NRTAPIDefinitionAnnotation ] = annotations .NRTAPIFromCluster
1263
+ return reconciler .Client .Update (context .TODO (), nroUpdated )
1264
+ }).WithPolling (1 * time .Second ).WithTimeout (30 * time .Second ).Should (Succeed ())
1265
+
1266
+ Expect (reconciler .Client .Delete (context .TODO (), & crd )).To (Succeed ())
1267
+
1268
+ Expect (reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : nroKey })).ToNot (CauseRequeue ())
1269
+
1270
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , & nroUpdated )).To (Succeed ())
1271
+
1272
+ availableCondition = getConditionByType (nroUpdated .Status .Conditions , status .ConditionAvailable )
1273
+ Expect (availableCondition ).ToNot (BeNil ())
1274
+ Expect (availableCondition .Status ).To (Equal (metav1 .ConditionTrue ))
1275
+
1276
+ err := reconciler .Client .Get (context .TODO (), crdKey , & crd )
1277
+ Expect (apierrors .IsNotFound (err )).To (BeTrue (), "unexpected error: %v" , err )
1278
+
1279
+ Eventually (func () error {
1280
+ nroUpdated := & nropv1.NUMAResourcesOperator {}
1281
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , nroUpdated )).To (Succeed ())
1282
+ nroUpdated .Annotations = nil
1283
+ return reconciler .Client .Update (context .TODO (), nroUpdated )
1284
+ }).WithPolling (1 * time .Second ).WithTimeout (30 * time .Second ).Should (Succeed ())
1285
+
1286
+ Expect (reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : nroKey })).ToNot (CauseRequeue ())
1287
+
1288
+ Expect (reconciler .Client .Get (context .TODO (), nroKey , & nroUpdated )).To (Succeed ())
1289
+
1290
+ availableCondition = getConditionByType (nroUpdated .Status .Conditions , status .ConditionAvailable )
1291
+ Expect (availableCondition ).ToNot (BeNil ())
1292
+ Expect (availableCondition .Status ).To (Equal (metav1 .ConditionTrue ))
1293
+
1294
+ Expect (reconciler .Client .Get (context .TODO (), crdKey , & crd )).To (Succeed ())
1295
+ })
1296
+ })
1297
+
1125
1298
},
1126
1299
Entry ("Openshift Platform" , platform .OpenShift ),
1127
1300
Entry ("Hypershift Platform" , platform .HyperShift ),
0 commit comments