@@ -503,7 +503,6 @@ var _ = Describe("MySQL user controller", func() {
503503 // We need to make sure that the controller does not create infinite loops
504504 Consistently (requests ).ShouldNot (Receive (Equal (expectedRequest )))
505505 })
506-
507506 It ("removes the user finalizer, and the resource is deleted" , func () {
508507 fakeSQL .AllowExtraCalls ()
509508
@@ -520,6 +519,33 @@ var _ = Describe("MySQL user controller", func() {
520519 err := c .Get (context .TODO (), userKey , user .Unwrap ())
521520 Expect (apierrors .IsNotFound (err )).To (BeTrue ())
522521 })
522+ It ("removes the user finalizer, and the resource is deleted,database user retain" , func () {
523+ fakeSQL .AddExpectedCalls (func (query string , args ... interface {}) error {
524+ defer GinkgoRecover ()
525+
526+ PanicWith ("Shouldn't call this!" )
527+ return nil
528+ })
529+
530+ if user .ObjectMeta .Annotations == nil {
531+ user .ObjectMeta .Annotations = map [string ]string {}
532+ }
533+ user .ObjectMeta .Annotations [mysqlv1alpha1 .MysqlResourceDeletionPolicyAnnotationKey ] = string (mysqlv1alpha1 .MysqlResourceDeletionPolicyRetain )
534+
535+ Expect (c .Delete (context .TODO (), user .Unwrap ())).To (Succeed ())
536+ // Wait for initial reconciliation
537+ Eventually (requests , timeout ).Should (Receive (Equal (expectedRequest )))
538+
539+ // Wait for second reconciliation triggered by finalizer removal
540+ Eventually (requests , timeout ).Should (Receive (Equal (expectedRequest )))
541+
542+ // We need to make sure that the controller does not create infinite loops
543+ Consistently (requests ).ShouldNot (Receive (Equal (expectedRequest )))
544+
545+ err := c .Get (context .TODO (), userKey , user .Unwrap ())
546+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
547+ delete (user .ObjectMeta .Annotations , mysqlv1alpha1 .MysqlResourceDeletionPolicyAnnotationKey )
548+ })
523549 })
524550 Context ("and the user cannot be deleted in mysql" , func () {
525551 deletionResult := errors .New ("couldn't delete user" )
0 commit comments