Skip to content

Commit 079d482

Browse files
committed
Introduces PipelineConfig class with TTL configuration
Signed-off-by: Ricardo M. Oliveira <rmartine@redhat.com>
1 parent 6684b6d commit 079d482

File tree

9 files changed

+76
-9
lines changed

9 files changed

+76
-9
lines changed

api/v2alpha1/go/cachekey/cache_key.pb.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2alpha1/go/pipelinespec/pipeline_spec.pb.go

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2alpha1/pipeline_spec.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,8 @@ message PipelineStateEnum {
10791079
message PlatformSpec {
10801080
// Platform key to full platform config
10811081
map<string, SinglePlatformSpec> platforms = 1;
1082+
1083+
10821084
}
10831085

10841086
message SinglePlatformSpec {
@@ -1095,6 +1097,11 @@ message SinglePlatformSpec {
10951097
PipelineConfig pipelineConfig = 4;
10961098
}
10971099

1100+
message PipelineConfig {
1101+
// Set TTL at pipeline-level
1102+
optional int32 pipelineTtl = 1;
1103+
}
1104+
10981105
message PlatformDeploymentConfig {
10991106
// Map of executor label to executor-level config
11001107
// Mirrors PipelineSpec.deployment_spec.executors structure

backend/src/apiserver/template/v2_template.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"regexp"
2424
"strings"
2525

26+
"github.com/golang/glog"
2627
structpb "github.com/golang/protobuf/ptypes/struct"
2728
"github.com/kubeflow/pipelines/api/v2alpha1/go/pipelinespec"
2829
"github.com/kubeflow/pipelines/backend/src/apiserver/model"
@@ -77,9 +78,17 @@ func (t *V2Spec) ScheduledWorkflow(modelJob *model.Job) (*scheduledworkflow.Sche
7778
}
7879
}
7980

81+
var pipeline_options argocompiler.Options
82+
if t.platformSpec.PipelineConfig.Ttl != nil {
83+
glog.Info("Found pipeline config")
84+
pipeline_options = argocompiler.Options{
85+
TtlSeconds: *t.platformSpec.PipelineConfig.Ttl,
86+
}
87+
}
88+
8089
var obj interface{}
8190
if util.CurrentExecutionType() == util.ArgoWorkflow {
82-
obj, err = argocompiler.Compile(job, kubernetesSpec, nil)
91+
obj, err = argocompiler.Compile(job, kubernetesSpec, &pipeline_options)
8392
} else if util.CurrentExecutionType() == util.TektonPipelineRun {
8493
obj, err = tektoncompiler.Compile(job, kubernetesSpec, &tektoncompiler.Options{LauncherImage: Launcher})
8594
}
@@ -300,9 +309,17 @@ func (t *V2Spec) RunWorkflow(modelRun *model.Run, options RunWorkflowOptions) (u
300309
}
301310
}
302311

312+
var pipeline_options *argocompiler.Options
313+
if t.platformSpec.PipelineConfig.Ttl != nil {
314+
glog.Info("Found pipeline config")
315+
pipeline_options = &argocompiler.Options{
316+
TtlSeconds: *t.platformSpec.PipelineConfig.Ttl,
317+
}
318+
}
319+
303320
var obj interface{}
304321
if util.CurrentExecutionType() == util.ArgoWorkflow {
305-
obj, err = argocompiler.Compile(job, kubernetesSpec, nil)
322+
obj, err = argocompiler.Compile(job, kubernetesSpec, pipeline_options)
306323
} else if util.CurrentExecutionType() == util.TektonPipelineRun {
307324
obj, err = tektoncompiler.Compile(job, kubernetesSpec, nil)
308325
}
@@ -344,7 +361,7 @@ func IsPlatformSpecWithKubernetesConfig(template []byte) bool {
344361
return false
345362
}
346363
_, ok := platformSpec.Platforms["kubernetes"]
347-
return ok
364+
return ok || platformSpec.PipelineConfig != nil
348365
}
349366

350367
func (t *V2Spec) validatePipelineJobInputs(job *pipelinespec.PipelineJob) error {

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{

sdk/python/kfp/compiler/pipeline_spec_builder.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,10 @@ def create_pipeline_spec(
19531953
if pipeline_config is not None:
19541954
_merge_pipeline_config(
19551955
pipelineConfig=pipeline_config, platformSpec=platform_spec)
1956+
<<<<<<< HEAD
19561957

1958+
=======
1959+
>>>>>>> cc9690e2b (Introduces PipelineConfig class with TTL configuration)
19571960
for group in all_groups:
19581961
build_spec_by_group(
19591962
pipeline_spec=pipeline_spec,
@@ -2076,6 +2079,11 @@ def _merge_pipeline_config(pipelineConfig: pipeline_config.PipelineConfig,
20762079
# {'pipelineConfig': {
20772080
# '<some pipeline config option>': pipelineConfig.<get that value>,
20782081
# }}, platformSpec.platforms['kubernetes'])
2082+
2083+
pipeline_config_json = json_format.ParseDict(
2084+
{'pipelineConfig': {
2085+
'pipelineTtl': pipelineConfig.get_ttl(),
2086+
}}, platformSpec.platforms['kubernetes'])
20792087

20802088
return platformSpec
20812089

sdk/python/kfp/dsl/component_decorator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import warnings
1818

1919
from kfp.dsl import component_factory
20+
from kfp.dsl import pipeline_config
2021

2122

2223
def component(func: Optional[Callable] = None,

sdk/python/kfp/dsl/pipeline_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ def __init__(self):
2121
pass
2222

2323
# TODO add pipeline level configs
24+
def set_ttl(self, ttl: int):
25+
self.__ttl = ttl
26+
27+
def get_ttl(self) -> int:
28+
return int(self.__ttl)

sdk/python/kfp/dsl/pipeline_context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ def my_pipeline(a: str, b: int):
5353
pipeline_root: The root directory from which to read input and output
5454
parameters and artifacts.
5555
display_name: A human-readable name for the pipeline.
56+
<<<<<<< HEAD
5657
pipeline_config: Pipeline-level config options.
58+
=======
59+
pipeline_config: Pipeline-level configuration.
60+
>>>>>>> cc9690e2b (Introduces PipelineConfig class with TTL configuration)
5761
"""
5862
if func is None:
5963
return functools.partial(

0 commit comments

Comments
 (0)