Skip to content

Commit fbdf73f

Browse files
committed
Add TTL Strategy in Workflow Spec
1 parent 60a8865 commit fbdf73f

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

backend/src/apiserver/template/v2_template.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,19 @@ func (t *V2Spec) ScheduledWorkflow(modelJob *model.Job) (*scheduledworkflow.Sche
7777
}
7878
}
7979

80+
var pipeline_options argocompiler.Options
81+
for _, platform := range t.platformSpec.Platforms {
82+
if platform.PipelineConfig.PipelineTtl != 0 {
83+
pipeline_options = argocompiler.Options{
84+
TtlSeconds: platform.PipelineConfig.PipelineTtl,
85+
}
86+
break
87+
}
88+
}
89+
8090
var obj interface{}
8191
if util.CurrentExecutionType() == util.ArgoWorkflow {
82-
obj, err = argocompiler.Compile(job, kubernetesSpec, nil)
92+
obj, err = argocompiler.Compile(job, kubernetesSpec, &pipeline_options)
8393
} else if util.CurrentExecutionType() == util.TektonPipelineRun {
8494
obj, err = tektoncompiler.Compile(job, kubernetesSpec, &tektoncompiler.Options{LauncherImage: Launcher})
8595
}
@@ -300,9 +310,19 @@ func (t *V2Spec) RunWorkflow(modelRun *model.Run, options RunWorkflowOptions) (u
300310
}
301311
}
302312

313+
var pipeline_options *argocompiler.Options
314+
for _, platform := range t.platformSpec.Platforms {
315+
if platform.PipelineConfig.PipelineTtl != 0 {
316+
pipeline_options = &argocompiler.Options{
317+
TtlSeconds: platform.PipelineConfig.PipelineTtl,
318+
}
319+
break
320+
}
321+
}
322+
303323
var obj interface{}
304324
if util.CurrentExecutionType() == util.ArgoWorkflow {
305-
obj, err = argocompiler.Compile(job, kubernetesSpec, nil)
325+
obj, err = argocompiler.Compile(job, kubernetesSpec, pipeline_options)
306326
} else if util.CurrentExecutionType() == util.TektonPipelineRun {
307327
obj, err = tektoncompiler.Compile(job, kubernetesSpec, nil)
308328
}

backend/src/v2/compiler/argocompiler/argo.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ type Options struct {
4040
// optional
4141
PipelineRoot string
4242
// TODO(Bobgy): add an option -- dev mode, ImagePullPolicy should only be Always in dev mode.
43+
TtlSeconds int32
4344
}
4445

46+
const (
47+
pipeline_default_ttlSeconds = int32(30)
48+
)
49+
4550
func Compile(jobArg *pipelinespec.PipelineJob, kubernetesSpecArg *pipelinespec.SinglePlatformSpec, opts *Options) (*wfapi.Workflow, error) {
4651
// clone jobArg, because we don't want to change it
4752
jobMsg := proto.Clone(jobArg)
@@ -86,6 +91,11 @@ func Compile(jobArg *pipelinespec.PipelineJob, kubernetesSpecArg *pipelinespec.S
8691
}
8792
}
8893

94+
pipeline_ttlseconds := pipeline_default_ttlSeconds
95+
if &opts.TtlSeconds != nil {
96+
pipeline_ttlseconds = opts.TtlSeconds
97+
}
98+
8999
// initialization
90100
wf := &wfapi.Workflow{
91101
TypeMeta: k8smeta.TypeMeta{
@@ -117,6 +127,9 @@ func Compile(jobArg *pipelinespec.PipelineJob, kubernetesSpecArg *pipelinespec.S
117127
},
118128
ServiceAccountName: "pipeline-runner",
119129
Entrypoint: tmplEntrypoint,
130+
TTLStrategy: &wfapi.TTLStrategy{
131+
SecondsAfterCompletion: &pipeline_ttlseconds,
132+
},
120133
},
121134
}
122135
c := &workflowCompiler{

0 commit comments

Comments
 (0)