mirror of
				https://github.com/gethomepage/homepage.git
				synced 2025-10-31 02:27:02 -04:00 
			
		
		
		
	Fix: kubernetes statistics not respecting selector (#5199)
This commit is contained in:
		
							parent
							
								
									1fe4f49771
								
							
						
					
					
						commit
						d99c3cb691
					
				| @ -53,9 +53,11 @@ export default async function handler(req, res) { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     const podNames = new Set(); | ||||||
|     let cpuLimit = 0; |     let cpuLimit = 0; | ||||||
|     let memLimit = 0; |     let memLimit = 0; | ||||||
|     pods.forEach((pod) => { |     pods.forEach((pod) => { | ||||||
|  |       podNames.add(pod.metadata.name); | ||||||
|       pod.spec.containers.forEach((container) => { |       pod.spec.containers.forEach((container) => { | ||||||
|         if (container?.resources?.limits?.cpu) { |         if (container?.resources?.limits?.cpu) { | ||||||
|           cpuLimit += parseCpu(container?.resources?.limits?.cpu); |           cpuLimit += parseCpu(container?.resources?.limits?.cpu); | ||||||
| @ -66,12 +68,8 @@ export default async function handler(req, res) { | |||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const podStatsList = await Promise.all( |     const namespaceMetrics = await metricsApi | ||||||
|       pods.map(async (pod) => { |       .getPodMetrics(namespace) | ||||||
|         let depMem = 0; |  | ||||||
|         let depCpu = 0; |  | ||||||
|         const podMetrics = await metricsApi |  | ||||||
|           .getPodMetrics(namespace, pod.items) |  | ||||||
|       .then((response) => response.items) |       .then((response) => response.items) | ||||||
|       .catch((err) => { |       .catch((err) => { | ||||||
|         // 404 generally means that the metrics have not been populated yet
 |         // 404 generally means that the metrics have not been populated yet
 | ||||||
| @ -80,28 +78,22 @@ export default async function handler(req, res) { | |||||||
|         } |         } | ||||||
|         return null; |         return null; | ||||||
|       }); |       }); | ||||||
|         if (podMetrics) { | 
 | ||||||
|           podMetrics.forEach((metrics) => { |  | ||||||
|             metrics.containers.forEach((container) => { |  | ||||||
|               depMem += parseMemory(container.usage.memory); |  | ||||||
|               depCpu += parseCpu(container.usage.cpu); |  | ||||||
|             }); |  | ||||||
|           }); |  | ||||||
|         } |  | ||||||
|         return { |  | ||||||
|           mem: depMem, |  | ||||||
|           cpu: depCpu, |  | ||||||
|         }; |  | ||||||
|       }), |  | ||||||
|     ); |  | ||||||
|     const stats = { |     const stats = { | ||||||
|       mem: 0, |       mem: 0, | ||||||
|       cpu: 0, |       cpu: 0, | ||||||
|     }; |     }; | ||||||
|     podStatsList.forEach((podStat) => { | 
 | ||||||
|       stats.mem += podStat.mem; |     if (namespaceMetrics) { | ||||||
|       stats.cpu += podStat.cpu; |       const podMetrics = namespaceMetrics.filter((item) => podNames.has(item.metadata.name)); | ||||||
|  |       podMetrics.forEach((metrics) => { | ||||||
|  |         metrics.containers.forEach((container) => { | ||||||
|  |           stats.mem += parseMemory(container.usage.memory); | ||||||
|  |           stats.cpu += parseCpu(container.usage.cpu); | ||||||
|         }); |         }); | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     stats.cpuLimit = cpuLimit; |     stats.cpuLimit = cpuLimit; | ||||||
|     stats.memLimit = memLimit; |     stats.memLimit = memLimit; | ||||||
|     stats.cpuUsage = cpuLimit ? 100 * (stats.cpu / cpuLimit) : 0; |     stats.cpuUsage = cpuLimit ? 100 * (stats.cpu / cpuLimit) : 0; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user