Add utility for determining qos of a pod

This commit is contained in:
derekwaynecarr
2016-04-21 16:58:06 -04:00
parent 5555f6e118
commit 2b9cfd414d
2 changed files with 124 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ package util
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/sets"
)
const (
@@ -46,6 +47,25 @@ func isResourceBestEffort(container *api.Container, resource api.ResourceName) b
return !hasReq || req.Value() == 0
}
// GetPodQos returns the QoS class of a pod.
// The QoS class of a pod is the lowest QoS class for each resource in each container.
func GetPodQos(pod *api.Pod) string {
qosValues := sets.NewString()
for _, container := range pod.Spec.Containers {
qosPerResource := GetQoS(&container)
for _, qosValue := range qosPerResource {
qosValues.Insert(qosValue)
}
}
if qosValues.Has(BestEffort) {
return BestEffort
}
if qosValues.Has(Burstable) {
return Burstable
}
return Guaranteed
}
// GetQos returns a mapping of resource name to QoS class of a container
func GetQoS(container *api.Container) map[api.ResourceName]string {
resourceToQoS := map[api.ResourceName]string{}