Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kosmos-io/kosmos
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e60f0ca2fd24aae95a2f1ab9fef88b1eddf8b3ec
Choose a base ref
..
head repository: kosmos-io/kosmos
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cb54a5899c20395ed8ac1ce93b1c7c8f64712eba
Choose a head ref
Showing with 11 additions and 11 deletions.
  1. +11 −11 pkg/utils/resources.go
22 changes: 11 additions & 11 deletions pkg/utils/resources.go
Original file line number Diff line number Diff line change
@@ -11,29 +11,29 @@ const (
)

func CalculateClusterResources(nodes *corev1.NodeList, pods *corev1.PodList) corev1.ResourceList {
notNodes := GetNotReadyAndUnschedulableLeafNodes(nodes)
base := GetNodesTotalResources(nodes, notNodes)
reqs, _ := GetPodsTotalRequestsAndLimits(pods, notNodes)
unavailableNodes := GetNotReadyAndUnschedulableLeafNodes(nodes)
base := GetNodesTotalResources(nodes, unavailableNodes)
reqs, _ := GetPodsTotalRequestsAndLimits(pods, unavailableNodes)
podNums := GetUsedPodNums(pods, nodes)
SubResourceList(base, reqs)
SubResourceList(base, podNums)
return base
}

func GetNotReadyAndUnschedulableLeafNodes(leafNodes *corev1.NodeList) (notNodes map[string]corev1.Node) {
notNodes = make(map[string]corev1.Node)
func GetNotReadyAndUnschedulableLeafNodes(leafNodes *corev1.NodeList) (unavailableNodes map[string]corev1.Node) {
unavailableNodes = make(map[string]corev1.Node)
for i, n := range leafNodes.Items {
if n.Spec.Unschedulable || !NodeReady(&leafNodes.Items[i]) {
notNodes[n.Name] = n
unavailableNodes[n.Name] = n
}
}
return notNodes
return unavailableNodes
}

func GetNodesTotalResources(nodes *corev1.NodeList, notNodes map[string]corev1.Node) (total corev1.ResourceList) {
func GetNodesTotalResources(nodes *corev1.NodeList, unavailableNodes map[string]corev1.Node) (total corev1.ResourceList) {
total = corev1.ResourceList{}
for _, n := range nodes.Items {
if _, ok := notNodes[n.Name]; ok {
if _, ok := unavailableNodes[n.Name]; ok {
continue
}
for key, val := range n.Status.Allocatable {
@@ -61,7 +61,7 @@ func SubResourceList(base, list corev1.ResourceList) {

// GetPodsTotalRequestsAndLimits
// lifted from https://github.com/kubernetes/kubernetes/blob/v1.21.8/staging/src/k8s.io/kubectl/pkg/describe/describe.go#L4051
func GetPodsTotalRequestsAndLimits(podList *corev1.PodList, notNodes map[string]corev1.Node) (reqs corev1.ResourceList, limits corev1.ResourceList) {
func GetPodsTotalRequestsAndLimits(podList *corev1.PodList, unavailableNodes map[string]corev1.Node) (reqs corev1.ResourceList, limits corev1.ResourceList) {
reqs, limits = corev1.ResourceList{}, corev1.ResourceList{}
if podList.Items != nil {
for _, p := range podList.Items {
@@ -72,7 +72,7 @@ func GetPodsTotalRequestsAndLimits(podList *corev1.PodList, notNodes map[string]
if pod.Status.Phase != corev1.PodRunning {
continue
}
if _, ok := notNodes[pod.Spec.NodeName]; ok {
if _, ok := unavailableNodes[pod.Spec.NodeName]; ok {
continue
}
podReqs, podLimits := v1resource.PodRequestsAndLimits(&pod)