Skip to content

Commit 15fda0b

Browse files
fix topology-updater cpu report
1 parent 86d2809 commit 15fda0b

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

pkg/resourcemonitor/podresourcesscanner.go

+23-21
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (resMon *PodResourcesScanner) isWatchable(podNamespace string, podName stri
6363
return false, false, err
6464
}
6565

66+
if pod.Status.QOSClass != corev1.PodQOSGuaranteed {
67+
return false, false, nil
68+
}
69+
6670
isIntegralGuaranteed := hasExclusiveCPUs(pod)
6771

6872
if resMon.namespace == "*" && (isIntegralGuaranteed || hasDevice) {
@@ -85,9 +89,9 @@ func hasExclusiveCPUs(pod *corev1.Pod) bool {
8589
continue
8690
}
8791
totalCPU += cpuQuantity.Value()
88-
isInitContainerGuaranteed := hasIntegralCPUs(pod, &container)
89-
if !isInitContainerGuaranteed {
90-
return false
92+
isInitContainerGuaranteed := hasIntegralCPUs(&container)
93+
if isInitContainerGuaranteed {
94+
return true
9195
}
9296
}
9397
for _, container := range pod.Spec.Containers {
@@ -96,9 +100,9 @@ func hasExclusiveCPUs(pod *corev1.Pod) bool {
96100
continue
97101
}
98102
totalCPU += cpuQuantity.Value()
99-
isAppContainerGuaranteed := hasIntegralCPUs(pod, &container)
100-
if !isAppContainerGuaranteed {
101-
return false
103+
isAppContainerGuaranteed := hasIntegralCPUs(&container)
104+
if isAppContainerGuaranteed {
105+
return true
102106
}
103107
}
104108

@@ -107,7 +111,7 @@ func hasExclusiveCPUs(pod *corev1.Pod) bool {
107111
}
108112

109113
// hasIntegralCPUs returns true if a container in pod is requesting integral CPUs else returns false
110-
func hasIntegralCPUs(pod *corev1.Pod, container *corev1.Container) bool {
114+
func hasIntegralCPUs(container *corev1.Container) bool {
111115
cpuQuantity := container.Resources.Requests[corev1.ResourceCPU]
112116
return cpuQuantity.Value()*1000 == cpuQuantity.MilliValue()
113117
}
@@ -147,7 +151,7 @@ func (resMon *PodResourcesScanner) Scan() (ScanResponse, error) {
147151
for _, podResource := range respPodResources {
148152
klog.InfoS("scanning pod", "podName", podResource.GetName())
149153
hasDevice := hasDevice(podResource)
150-
isWatchable, isIntegralGuaranteed, err := resMon.isWatchable(podResource.GetNamespace(), podResource.GetName(), hasDevice)
154+
isWatchable, _, err := resMon.isWatchable(podResource.GetNamespace(), podResource.GetName(), hasDevice)
151155
if err != nil {
152156
return ScanResponse{}, fmt.Errorf("checking if pod in a namespace is watchable, namespace:%v, pod name %v: %w", podResource.GetNamespace(), podResource.GetName(), err)
153157
}
@@ -165,19 +169,17 @@ func (resMon *PodResourcesScanner) Scan() (ScanResponse, error) {
165169
Name: container.Name,
166170
}
167171

168-
if isIntegralGuaranteed {
169-
cpuIDs := container.GetCpuIds()
170-
if len(cpuIDs) > 0 {
171-
var resCPUs []string
172-
for _, cpuID := range container.GetCpuIds() {
173-
resCPUs = append(resCPUs, strconv.FormatInt(cpuID, 10))
174-
}
175-
contRes.Resources = []ResourceInfo{
176-
{
177-
Name: corev1.ResourceCPU,
178-
Data: resCPUs,
179-
},
180-
}
172+
cpuIDs := container.GetCpuIds()
173+
if len(cpuIDs) > 0 {
174+
var resCPUs []string
175+
for _, cpuID := range container.GetCpuIds() {
176+
resCPUs = append(resCPUs, strconv.FormatInt(cpuID, 10))
177+
}
178+
contRes.Resources = []ResourceInfo{
179+
{
180+
Name: corev1.ResourceCPU,
181+
Data: resCPUs,
182+
},
181183
}
182184
}
183185

0 commit comments

Comments
 (0)