Skip to content

Commit

Permalink
sync status of pod
Browse files Browse the repository at this point in the history
Signed-off-by: bruce <[email protected]>
  • Loading branch information
xyz2277 committed May 31, 2022
1 parent 519a385 commit ca50789
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pkg/resourceinterpreter/defaultinterpreter/aggregatestatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func getAllDefaultAggregateStatusInterpreter() map[schema.GroupVersionKind]aggre
s[batchv1.SchemeGroupVersion.WithKind(util.JobKind)] = aggregateJobStatus
s[appsv1.SchemeGroupVersion.WithKind(util.DaemonSetKind)] = aggregateDaemonSetStatus
s[appsv1.SchemeGroupVersion.WithKind(util.StatefulSetKind)] = aggregateStatefulSetStatus
s[corev1.SchemeGroupVersion.WithKind(util.PodKind)] = aggregatePodStatus
return s
}

Expand Down Expand Up @@ -264,3 +265,50 @@ func aggregateStatefulSetStatus(object *unstructured.Unstructured, aggregatedSta

return helper.ToUnstructured(statefulSet)
}

func aggregatePodStatus(object *unstructured.Unstructured, aggregatedStatusItems []workv1alpha2.AggregatedStatusItem) (*unstructured.Unstructured, error) {
pod, err := helper.ConvertToPod(object)
if err != nil {
return nil, err
}

newStatus := &corev1.PodStatus{}
newStatus.ContainerStatuses = make([]corev1.ContainerStatus, 0)
readySum := 0
containerSum := 0
for _, item := range aggregatedStatusItems {
if item.Status == nil {
continue
}

temp := &corev1.PodStatus{}
if err = json.Unmarshal(item.Status.Raw, temp); err != nil {
return nil, err
}

for _, containerStatus := range temp.ContainerStatuses {
tempStatus := containerStatus
newStatus.ContainerStatuses = append(newStatus.ContainerStatuses, tempStatus)
if tempStatus.Ready {
readySum++
}
containerSum++
}
klog.V(3).Infof("Grab pod(%s/%s) status from cluster(%s), phase: %s", pod.Namespace,
pod.Name, item.ClusterName, temp.Phase)
}

if reflect.DeepEqual(pod.Status, *newStatus) {
klog.V(3).Infof("ignore update pod(%s/%s) status as up to date", pod.Namespace, pod.Name)
return object, nil
}

if containerSum == readySum {
newStatus.Phase = corev1.PodRunning
} else {
newStatus.Phase = corev1.PodPending
}

pod.Status = *newStatus
return helper.ToUnstructured(pod)
}

0 comments on commit ca50789

Please sign in to comment.