@@ -211,6 +211,47 @@ func DeleteAndVerifyDeployments(t *testing.T, clients *test.Clients, names test.
211211 t .Logf ("The deployment %s/%s reached the desired state." , deployment .Namespace , deployment .Name )
212212}
213213
214+ // DeleteAndVerifyConfigMaps verify whether all the ConfigMaps for knative serving are able to recreate, when they are deleted.
215+ func DeleteAndVerifyConfigMaps (t * testing.T , clients * test.Clients , names test.ResourceNames ) {
216+ cmList , err := clients .KubeClient .CoreV1 ().ConfigMaps (names .Namespace ).List (context .TODO (), metav1.ListOptions {})
217+ if err != nil {
218+ t .Fatalf ("Failed to get any ConfigMap under the namespace %q: %v" ,
219+ test .ServingOperatorNamespace , err )
220+ }
221+ if len (cmList .Items ) == 0 {
222+ t .Fatalf ("No ConfigMap under the namespace %q was found" ,
223+ test .ServingOperatorNamespace )
224+ }
225+ // Delete the first ConfigMap and verify the operator recreates it
226+ configMap := cmList .Items [0 ]
227+ if err := clients .KubeClient .CoreV1 ().ConfigMaps (configMap .Namespace ).Delete (context .TODO (), configMap .Name , metav1.DeleteOptions {}); err != nil {
228+ t .Fatalf ("Failed to delete ConfigMap %s/%s: %v" , configMap .Namespace , configMap .Name , err )
229+ }
230+
231+ waitErr := wait .PollUntilContextTimeout (context .TODO (), Interval , Timeout , true , func (context.Context ) (bool , error ) {
232+ _ , err := clients .KubeClient .CoreV1 ().ConfigMaps (configMap .Namespace ).Get (context .TODO (), configMap .Name , metav1.GetOptions {})
233+ if err != nil {
234+ // If the ConfigMap is not found, we continue to wait for the availability.
235+ if apierrs .IsNotFound (err ) {
236+ return false , nil
237+ }
238+ return false , err
239+ }
240+ // For ConfigMaps, we consider it recreated as soon as it reappears.
241+ return true , nil
242+ })
243+
244+ if waitErr != nil {
245+ t .Fatalf ("The ConfigMap %s/%s failed to be recreated: %v" , configMap .Namespace , configMap .Name , err )
246+ }
247+
248+ if _ , err := WaitForKnativeServingState (clients .KnativeServing (), test .OperatorName ,
249+ IsKnativeServingReady ); err != nil {
250+ t .Fatalf ("KnativeService %q failed to reach the desired state: %v" , test .OperatorName , err )
251+ }
252+ t .Logf ("The ConfigMap %s/%s was successfully recreated." , configMap .Namespace , configMap .Name )
253+ }
254+
214255// KSOperatorCRDelete deletes tha KnativeServing to see if all resources will be deleted
215256func KSOperatorCRDelete (t * testing.T , clients * test.Clients , names test.ResourceNames ) {
216257 if err := clients .KnativeServing ().Delete (context .TODO (), names .KnativeServing , metav1.DeleteOptions {}); err != nil {
@@ -399,6 +440,46 @@ func DeleteAndVerifyEventingDeployments(t *testing.T, clients *test.Clients, nam
399440 t .Logf ("The deployment %s/%s reached the desired state." , deployment .Namespace , deployment .Name )
400441}
401442
443+ // DeleteAndVerifyEventingConfigMaps verify whether all the ConfigMaps for knative eventing are able to recreate, when they are deleted.
444+ func DeleteAndVerifyEventingConfigMaps (t * testing.T , clients * test.Clients , names test.ResourceNames ) {
445+ cmList , err := clients .KubeClient .CoreV1 ().ConfigMaps (names .Namespace ).List (context .TODO (), metav1.ListOptions {})
446+ if err != nil {
447+ t .Fatalf ("Failed to get any ConfigMap under the namespace %q: %v" ,
448+ test .EventingOperatorNamespace , err )
449+ }
450+ if len (cmList .Items ) == 0 {
451+ t .Fatalf ("No ConfigMap under the namespace %q was found" ,
452+ test .EventingOperatorNamespace )
453+ }
454+ // Delete the first ConfigMap and verify the operator recreates it
455+ configMap := cmList .Items [0 ]
456+ if err := clients .KubeClient .CoreV1 ().ConfigMaps (configMap .Namespace ).Delete (context .TODO (), configMap .Name , metav1.DeleteOptions {}); err != nil {
457+ t .Fatalf ("Failed to delete ConfigMap %s/%s: %v" , configMap .Namespace , configMap .Name , err )
458+ }
459+
460+ waitErr := wait .PollUntilContextTimeout (context .TODO (), Interval , Timeout , true , func (context.Context ) (bool , error ) {
461+ _ , err := clients .KubeClient .CoreV1 ().ConfigMaps (configMap .Namespace ).Get (context .TODO (), configMap .Name , metav1.GetOptions {})
462+ if err != nil {
463+ // If the ConfigMap is not found, we continue to wait for the availability.
464+ if apierrs .IsNotFound (err ) {
465+ return false , nil
466+ }
467+ return false , err
468+ }
469+ return true , nil
470+ })
471+
472+ if waitErr != nil {
473+ t .Fatalf ("The ConfigMap %s/%s failed to reach the desired state: %v" , configMap .Namespace , configMap .Name , err )
474+ }
475+
476+ if _ , err := WaitForKnativeEventingState (clients .KnativeEventing (), test .OperatorName ,
477+ IsKnativeEventingReady ); err != nil {
478+ t .Fatalf ("KnativeService %q failed to reach the desired state: %v" , test .OperatorName , err )
479+ }
480+ t .Logf ("The ConfigMap %s/%s reached the desired state." , configMap .Namespace , configMap .Name )
481+ }
482+
402483// KEOperatorCRDelete deletes tha KnativeEventing to see if all resources will be deleted
403484func KEOperatorCRDelete (t * testing.T , clients * test.Clients , names test.ResourceNames ) {
404485 if err := clients .KnativeEventing ().Delete (context .TODO (), names .KnativeEventing , metav1.DeleteOptions {}); err != nil {
0 commit comments