|
76 | 76 | return headPodReady and clusterProvisioned and not replicaFailure |
77 | 77 | end |
78 | 78 | statusAggregation: |
79 | | - luaScript: > |
| 79 | + luaScript: | |
| 80 | + local kube = require("kube") |
| 81 | +
|
80 | 82 | function AggregateStatus(desiredObj, statusItems) |
81 | 83 | if statusItems == nil then |
82 | 84 | return desiredObj |
|
85 | 87 | desiredObj.status = {} |
86 | 88 | end |
87 | 89 |
|
| 90 | + desiredObj.spec = nil |
| 91 | +
|
88 | 92 | -- If only one item, use it directly |
89 | 93 | if #statusItems == 1 then |
90 | 94 | desiredObj.status = statusItems[1].status |
|
98 | 102 | local maxWorkerReplicas = 0 |
99 | 103 | local minWorkerReplicas = 0 |
100 | 104 | local desiredWorkerReplicas = 0 |
101 | | - local desiredCPU = 0 |
| 105 | + local desiredCPU = "0" |
102 | 106 | local desiredGPU = 0 |
103 | | - local desiredMemory = 0 |
| 107 | + local desiredMemory = "0" |
104 | 108 | local desiredTPU = 0 |
105 | 109 | local lastUpdateTime = nil |
106 | 110 | local endpoints = nil |
@@ -136,22 +140,19 @@ spec: |
136 | 140 | desiredWorkerReplicas = desiredWorkerReplicas + currentStatus.desiredWorkerReplicas |
137 | 141 | end |
138 | 142 |
|
139 | | - -- Sum resource quantities (stored as numeric strings like "2", "4", etc.) |
| 143 | + -- Sum resource quantities using kube library |
140 | 144 | if currentStatus.desiredCPU ~= nil and currentStatus.desiredCPU ~= "" then |
141 | | - desiredCPU = desiredCPU + tonumber(currentStatus.desiredCPU) |
| 145 | + desiredCPU = kube.resourceAdd(desiredCPU, currentStatus.desiredCPU) |
142 | 146 | end |
143 | 147 | if currentStatus.desiredGPU ~= nil and currentStatus.desiredGPU ~= "" then |
144 | 148 | desiredGPU = desiredGPU + tonumber(currentStatus.desiredGPU) |
145 | 149 | end |
146 | 150 | if currentStatus.desiredTPU ~= nil and currentStatus.desiredTPU ~= "" then |
147 | 151 | desiredTPU = desiredTPU + tonumber(currentStatus.desiredTPU) |
148 | 152 | end |
149 | | - -- For memory, parse numeric part (e.g., "3G" -> 3) |
| 153 | + -- Sum memory quantities using kube library |
150 | 154 | if currentStatus.desiredMemory ~= nil and currentStatus.desiredMemory ~= "" then |
151 | | - local memNum = tonumber(string.match(currentStatus.desiredMemory, "%d+")) |
152 | | - if memNum ~= nil then |
153 | | - desiredMemory = desiredMemory + memNum |
154 | | - end |
| 155 | + desiredMemory = kube.resourceAdd(desiredMemory, currentStatus.desiredMemory) |
155 | 156 | end |
156 | 157 |
|
157 | 158 | -- Take the most recent lastUpdateTime |
@@ -184,13 +185,10 @@ spec: |
184 | 185 | desiredObj.status.maxWorkerReplicas = maxWorkerReplicas |
185 | 186 | desiredObj.status.minWorkerReplicas = minWorkerReplicas |
186 | 187 | desiredObj.status.desiredWorkerReplicas = desiredWorkerReplicas |
187 | | - desiredObj.status.desiredCPU = tostring(desiredCPU) |
| 188 | + desiredObj.status.desiredCPU = desiredCPU |
188 | 189 | desiredObj.status.desiredGPU = tostring(desiredGPU) |
189 | 190 | desiredObj.status.desiredTPU = tostring(desiredTPU) |
190 | | - -- Reconstruct memory with unit suffix |
191 | | - if desiredMemory > 0 then |
192 | | - desiredObj.status.desiredMemory = tostring(desiredMemory) .. "G" |
193 | | - end |
| 191 | + desiredObj.status.desiredMemory = desiredMemory |
194 | 192 | desiredObj.status.lastUpdateTime = lastUpdateTime |
195 | 193 | desiredObj.status.endpoints = endpoints |
196 | 194 | desiredObj.status.head = head |
|
0 commit comments