tflobbe commented on code in PR #561: URL: https://github.com/apache/solr-operator/pull/561#discussion_r1199178613
########## controllers/solr_cluster_ops_util.go: ########## @@ -210,9 +219,43 @@ func evictSinglePod(ctx context.Context, r *SolrCloudReconciler, instance *solrv } // Only evict from the pod if it contains replicas in the clusterState - if err, podIsEmpty = util.EvictReplicasForPodIfNecessary(ctx, instance, pod, podHasReplicas, "scaleDown", logger); err != nil { + if e, canDeletePod := util.EvictReplicasForPodIfNecessary(ctx, instance, pod, podHasReplicas, "scaleDown", logger); e != nil { + err = e logger.Error(err, "Error while evicting replicas on Pod, when scaling down SolrCloud", "pod", pod.Name) + } else if canDeletePod { + // The pod previously had replicas, so loop back in the next reconcile to make sure that the pod doesn't + // have replicas anymore even if the previous evict command was successful. + // If there are still replicas, it will start the eviction process again + podIsEmpty = !podHasReplicas } return } + +func getReplicasForPod(ctx context.Context, cloud *solrv1beta1.SolrCloud, podName string, logger logr.Logger) (replicas []string, err error) { + clusterResp := &solr_api.SolrClusterStatusResponse{} + queryParams := url.Values{} + queryParams.Add("action", "CLUSTERSTATUS") + err = solr_api.CallCollectionsApi(ctx, cloud, queryParams, clusterResp) + if err == nil { + if hasError, apiErr := solr_api.CheckForCollectionsApiError("CLUSTERSTATUS", clusterResp.ResponseHeader); hasError { + err = apiErr + } + } + podNodeName := util.SolrNodeName(cloud, podName) + if err == nil { + for _, colState := range clusterResp.ClusterStatus.Collections { + for _, shardState := range colState.Shards { + for replica, replicaState := range shardState.Replicas { + if replicaState.NodeName == podNodeName { + replicas = append(replicas, replica) + } + } + } + } + } + if err != nil { Review Comment: Why not `else`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org