in pkg/controller/sub_controller/sub_controller.go [112:159]
func (d *SubDefaultController) ClassifyPodsByStatus(namespace string, status *dorisv1.ComponentStatus, labels map[string]string, replicas int32, componentType dorisv1.ComponentType) error {
var podList corev1.PodList
if err := d.K8sclient.List(context.Background(), &podList, client.InNamespace(namespace), client.MatchingLabels(labels)); err != nil {
return err
}
var creatings, readys, faileds []string
podmap := make(map[string]corev1.Pod)
if len(podList.Items) == 0 {
return nil
}
restartAnnotationsKey := dorisv1.GetRestartAnnotationKey(componentType)
firstRestartAnnotation := podList.Items[0].Annotations[restartAnnotationsKey]
//get all pod status that controlled by st.
stsRollingRestartAnnotationsSameCheck := true
for _, pod := range podList.Items {
if pod.Annotations[restartAnnotationsKey] != firstRestartAnnotation {
stsRollingRestartAnnotationsSameCheck = false
}
podmap[pod.Name] = pod
if ready := k8s.PodIsReady(&pod.Status); ready {
readys = append(readys, pod.Name)
} else if pod.Status.Phase == corev1.PodRunning || pod.Status.Phase == corev1.PodPending {
creatings = append(creatings, pod.Name)
} else {
faileds = append(faileds, pod.Name)
}
}
if len(readys) == int(replicas) && stsRollingRestartAnnotationsSameCheck {
status.ComponentCondition.Phase = dorisv1.Available
} else if len(faileds) != 0 {
status.ComponentCondition.Phase = dorisv1.HaveMemberFailed
status.ComponentCondition.Reason = podmap[faileds[0]].Status.Reason
status.ComponentCondition.Message = podmap[faileds[0]].Status.Message
} else if len(creatings) != 0 {
status.ComponentCondition.Reason = podmap[creatings[0]].Status.Reason
status.ComponentCondition.Message = podmap[creatings[0]].Status.Message
}
status.RunningMembers = readys
status.FailedMembers = faileds
status.CreatingMembers = creatings
return nil
}