@@ -22,7 +22,7 @@ import (
2222
2323 "github.com/rabbitmq/cluster-operator/internal/resource"
2424 "github.com/rabbitmq/cluster-operator/internal/status"
25- "k8s.io/apimachinery/pkg/api/errors"
25+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
2626 "k8s.io/client-go/kubernetes"
2727 "k8s.io/client-go/rest"
2828 "k8s.io/client-go/tools/record"
@@ -89,7 +89,7 @@ func (r *RabbitmqClusterReconciler) Reconcile(ctx context.Context, req ctrl.Requ
8989
9090 if client .IgnoreNotFound (err ) != nil {
9191 return ctrl.Result {}, err
92- } else if errors .IsNotFound (err ) {
92+ } else if k8serrors .IsNotFound (err ) {
9393 // No need to requeue if the resource no longer exists
9494 return ctrl.Result {}, nil
9595 }
@@ -163,13 +163,31 @@ func (r *RabbitmqClusterReconciler) Reconcile(ctx context.Context, req ctrl.Requ
163163
164164 // only StatefulSetBuilder returns true
165165 if builder .UpdateMayRequireStsRecreate () {
166- if err = r .reconcilePVC (ctx , builder , rabbitmqCluster , resource ); err != nil {
167- rabbitmqCluster .Status .SetCondition (status .ReconcileSuccess , corev1 .ConditionFalse , "FailedReconcilePVC" , err .Error ())
168- if statusErr := r .Status ().Update (ctx , rabbitmqCluster ); statusErr != nil {
169- logger .Error (statusErr , "Failed to update ReconcileSuccess condition state" )
170- }
166+ sts := resource .(* appsv1.StatefulSet )
167+
168+ current , err := r .statefulSet (ctx , rabbitmqCluster )
169+ if client .IgnoreNotFound (err ) != nil {
171170 return ctrl.Result {}, err
172171 }
172+
173+ // only checks for PVC expansion and scale down if statefulSet is created
174+ // else continue to CreateOrUpdate()
175+ if ! k8serrors .IsNotFound (err ) {
176+ if err := builder .Update (sts ); err != nil {
177+ return ctrl.Result {}, err
178+ }
179+ if err = r .reconcilePVC (ctx , rabbitmqCluster , current , sts ); err != nil {
180+ rabbitmqCluster .Status .SetCondition (status .ReconcileSuccess , corev1 .ConditionFalse , "FailedReconcilePVC" , err .Error ())
181+ if statusErr := r .Status ().Update (ctx , rabbitmqCluster ); statusErr != nil {
182+ logger .Error (statusErr , "Failed to update ReconcileSuccess condition state" )
183+ }
184+ return ctrl.Result {}, err
185+ }
186+ if r .scaleDown (ctx , rabbitmqCluster , current , sts ) {
187+ // return when cluster scale down detected; unsupported operation
188+ return ctrl.Result {}, nil
189+ }
190+ }
173191 }
174192
175193 var operationResult controllerutil.OperationResult
@@ -269,7 +287,7 @@ func (r *RabbitmqClusterReconciler) updateStatus(ctx context.Context, rmq *rabbi
269287
270288 if ! reflect .DeepEqual (rmq .Status .Conditions , oldConditions ) {
271289 if err = r .Status ().Update (ctx , rmq ); err != nil {
272- if errors .IsConflict (err ) {
290+ if k8serrors .IsConflict (err ) {
273291 logger .Info ("failed to update status because of conflict; requeueing..." ,
274292 "namespace" , rmq .Namespace ,
275293 "name" , rmq .Name )
@@ -287,17 +305,17 @@ func (r *RabbitmqClusterReconciler) getChildResources(ctx context.Context, rmq *
287305
288306 if err := r .Client .Get (ctx ,
289307 types.NamespacedName {Name : rmq .ChildResourceName ("server" ), Namespace : rmq .Namespace },
290- sts ); err != nil && ! errors .IsNotFound (err ) {
308+ sts ); err != nil && ! k8serrors .IsNotFound (err ) {
291309 return nil , err
292- } else if errors .IsNotFound (err ) {
310+ } else if k8serrors .IsNotFound (err ) {
293311 sts = nil
294312 }
295313
296314 if err := r .Client .Get (ctx ,
297315 types.NamespacedName {Name : rmq .ChildResourceName (resource .ServiceSuffix ), Namespace : rmq .Namespace },
298- endPoints ); err != nil && ! errors .IsNotFound (err ) {
316+ endPoints ); err != nil && ! k8serrors .IsNotFound (err ) {
299317 return nil , err
300- } else if errors .IsNotFound (err ) {
318+ } else if k8serrors .IsNotFound (err ) {
301319 endPoints = nil
302320 }
303321
0 commit comments