in controllers/solr_pod_lifecycle_util.go [49:116]
func DeletePodForUpdate(ctx context.Context, r *SolrCloudReconciler, instance *solrv1beta1.SolrCloud, pod *corev1.Pod, podHasReplicas bool, logger logr.Logger) (requeueAfterDuration time.Duration, requestInProgress bool, err error) {
// Before doing anything to the pod, make sure that users cannot send requests to the pod anymore.
ps := PodStarted
podStoppedReadinessConditions := map[corev1.PodConditionType]podReadinessConditionChange{
util.SolrIsNotStoppedReadinessCondition: {
reason: PodUpdate,
message: "Pod is being deleted, traffic to the pod must be stopped",
status: false,
},
util.SolrReplicasNotEvictedReadinessCondition: {
// Only set this condition if the condition hasn't been changed since pod start
// We do not want to over-write future states later down the eviction pipeline
matchPreviousReason: &ps,
reason: EvictingReplicas,
message: "Pod is being deleted, ephemeral data must be evicted",
status: false,
},
}
if updatedPod, e := EnsurePodReadinessConditions(ctx, r, pod, podStoppedReadinessConditions, logger); e != nil {
err = e
return
} else {
pod = updatedPod
}
// If the pod needs to be drained of replicas (i.e. upgrading a pod with ephemeral storage), do that before deleting the pod
deletePod := false
if PodConditionEquals(pod, util.SolrReplicasNotEvictedReadinessCondition, EvictingReplicas) {
// Only evict pods that contain replicas in the clusterState
if evictError, canDeletePod, inProgTmp := util.EvictReplicasForPodIfNecessary(ctx, instance, pod, podHasReplicas, "podUpdate", logger); evictError != nil {
requestInProgress = true
err = evictError
logger.Error(err, "Error while evicting replicas on pod", "pod", pod.Name)
} else if canDeletePod {
requestInProgress = inProgTmp
if podHasReplicas {
// 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
requeueAfterDuration = time.Millisecond * 10
} else {
deletePod = true
}
} else {
requestInProgress = inProgTmp
// Try again in 5 seconds if we cannot delete a pod.
requeueAfterDuration = time.Second * 5
}
} else {
// If a pod has no replicas, then update it when asked to
deletePod = true
}
// Delete the pod
if deletePod {
logger.Info("Deleting solr pod for update", "pod", pod.Name)
err = r.Delete(ctx, pod, client.Preconditions{
UID: &pod.UID,
})
if err != nil {
logger.Error(err, "Error while killing solr pod for update", "pod", pod.Name)
}
// TODO: Create event for the CRD.
}
return
}