Skip to content

Commit

Permalink
fix pod request according to kubernetes which initContainers and PodO…
Browse files Browse the repository at this point in the history
…verhead should be calculated
  • Loading branch information
fighterhit committed Aug 21, 2021
1 parent 431e5e5 commit 4d63403
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,15 @@ package util
import (
"github.com/virtual-kubelet/tensile-kube/pkg/common"
corev1 "k8s.io/api/core/v1"
resourcehelper "k8s.io/kubernetes/pkg/api/v1/resource"
)

// GetRequestFromContainer get resources required by container
func GetRequestFromContainer(container *corev1.Container) *common.Resource {
resources := container.Resources.Requests
if resources == nil {
resources = container.Resources.Limits
if resources == nil {
resources = corev1.ResourceList{}
}
}
capacity := common.ConvertResource(resources)
return capacity
}

// GetRequestFromPod get resources required by pod
func GetRequestFromPod(pod *corev1.Pod) *common.Resource {
if pod == nil {
return nil
}
capacity := common.Resource{Custom: common.CustomResources{}}
for _, container := range pod.Spec.Containers {
res := GetRequestFromContainer(&container)
capacity.Add(res)
}
return &capacity
reqs, _ := resourcehelper.PodRequestsAndLimits(pod)
capacity := common.ConvertResource(reqs)
return capacity
}

0 comments on commit 4d63403

Please sign in to comment.