From 35d73b6cdabda9343a70bb00da2bb02181b803d9 Mon Sep 17 00:00:00 2001 From: vinay kulkarni Date: Sat, 29 Jul 2023 13:30:09 +0000 Subject: [PATCH] Perf optimization: Move away from GetPodQOS, using PodStatus.QOSClass instead Kubernetes-commit: 5d4410b9601f27942fa1d1a4e65c2aa3a65637b1 --- pkg/describe/describe.go | 6 +----- pkg/util/qos/qos.go | 9 +++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/describe/describe.go b/pkg/describe/describe.go index 15ed22e0e..924e745b0 100644 --- a/pkg/describe/describe.go +++ b/pkg/describe/describe.go @@ -871,11 +871,7 @@ func describePod(pod *corev1.Pod, events *corev1.EventList) (string, error) { } } describeVolumes(pod.Spec.Volumes, w, "") - if pod.Status.QOSClass != "" { - w.Write(LEVEL_0, "QoS Class:\t%s\n", pod.Status.QOSClass) - } else { - w.Write(LEVEL_0, "QoS Class:\t%s\n", qos.GetPodQOS(pod)) - } + w.Write(LEVEL_0, "QoS Class:\t%s\n", qos.PodQOSClass(pod)) printLabelsMultiline(w, "Node-Selectors", pod.Spec.NodeSelector) printPodTolerationsMultiline(w, "Tolerations", pod.Spec.Tolerations) describeTopologySpreadConstraints(pod.Spec.TopologySpreadConstraints, w, "") diff --git a/pkg/util/qos/qos.go b/pkg/util/qos/qos.go index 2270691f5..87183a095 100644 --- a/pkg/util/qos/qos.go +++ b/pkg/util/qos/qos.go @@ -28,6 +28,15 @@ func isSupportedQoSComputeResource(name core.ResourceName) bool { return supportedQoSComputeResources.Has(string(name)) } +// PodQOSClass returns the QoS class of a pod persisted in the PodStatus. +// If QOSClass is empty, it returns value of GetPodQOS() which computes pod's QoS class. +func PodQOSClass(pod *core.Pod) core.PodQOSClass { + if pod.Status.QOSClass != "" { + return pod.Status.QOSClass + } + return GetPodQOS(pod) +} + // GetPodQOS returns the QoS class of a pod. // A pod is besteffort if none of its containers have specified any requests or limits. // A pod is guaranteed only when requests and limits are specified for all the containers and they are equal.