Skip to content

Commit

Permalink
SDK - Skip attributes with missing values during PipelineMeta seriali…
Browse files Browse the repository at this point in the history
…zation (kubeflow#1448)

* SDK - Skip attributes with missing values during PipelineMeta serialization

* Fixed the tests
  • Loading branch information
Ark-kun authored and ajchili committed Aug 28, 2019
1 parent 160d526 commit 83f4553
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 52 deletions.
41 changes: 28 additions & 13 deletions sdk/python/kfp/dsl/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ def __init__(self,
self.default = default

def to_dict(self):
return {'name': self.name,
'description': self.description,
'type': self.param_type or '',
'default': self.default}
result = {}
if self.name:
result['name'] = self.name
if self.description:
result['description'] = self.description
if self.param_type:
result['type'] = self.param_type
if self.default:
result['default'] = self.default
return result


class ComponentMeta(BaseMeta):
Expand All @@ -66,11 +72,16 @@ def __init__(
self.outputs = [] if outputs is None else outputs

def to_dict(self):
return {'name': self.name,
'description': self.description,
'inputs': [ input.to_dict() for input in self.inputs ],
'outputs': [ output.to_dict() for output in self.outputs ]
}
result = {}
if self.name:
result['name'] = self.name
if self.description:
result['description'] = self.description
if self.inputs:
result['inputs'] = [input.to_dict() for input in self.inputs]
if self.outputs:
result['outputs'] = [output.to_dict() for output in self.outputs]
return result


# Add a pipeline level metadata calss here.
Expand All @@ -87,10 +98,14 @@ def __init__(
self.inputs = [] if inputs is None else inputs

def to_dict(self):
return {'name': self.name,
'description': self.description,
'inputs': [ input.to_dict() for input in self.inputs ]
}
result = {}
if self.name:
result['name'] = self.name
if self.description:
result['description'] = self.description
if self.inputs:
result['inputs'] = [input.to_dict() for input in self.inputs]
return result

def _annotation_to_typemeta(annotation):
'''_annotation_to_type_meta converts an annotation to a type structure
Expand Down
3 changes: 1 addition & 2 deletions sdk/python/tests/compiler/testdata/add_pod_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "Test adding pod env",
"inputs": [], "name": "Test adding pod env"}'
pipelines.kubeflow.org/pipeline_spec: '{"description": "Test adding pod env", "name": "Test adding pod env"}'
generateName: test-adding-pod-env-
spec:
arguments:
Expand Down
5 changes: 1 addition & 4 deletions sdk/python/tests/compiler/testdata/artifact_location.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "hello world", "inputs":
[{"default": null, "description": "", "name": "tag", "type": ""}, {"default":
"kubeflow", "description": "", "name": "namespace", "type": ""}, {"default":
"foobar", "description": "", "name": "bucket", "type": ""}], "name": "foo"}'
pipelines.kubeflow.org/pipeline_spec: '{"description": "hello world", "inputs": [{"name": "tag"}, {"default": "kubeflow", "name": "namespace"}, {"default": "foobar", "name": "bucket"}], "name": "foo"}'
generateName: foo-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "Get Most Frequent Word and Save to GCS", "inputs": [{"default": null, "description": "", "name": "message", "type": ""}, {"default": null, "description": "", "name": "outputpath", "type": ""}], "name": "Save Most Frequent"}'
pipelines.kubeflow.org/pipeline_spec: '{"description": "Get Most Frequent Word and Save to GCS", "inputs": [{"name": "message"}, {"name": "outputpath"}], "name": "Save Most Frequent"}'
generateName: save-most-frequent-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/coin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "shows how to use dsl.Condition.", "inputs": [], "name": "pipeline flip coin"}'
pipelines.kubeflow.org/pipeline_spec: '{"description": "shows how to use dsl.Condition.", "name": "pipeline flip coin"}'
generateName: pipeline-flip-coin-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "Download and Get Most Frequent Word and Save to GCS", "inputs": [{"default": null, "description": "", "name": "url", "type": ""}, {"default": null, "description": "", "name": "outputpath", "type": ""}], "name": "Download and Save Most Frequent"}'
pipelines.kubeflow.org/pipeline_spec: '{"description": "Download and Get Most Frequent Word and Save to GCS", "inputs": [{"name": "url"}, {"name": "outputpath"}], "name": "Download and Save Most Frequent"}'
generateName: download-and-save-most-frequent-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/default_value.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "A pipeline with parameter and default value.", "inputs": [{"default": "gs://ml-pipeline/shakespeare1.txt", "description": "", "name": "url", "type": ""}], "name": "Default Value"}'
pipelines.kubeflow.org/pipeline_spec: '{"description": "A pipeline with parameter and default value.", "inputs": [{"default": "gs://ml-pipeline/shakespeare1.txt", "name": "url"}], "name": "Default Value"}'
generateName: default-value-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/imagepullsecrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "Get Most Frequent Word and Save to GCS", "inputs": [{"default": null, "description": "", "name": "message", "type": ""}], "name": "Save Most Frequent"}'
pipelines.kubeflow.org/pipeline_spec: '{"description": "Get Most Frequent Word and Save to GCS", "inputs": [{"name": "message"}], "name": "Save Most Frequent"}'
generateName: save-most-frequent-
spec:
arguments:
Expand Down
3 changes: 1 addition & 2 deletions sdk/python/tests/compiler/testdata/param_op_transform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "Test that parameters used
in Op transformation functions as pod labels would be correcly identified and
set as arguments in he generated yaml", "inputs": [{"default": null, "description":
"", "name": "param", "type": ""}], "name": "Parameters in Op transformation
set as arguments in he generated yaml", "inputs": [{"name": "param"}], "name": "Parameters in Op transformation
functions"}'
generateName: parameters-in-op-transformation-functions-
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "Test the same PipelineParam
getting substituted in multiple places", "inputs": [], "name": "Param Substitutions"}'
getting substituted in multiple places", "name": "Param Substitutions"}'
generateName: param-substitutions-
spec:
arguments:
Expand Down
5 changes: 2 additions & 3 deletions sdk/python/tests/compiler/testdata/pipelineparams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ apiVersion: argoproj.io/v1alpha1
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "A pipeline with multiple
pipeline params.", "inputs": [{"default": "latest", "description": "", "name":
"tag", "type": ""}, {"default": 10, "description": "", "name": "sleep_ms", "type":
""}], "name": "PipelineParams"}'
pipeline params.", "inputs": [{"default": "latest", "name":
"tag"}, {"default": 10, "name": "sleep_ms"}], "name": "PipelineParams"}'
generateName: pipelineparams-
spec:
entrypoint: pipelineparams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "shows how to use dsl.Condition.", "inputs": [], "name": "pipeline flip coin"}'
pipelines.kubeflow.org/pipeline_spec: '{"description": "shows how to use dsl.Condition.", "name": "pipeline flip coin"}'
generateName: pipeline-flip-coin-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/recursive_do_while.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "shows how to use graph_component.",
"inputs": [], "name": "pipeline flip coin"}'
"name": "pipeline flip coin"}'
generateName: pipeline-flip-coin-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/recursive_while.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "shows how to use dsl.Condition.",
"inputs": [{"default": 12, "description": "", "name": "maxVal", "type": ""}],
"inputs": [{"default": 12, "name": "maxVal"}],
"name": "pipeline flip coin"}'
generateName: pipeline-flip-coin-
spec:
Expand Down
4 changes: 1 addition & 3 deletions sdk/python/tests/compiler/testdata/resourceop_basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "A Basic Example on ResourceOp
Usage.", "inputs": [{"default": null, "description": "", "name": "username",
"type": ""}, {"default": null, "description": "", "name": "password", "type":
""}], "name": "ResourceOp Basic"}'
Usage.", "inputs": [{"name": "username"}, {"name": "password"}], "name": "ResourceOp Basic"}'
generateName: resourceop-basic-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/sidecar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "A pipeline with sidecars.",
"inputs": [], "name": "Sidecar"}'
"name": "Sidecar"}'
generateName: sidecar-
apiVersion: argoproj.io/v1alpha1
spec:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/timeout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "shows how to use ContainerOp
set_retry().", "inputs": [], "name": "pipeline includes two steps which fail
set_retry().", "name": "pipeline includes two steps which fail
randomly."}'
generateName: pipeline-includes-two-steps-which-fail-randomly-
spec:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/volume.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "A pipeline with volume.",
"inputs": [], "name": "Volume"}'
"name": "Volume"}'
generateName: volume-
spec:
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "The fifth example of the
design doc.", "inputs": [{"default": null, "description": "", "name": "rok_url",
"type": ""}], "name": "VolumeSnapshotOp RokURL"}'
design doc.", "inputs": [{"name": "rok_url"}], "name": "VolumeSnapshotOp RokURL"}'
generateName: volumesnapshotop-rokurl-
spec:
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "The fourth example of
the design doc.", "inputs": [{"default": null, "description": "", "name": "url",
"type": ""}], "name": "VolumeSnapshotOp Sequential"}'
the design doc.", "inputs": [{"name": "url"}], "name": "VolumeSnapshotOp Sequential"}'
generateName: volumesnapshotop-sequential-
spec:
arguments:
Expand Down
3 changes: 1 addition & 2 deletions sdk/python/tests/compiler/testdata/volumeop_basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "A Basic Example on VolumeOp
Usage.", "inputs": [{"default": null, "description": "", "name": "size", "type":
""}], "name": "VolumeOp Basic"}'
Usage.", "inputs": [{"name": "size"}], "name": "VolumeOp Basic"}'
generateName: volumeop-basic-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/volumeop_dag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "The second example of
the design doc.", "inputs": [], "name": "Volume Op DAG"}'
the design doc.", "name": "Volume Op DAG"}'
generateName: volume-op-dag-
spec:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/tests/compiler/testdata/volumeop_parallel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "The first example of the
design doc.", "inputs": [], "name": "VolumeOp Parallel"}'
design doc.", "name": "VolumeOp Parallel"}'
generateName: volumeop-parallel-
spec:
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "The third example of the
design doc.", "inputs": [], "name": "VolumeOp Sequential"}'
design doc.", "name": "VolumeOp Sequential"}'
generateName: volumeop-sequential-
spec:
arguments:
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/tests/compiler/testdata/withitem_basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": null, "inputs": [{"default":
10, "description": "", "name": "my_pipe_param", "type": ""}], "name": "my-pipeline"}'
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default":
10, "name": "my_pipe_param"}], "name": "my-pipeline"}'
generateName: my-pipeline-
spec:
arguments:
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/tests/compiler/testdata/withitem_nested.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": null, "inputs": [{"default":
10, "description": "", "name": "my_pipe_param", "type": ""}], "name": "my-pipeline"}'
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default":
10, "name": "my_pipe_param"}], "name": "my-pipeline"}'
generateName: my-pipeline-
spec:
arguments:
Expand Down

0 comments on commit 83f4553

Please sign in to comment.