Skip to content

Commit

Permalink
ignore completed Pod and SharePod in resource accounting
Browse files Browse the repository at this point in the history
  • Loading branch information
ncy9371 committed Apr 29, 2020
1 parent ba93352 commit 8e624ec
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/scheduler/sync_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func syncPodResources(nodeRes NodeResources, podList []*corev1.Pod, sharePodList
if nodeName == "" || strings.Contains(pod.Name, kubesharev1.KubeShareDummyPodName) {
continue
}
// If a Pod is owned by a MtpguPod, calculating their resource usage later.
// If a Pod is owned by a SharePod, calculating their resource usage later.
ownedBySharePod := false
for _, owneref := range pod.ObjectMeta.OwnerReferences {
if owneref.Kind == "SharePod" {
Expand All @@ -43,6 +43,14 @@ func syncPodResources(nodeRes NodeResources, podList []*corev1.Pod, sharePodList
continue
}

if (pod.Spec.RestartPolicy == corev1.RestartPolicyOnFailure &&
pod.Status.Phase == corev1.PodSucceeded) ||
(pod.Spec.RestartPolicy == corev1.RestartPolicyNever &&
(pod.Status.Phase == corev1.PodSucceeded ||
pod.Status.Phase == corev1.PodFailed)) {
continue
}

for _, container := range pod.Spec.Containers {
nodeRes[nodeName].CpuFree -= container.Resources.Requests.Cpu().MilliValue()
nodeRes[nodeName].MemFree -= container.Resources.Requests.Memory().MilliValue()
Expand All @@ -63,9 +71,10 @@ func syncPodResources(nodeRes NodeResources, podList []*corev1.Pod, sharePodList
continue
}
if sharePod.Status.PodStatus != nil {
if (sharePod.Spec.RestartPolicy == corev1.RestartPolicyAlways) ||
(sharePod.Spec.RestartPolicy == corev1.RestartPolicyOnFailure &&
sharePod.Status.PodStatus.Phase == corev1.PodSucceeded) ||
// why policy Always is ignored? why??? I forgot why wrote this then
// if (sharePod.Spec.RestartPolicy == corev1.RestartPolicyAlways) ||
if (sharePod.Spec.RestartPolicy == corev1.RestartPolicyOnFailure &&
sharePod.Status.PodStatus.Phase == corev1.PodSucceeded) ||
(sharePod.Spec.RestartPolicy == corev1.RestartPolicyNever &&
(sharePod.Status.PodStatus.Phase == corev1.PodSucceeded ||
sharePod.Status.PodStatus.Phase == corev1.PodFailed)) {
Expand Down

1 comment on commit 8e624ec

@ncy9371
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#7

Please sign in to comment.