@@ -50,6 +50,7 @@ import (
5050 "github.com/rabbitmq/rabbitmq-stream-go-client/pkg/message"
5151 "github.com/rabbitmq/rabbitmq-stream-go-client/pkg/stream"
5252 corev1 "k8s.io/api/core/v1"
53+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
5354 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5455 "k8s.io/apimachinery/pkg/types"
5556 "k8s.io/client-go/kubernetes"
@@ -62,6 +63,11 @@ import (
6263const podCreationTimeout = 10 * time .Minute
6364const portReadinessTimeout = 1 * time .Minute
6465const k8sQueryTimeout = 1 * time .Minute
66+ const clusterDeletionTimeout = 90 * time .Second
67+
68+ // A create is rejected while a cluster of the same name is still terminating, so the retry needs
69+ // to cover a deletion.
70+ const clusterCreationTimeout = clusterDeletionTimeout
6571
6672type featureFlag struct {
6773 Name string
@@ -507,6 +513,32 @@ func createRabbitmqCluster(ctx context.Context, client client.Client, rabbitmqCl
507513 return client .Create (ctx , rabbitmqCluster )
508514}
509515
516+ // deleteRabbitmqClusterAndWait deletes a RabbitmqCluster and waits for it to disappear. Delete only
517+ // marks it: the operator's finalizer keeps the object in Terminating for a few seconds, and
518+ // recreating the same name before then fails with "object is being deleted ... already exists".
519+ func deleteRabbitmqClusterAndWait (ctx context.Context , c client.Client , cluster * rabbitmqv1beta1.RabbitmqCluster ) {
520+ GinkgoHelper ()
521+
522+ Expect (client .IgnoreNotFound (c .Delete (ctx , cluster ))).To (Succeed ())
523+
524+ key := types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }
525+ Eventually (ctx , func () error {
526+ var current rabbitmqv1beta1.RabbitmqCluster
527+ err := c .Get (ctx , key , & current )
528+ if k8serrors .IsNotFound (err ) {
529+ return nil
530+ }
531+ if err != nil {
532+ return err
533+ }
534+ return fmt .Errorf ("RabbitmqCluster %s is still present (deletionTimestamp: %v, finalizers: %v)" ,
535+ key , current .DeletionTimestamp , current .Finalizers )
536+ }).
537+ WithTimeout (clusterDeletionTimeout ).
538+ WithPolling (2 * time .Second ).
539+ Should (Succeed ())
540+ }
541+
510542func statefulSetPodName (cluster * rabbitmqv1beta1.RabbitmqCluster , index int ) string {
511543 return cluster .ChildResourceName (strings .Join ([]string {"server" , strconv .Itoa (index )}, "-" ))
512544}
0 commit comments