Skip to content

Commit f41623c

Browse files
committed
add vcjob
1 parent bc07584 commit f41623c

File tree

1 file changed

+67
-5
lines changed
  • pkg/resourceinterpreter/default/thirdparty/resourcecustomizations/batch.volcano.sh/v1alpha1/Job

1 file changed

+67
-5
lines changed

pkg/resourceinterpreter/default/thirdparty/resourcecustomizations/batch.volcano.sh/v1alpha1/Job/customizations.yaml

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,29 @@ spec:
110110
return nil
111111
end
112112
end
113+
113114
function AggregateStatus(desiredObj, statusItems)
114115
if statusItems == nil then return desiredObj end
115116
if desiredObj.status == nil then desiredObj.status = {} end
116-
117+
118+
if #statusItems == 1 then
119+
desiredObj.status = statusItems[1].status
120+
return desiredObj
121+
end
122+
123+
local failedClusters = {}
124+
local completedClusters = 0
125+
local latestTransition = {}
126+
local successfulClusters = 0
127+
local hasFailed = false
128+
local failedConditions = {}
129+
local failedPhases = {
130+
Failed = true,
131+
Aborted = true,
132+
Aborting = true,
133+
Terminated = true,
134+
Terminating = true,
135+
}
117136
local status = {
118137
state = {},
119138
minAvailable = 0,
@@ -129,7 +148,6 @@ spec:
129148
controlledResources = {},
130149
conditions = {},
131150
runningDuration = "0s",
132-
state = {}
133151
}
134152
135153
for i = 1, #statusItems do
@@ -144,7 +162,6 @@ spec:
144162
status.unknown = status.unknown + (s.unknown or 0)
145163
status.version = math.max(status.version, s.version or 0)
146164
status.retryCount = status.retryCount + (s.retryCount or 0)
147-
status.state = s.state
148165
if durationVal(s.runningDuration) > durationVal(status.runningDuration) then
149166
status.runningDuration = s.runningDuration
150167
end
@@ -161,17 +178,62 @@ spec:
161178
end
162179
end
163180
end
181+
164182
if s.controlledResources then
165183
for k, v in pairs(s.controlledResources) do
166184
status.controlledResources[k] = v
167185
end
168186
end
169187
170-
if s.conditions ~= nil then
188+
if s.conditions then
189+
local clusterHasFailed = false
171190
for _, c in ipairs(s.conditions) do
172-
table.insert(status.conditions, c)
191+
if failedPhases[c.status] then
192+
clusterHasFailed = true
193+
hasFailed = true
194+
end
195+
if not clusterHasFailed then
196+
local exist = latestTransition[c.status]
197+
if exist == nil or c.lastTransitionTime > exist.lastTransitionTime then
198+
latestTransition[c.status] = c
199+
end
200+
end
201+
end
202+
if clusterHasFailed and #failedConditions == 0 then
203+
failedConditions = s.conditions
173204
end
174205
end
206+
207+
if s.state ~= nil then
208+
local st = s.state
209+
if st.phase == "Completed" then
210+
successfulClusters = successfulClusters + 1
211+
elseif st.phase == "Failed" or st.phase == "Aborted" then
212+
table.insert(failedClusters, statusItems[i].clusterName)
213+
end
214+
end
215+
end
216+
end
217+
218+
if #failedClusters > 0 then
219+
status.state.phase = "Failed"
220+
status.state.reason = "VolcanoJobFailed"
221+
status.state.message = "Job failed in clusters: " .. table.concat(failedClusters, ",")
222+
status.state.lastTransitionTime = os.date("!%Y-%m-%dT%H:%M:%SZ")
223+
end
224+
225+
if successfulClusters == #statusItems and successfulClusters > 0 then
226+
status.state.phase = "Completed"
227+
status.state.reason = "Completed"
228+
status.state.message = "Job completed successfully"
229+
status.state.lastTransitionTime = os.date("!%Y-%m-%dT%H:%M:%SZ")
230+
end
231+
232+
if hasFailed then
233+
status.conditions = failedConditions
234+
else
235+
for _, v in pairs(latestTransition) do
236+
table.insert(status.conditions, v)
175237
end
176238
end
177239

0 commit comments

Comments
 (0)