@@ -186,29 +186,33 @@ func (r *ReconcilePerconaServerMongoDB) deleteReplsetPods(ctx context.Context, c
186186 return pods .Items [i ].Name < pods .Items [j ].Name
187187 })
188188
189- switch * sts . Spec . Replicas {
190- case 0 :
189+ switch {
190+ case * sts . Spec . Replicas == 0 :
191191 rs .Size = 0
192192 if len (pods .Items ) == 0 {
193193 return nil
194194 }
195195 return errWaitingTermination
196- case 1 :
196+ case * sts . Spec . Replicas == 1 || len ( pods . Items ) == 1 :
197197 rs .Size = 1
198198 // If there is one pod left, we need to be sure that it's the primary.
199199 if len (pods .Items ) != 1 {
200200 return errWaitingTermination
201201 }
202202
203- isPrimary , err := r .isPodPrimary (ctx , cr , pods .Items [0 ], rs )
204- if err != nil {
205- return errors .Wrap (err , "is pod primary" )
206- }
207- if ! isPrimary {
208- return errWaitingFirstPrimary
203+ firstPod := pods .Items [0 ]
204+ // If it's not ready, we can delete it
205+ if isContainerAndPodRunning (firstPod , "mongod" ) && isPodReady (firstPod ) {
206+ isPrimary , err := r .isPodPrimary (ctx , cr , firstPod , rs )
207+ if err != nil {
208+ return errors .Wrap (err , "is pod primary" )
209+ }
210+ if ! isPrimary {
211+ return errWaitingFirstPrimary
212+ }
213+ // If true, we should resize the replset to 0
209214 }
210215
211- // If true, we should resize the replset to 0
212216 rs .Size = 0
213217 return errWaitingTermination
214218 default :
0 commit comments