Skip to content

Commit

Permalink
chore(sdk): Warn on container component without command. Fixes #4800 (#…
Browse files Browse the repository at this point in the history
…6335)

* Warn on container component without command

* address cr comments
  • Loading branch information
chensun authored Aug 14, 2021
1 parent f6540c5 commit 50f7dcd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sdk/python/kfp/components/_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from collections import OrderedDict
import pathlib
from typing import Any, Callable, List, Mapping, NamedTuple, Sequence, Union
import warnings

from ._naming import _sanitize_file_name, _sanitize_python_function_name, generate_unique_name_conversion_table
from ._yaml_utils import load_yaml
from .structures import *
Expand Down Expand Up @@ -163,6 +165,17 @@ def _load_component_spec_from_component_text(text) -> ComponentSpec:
component_dict = load_yaml(text)
component_spec = ComponentSpec.from_dict(component_dict)

if isinstance(component_spec.implementation, ContainerImplementation) and (
component_spec.implementation.container.command is None):
warnings.warn(
'Container component must specify command to be compatible with KFP '
'v2 compatible mode and emissary executor, which will be the default'
' executor for KFP v2.'
'https://www.kubeflow.org/docs/components/pipelines/installation/choose-executor/',
category=FutureWarning,
)


# Calculating hash digest for the component
import hashlib
data = text if isinstance(text, bytes) else text.encode('utf-8')
Expand Down
15 changes: 15 additions & 0 deletions sdk/python/kfp/components_tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,21 @@ def test_fail_type_compatibility_check_for_types_with_different_schemas(self):
with self.assertRaises(TypeError):
b_task = task_factory_b(in1=a_task.outputs['out1'])

def test_container_component_without_command_should_warn(self):
component_a = '''\
name: component without command
inputs:
- {name: in1, type: String}
implementation:
container:
image: busybox
'''

with self.assertWarnsRegex(
FutureWarning,
'Container component must specify command to be compatible with '
'KFP v2 compatible mode and emissary executor'):
task_factory_a = comp.load_component_from_text(component_a)

if __name__ == '__main__':
unittest.main()

0 comments on commit 50f7dcd

Please sign in to comment.