@@ -37,6 +37,9 @@ import (
37
37
38
38
const (
39
39
driverTypeArg = "type"
40
+ ROOT_DAG = "ROOT_DAG"
41
+ DAG = "DAG"
42
+ CONTAINER = "CONTAINER"
40
43
)
41
44
42
45
var (
@@ -160,12 +163,12 @@ func drive() (err error) {
160
163
var execution * driver.Execution
161
164
var driverErr error
162
165
switch * driverType {
163
- case " ROOT_DAG" :
166
+ case ROOT_DAG :
164
167
options .RuntimeConfig = runtimeConfig
165
168
execution , driverErr = driver .RootDAG (ctx , options , client )
166
- case " DAG" :
169
+ case DAG :
167
170
execution , driverErr = driver .DAG (ctx , options , client )
168
- case " CONTAINER" :
171
+ case CONTAINER :
169
172
options .Container = containerSpec
170
173
options .KubernetesExecutorConfig = k8sExecCfg
171
174
execution , driverErr = driver .Container (ctx , options , client , cacheClient )
@@ -183,35 +186,60 @@ func drive() (err error) {
183
186
err = driverErr
184
187
}()
185
188
}
189
+
190
+ executionPaths := & ExecutionPaths {
191
+ ExecutionID : * executionIDPath ,
192
+ IterationCount : * iterationCountPath ,
193
+ CachedDecision : * cachedDecisionPath ,
194
+ Condition : * conditionPath ,
195
+ PodSpecPatch : * podSpecPatchPath }
196
+
197
+ return handleExecution (execution , * driverType , executionPaths )
198
+ }
199
+
200
+ func handleExecution (execution * driver.Execution , driverType string , executionPaths * ExecutionPaths ) error {
186
201
if execution .ID != 0 {
187
202
glog .Infof ("output execution.ID=%v" , execution .ID )
188
- if * executionIDPath != "" {
189
- if err = writeFile (* executionIDPath , []byte (fmt .Sprint (execution .ID ))); err != nil {
203
+ if executionPaths . ExecutionID != "" {
204
+ if err : = writeFile (executionPaths . ExecutionID , []byte (fmt .Sprint (execution .ID ))); err != nil {
190
205
return fmt .Errorf ("failed to write execution ID to file: %w" , err )
191
206
}
192
207
}
193
208
}
194
209
if execution .IterationCount != nil {
195
- if err = writeFile (* iterationCountPath , []byte (fmt .Sprintf ("%v" , * execution .IterationCount ))); err != nil {
210
+ if err : = writeFile (executionPaths . IterationCount , []byte (fmt .Sprintf ("%v" , * execution .IterationCount ))); err != nil {
196
211
return fmt .Errorf ("failed to write iteration count to file: %w" , err )
197
212
}
213
+ } else {
214
+ if driverType == ROOT_DAG {
215
+ if err := writeFile (executionPaths .IterationCount , []byte ("0" )); err != nil {
216
+ return fmt .Errorf ("failed to write iteration count to file: %w" , err )
217
+ }
218
+ }
198
219
}
199
220
if execution .Cached != nil {
200
- if err = writeFile (* cachedDecisionPath , []byte (strconv .FormatBool (* execution .Cached ))); err != nil {
221
+ if err : = writeFile (executionPaths . CachedDecision , []byte (strconv .FormatBool (* execution .Cached ))); err != nil {
201
222
return fmt .Errorf ("failed to write cached decision to file: %w" , err )
202
223
}
203
224
}
204
225
if execution .Condition != nil {
205
- if err = writeFile (* conditionPath , []byte (strconv .FormatBool (* execution .Condition ))); err != nil {
226
+ if err : = writeFile (executionPaths . Condition , []byte (strconv .FormatBool (* execution .Condition ))); err != nil {
206
227
return fmt .Errorf ("failed to write condition to file: %w" , err )
207
228
}
229
+ } else {
230
+ // nil is a valid value for Condition
231
+ if driverType == ROOT_DAG || driverType == CONTAINER {
232
+ if err := writeFile (executionPaths .Condition , []byte ("nil" )); err != nil {
233
+ return fmt .Errorf ("failed to write condition to file: %w" , err )
234
+ }
235
+ }
208
236
}
209
237
if execution .PodSpecPatch != "" {
210
238
glog .Infof ("output podSpecPatch=\n %s\n " , execution .PodSpecPatch )
211
- if * podSpecPatchPath == "" {
239
+ if executionPaths . PodSpecPatch == "" {
212
240
return fmt .Errorf ("--pod_spec_patch_path is required for container executor drivers" )
213
241
}
214
- if err = writeFile (* podSpecPatchPath , []byte (execution .PodSpecPatch )); err != nil {
242
+ if err : = writeFile (executionPaths . PodSpecPatch , []byte (execution .PodSpecPatch )); err != nil {
215
243
return fmt .Errorf ("failed to write pod spec patch to file: %w" , err )
216
244
}
217
245
}
0 commit comments