github.com/kubeflow/training-operator@v1.7.0/pkg/core/status.go (about) 1 /* 2 Copyright 2023 The Kubeflow Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package core 18 19 import ( 20 apiv1 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v1" 21 corev1 "k8s.io/api/core/v1" 22 ) 23 24 // InitializeReplicaStatuses initializes the ReplicaStatuses for replica. 25 func InitializeReplicaStatuses(jobStatus *apiv1.JobStatus, rtype apiv1.ReplicaType) { 26 if jobStatus.ReplicaStatuses == nil { 27 jobStatus.ReplicaStatuses = make(map[apiv1.ReplicaType]*apiv1.ReplicaStatus) 28 } 29 30 jobStatus.ReplicaStatuses[rtype] = &apiv1.ReplicaStatus{} 31 } 32 33 // UpdateJobReplicaStatuses updates the JobReplicaStatuses according to the pod. 34 func UpdateJobReplicaStatuses(jobStatus *apiv1.JobStatus, rtype apiv1.ReplicaType, pod *corev1.Pod) { 35 switch pod.Status.Phase { 36 case corev1.PodRunning: 37 if pod.DeletionTimestamp != nil { 38 // when node is not ready, the pod will be in terminating state. 39 // Count deleted Pods as failures to account for orphan Pods that 40 // never have a chance to reach the Failed phase. 41 jobStatus.ReplicaStatuses[rtype].Failed++ 42 } else { 43 jobStatus.ReplicaStatuses[rtype].Active++ 44 } 45 case corev1.PodSucceeded: 46 jobStatus.ReplicaStatuses[rtype].Succeeded++ 47 case corev1.PodFailed: 48 jobStatus.ReplicaStatuses[rtype].Failed++ 49 } 50 }