@@ -63,6 +63,10 @@ func (resMon *PodResourcesScanner) isWatchable(podNamespace string, podName stri
63
63
return false , false , err
64
64
}
65
65
66
+ if pod .Status .QOSClass != corev1 .PodQOSGuaranteed {
67
+ return false , false , nil
68
+ }
69
+
66
70
isIntegralGuaranteed := hasExclusiveCPUs (pod )
67
71
68
72
if resMon .namespace == "*" && (isIntegralGuaranteed || hasDevice ) {
@@ -85,9 +89,9 @@ func hasExclusiveCPUs(pod *corev1.Pod) bool {
85
89
continue
86
90
}
87
91
totalCPU += cpuQuantity .Value ()
88
- isInitContainerGuaranteed := hasIntegralCPUs (pod , & container )
89
- if ! isInitContainerGuaranteed {
90
- return false
92
+ isInitContainerGuaranteed := hasIntegralCPUs (& container )
93
+ if isInitContainerGuaranteed {
94
+ return true
91
95
}
92
96
}
93
97
for _ , container := range pod .Spec .Containers {
@@ -96,9 +100,9 @@ func hasExclusiveCPUs(pod *corev1.Pod) bool {
96
100
continue
97
101
}
98
102
totalCPU += cpuQuantity .Value ()
99
- isAppContainerGuaranteed := hasIntegralCPUs (pod , & container )
100
- if ! isAppContainerGuaranteed {
101
- return false
103
+ isAppContainerGuaranteed := hasIntegralCPUs (& container )
104
+ if isAppContainerGuaranteed {
105
+ return true
102
106
}
103
107
}
104
108
@@ -107,7 +111,7 @@ func hasExclusiveCPUs(pod *corev1.Pod) bool {
107
111
}
108
112
109
113
// 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 {
111
115
cpuQuantity := container .Resources .Requests [corev1 .ResourceCPU ]
112
116
return cpuQuantity .Value ()* 1000 == cpuQuantity .MilliValue ()
113
117
}
@@ -147,7 +151,7 @@ func (resMon *PodResourcesScanner) Scan() (ScanResponse, error) {
147
151
for _ , podResource := range respPodResources {
148
152
klog .InfoS ("scanning pod" , "podName" , podResource .GetName ())
149
153
hasDevice := hasDevice (podResource )
150
- isWatchable , isIntegralGuaranteed , err := resMon .isWatchable (podResource .GetNamespace (), podResource .GetName (), hasDevice )
154
+ isWatchable , _ , err := resMon .isWatchable (podResource .GetNamespace (), podResource .GetName (), hasDevice )
151
155
if err != nil {
152
156
return ScanResponse {}, fmt .Errorf ("checking if pod in a namespace is watchable, namespace:%v, pod name %v: %w" , podResource .GetNamespace (), podResource .GetName (), err )
153
157
}
@@ -165,19 +169,17 @@ func (resMon *PodResourcesScanner) Scan() (ScanResponse, error) {
165
169
Name : container .Name ,
166
170
}
167
171
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
+ },
181
183
}
182
184
}
183
185
0 commit comments