Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize KFP input/output params in kwargs #2533

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion elyra/pipeline/kfp/processor_kfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,11 @@ def _cc_pipeline(self,
operation.component_params_as_dict.pop(parameter, None)

# Create ContainerOp instance and assign appropriate user-provided name
container_op = factory_function(**operation.component_params_as_dict)
sanitized_component_params = {
self._sanitize_param_name(name): value
for name, value in operation.component_params_as_dict.items()
}
container_op = factory_function(**sanitized_component_params)
container_op.set_display_name(operation.name)

if operation.doc:
Expand Down Expand Up @@ -692,6 +696,29 @@ def _sanitize_operation_name(name: str) -> str:
"""
return re.sub('-+', '-', re.sub('[^-_0-9A-Za-z ]+', '-', name)).lstrip('-').rstrip('-')

@staticmethod
def _sanitize_param_name(name: str) -> str:
"""
Sanitize a component parameter name.

Behavior is mirrored from how Kubeflow 1.X sanitizes identifier names:
- https://github.com/kubeflow/pipelines/blob/1.8.1/sdk/python/kfp/components/_naming.py#L32-L42
- https://github.com/kubeflow/pipelines/blob/1.8.1/sdk/python/kfp/components/_naming.py#L49-L50
"""
normalized_name = name.lower()

# remove non-word characters
normalized_name = re.sub(r'[\W_]', ' ', normalized_name)

# no double spaces, leading or trailing spaces
normalized_name = re.sub(' +', ' ', normalized_name).strip()

# no leading digits
if re.match(r'\d', normalized_name):
normalized_name = 'n' + normalized_name

return normalized_name.replace(' ', '_')


class KfpPipelineProcessorResponse(PipelineProcessorResponse):
_type = RuntimeProcessorType.KUBEFLOW_PIPELINES
Expand Down