0yukali0 commented on a change in pull request #281:
URL:
https://github.com/apache/incubator-yunikorn-k8shim/pull/281#discussion_r676701331
##########
File path: pkg/common/resource.go
##########
@@ -72,9 +72,31 @@ func GetPodResource(pod *v1.Pod) (resource *si.Resource) {
containerResource := getResource(resourceList)
podResource = Add(podResource, containerResource)
}
+
+ // vcore, mem compare between initcontainer and containers and
replace(choose bigger one)
+ if pod.Spec.InitContainers != nil {
+ IsNeedMoreResourceAndSet(pod, podResource)
+ }
+
return podResource
}
+func IsNeedMoreResourceAndSet(pod *v1.Pod, containersResources *si.Resource) {
+ for _, c := range pod.Spec.InitContainers {
+ resourceList := c.Resources.Requests
+ initCResource := getResource(resourceList)
+ for resouceName, v1 := range initCResource.Resources {
+ v2, exist := containersResources.Resources[resouceName]
+ if !exist {
+ continue
+ }
+ if v1.GetValue() > v2.GetValue() {
+ containersResources.Resources[resouceName] = v1
Review comment:
Thank you for advise, i will modify it with replace.
This code idea is from k8s default scheduler.
k8s default scheduler make assigned node has enough allocated resource to
handle max resource requirement in pod.
Calculation function: podResourceRequest = max(sum(podSpec.Containers),
podSpec.InitContainers) + overHead
k8s doc of initcontainer describe requirement of resource usage.
related doc:
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#resources
It show up in default scheduler predicate and score.
prefilter and filter use the calculation function to check if node has
enough allocated resource for max requirement in pod.
related code:
https://github.com/kubernetes/kubernetes/blob/master/pkg/scheduler/framework/plugins/noderesources/fit.go#L135-L179
https://github.com/kubernetes/kubernetes/blob/eae87bfe7e9636694a5cb45a9863715b7b25435c/pkg/scheduler/framework/plugins/noderesources/resource_allocation.go#L108-L135
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]