-
Notifications
You must be signed in to change notification settings - Fork 125
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
Fix edge cases such as disable istio-inject for Tekton compiler #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,18 +26,6 @@ | |
from .. import tekton_api_version | ||
|
||
|
||
class literal_str(str): | ||
"""Literal string class for pyyaml | ||
|
||
Literal string class is used for converting string with newline into | ||
yaml's literal string format with '|'. In pyyaml, literal string | ||
conversion is not natively supported in the default dumper. | ||
Therefore, we need to define this class as part of the dumper | ||
before compiling it into yaml. | ||
""" | ||
pass | ||
|
||
|
||
def _get_base_step(name: str): | ||
"""Base image step for running bash commands. | ||
|
||
|
@@ -329,12 +317,11 @@ def _process_output_artifacts(outputs_dict: Dict[Text, Any], | |
mounted_artifact_paths = [] | ||
for artifact in outputs_dict['artifacts']: | ||
if artifact['name'] in replaced_param_list: | ||
print(replaced_param_list) | ||
copy_artifacts_step['script'] = copy_artifacts_step['script'] + \ | ||
'mc cp $(results.%s.path) storage/%s/runs/$PIPELINERUN/$PODNAME/%s' % (artifact_to_result_mapping[artifact['name']], bucket, artifact['path'].rsplit("/", 1)[1]) | ||
'mc cp $(results.%s.path) storage/%s/runs/$PIPELINERUN/$PODNAME/%s\n' % (artifact_to_result_mapping[artifact['name']], bucket, artifact['path'].rsplit("/", 1)[1]) | ||
else: | ||
copy_artifacts_step['script'] = copy_artifacts_step['script'] + \ | ||
'mc cp %s storage/%s/runs/$PIPELINERUN/$PODNAME/%s' % (artifact['path'], bucket, artifact['path'].rsplit("/", 1)[1]) | ||
'mc cp %s storage/%s/runs/$PIPELINERUN/$PODNAME/%s\n' % (artifact['path'], bucket, artifact['path'].rsplit("/", 1)[1]) | ||
if artifact['path'].rsplit("/", 1)[0] not in mounted_artifact_paths: | ||
volume_mount_step_template.append({'name': artifact['name'], 'mountPath': artifact['path'].rsplit("/", 1)[0]}) | ||
volume_template.append({'name': artifact['name'], 'emptyDir': {}}) | ||
|
@@ -445,17 +432,6 @@ def _op_to_template(op: BaseOp, enable_artifacts=False): | |
if processed_op.init_containers: | ||
template['spec']['steps'] = _prepend_steps(processed_op.init_containers, template['spec']['steps']) | ||
|
||
# initial base_step and volume setup | ||
base_step = { | ||
'image': 'busybox', | ||
'name': 'copy-results', | ||
'script': '#!/bin/sh\nset -exo pipefail\n' | ||
} | ||
volume_mount_step_template = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aren't those still being used in the code below? |
||
volume_template = [] | ||
mounted_param_paths = [] | ||
replaced_param_list = [] | ||
|
||
# inputs | ||
input_artifact_paths = processed_op.input_artifact_paths if isinstance(processed_op, dsl.ContainerOp) else None | ||
artifact_arguments = processed_op.artifact_arguments if isinstance(processed_op, dsl.ContainerOp) else None | ||
|
@@ -475,7 +451,6 @@ def _op_to_template(op: BaseOp, enable_artifacts=False): | |
mount_path = artifact['path'].rsplit("/", 1)[0] | ||
if mount_path not in mounted_param_paths: | ||
_add_mount_path(artifact['name'], artifact['path'], mount_path, volume_mount_step_template, volume_template, mounted_param_paths) | ||
copy_inputs_step['script'] = literal_str(copy_inputs_step['script']) | ||
template['spec']['steps'] = _prepend_steps([copy_inputs_step], template['spec']['steps']) | ||
_update_volumes(template, volume_mount_step_template, volume_template) | ||
|
||
|
@@ -502,11 +477,9 @@ def _op_to_template(op: BaseOp, enable_artifacts=False): | |
replaced_param_list, | ||
artifact_to_result_mapping) | ||
if mounted_param_paths: | ||
copy_results_step['script'] = literal_str(copy_results_step['script']) | ||
template['spec']['steps'].append(copy_results_step) | ||
_update_volumes(template, volume_mount_step_template, volume_template) | ||
if copy_artifacts_step: | ||
copy_artifacts_step['script'] = literal_str(copy_artifacts_step['script']) | ||
template['spec']['steps'].append(copy_artifacts_step) | ||
|
||
# ********************************************************** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
import textwrap | ||
from typing import Callable, Set, List, Text, Dict, Tuple, Any, Union, Optional | ||
|
||
from ._op_to_template import _op_to_template, literal_str | ||
from ._op_to_template import _op_to_template | ||
|
||
from kfp import dsl | ||
from kfp.compiler._default_transformers import add_pod_env | ||
|
@@ -36,18 +36,6 @@ | |
from .. import tekton_api_version | ||
|
||
|
||
def _literal_str_representer(dumper, data): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot the history of this, can you quickly explain why we had to add this and why it's no longer needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to add literal style to make the script part looks nicer. But there's some edge cases with pyyaml when using it on integer since it's designed with yaml 1.1 Here's the definition of literal style in yaml |
||
"""pyyaml representer for literal yaml string dumper | ||
|
||
Create a representer for the literal string class that converts the string | ||
object with newline into yaml's literal string '|' style. | ||
""" | ||
return dumper.represent_scalar(u'tag:yaml.org,2002:str', data, style='|') | ||
|
||
# Add the _literal_str_representer as part of the yaml dumper. | ||
yaml.add_representer(literal_str, _literal_str_representer) | ||
|
||
|
||
class TektonCompiler(Compiler) : | ||
"""DSL Compiler to generate Tekton YAML. | ||
|
||
|
@@ -296,7 +284,7 @@ def _process_resourceOp(self, task_refs, pipeline): | |
valueFrom: '%s' | ||
""" % (value[0], value[1])) | ||
output_values += output_value | ||
tp['value'] = literal_str(output_values) | ||
tp['value'] = output_values | ||
|
||
|
||
def _workflow_with_pipelinerun(self, task_refs, pipeline, pipeline_template, workflow): | ||
|
@@ -497,7 +485,11 @@ def _create_pipeline_workflow(self, args, pipeline, op_transformers=None, pipeli | |
'apiVersion': tekton_api_version, | ||
'kind': 'Pipeline', | ||
'metadata': { | ||
'name': pipeline.name or 'Pipeline' | ||
'name': pipeline.name or 'Pipeline', | ||
'annotations': { | ||
# Disable Istio inject since Tekton cannot run with Istio sidecar | ||
'sidecar.istio.io/inject': 'false' | ||
} | ||
}, | ||
'spec': { | ||
'params': params, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import unittest | ||
import yaml | ||
import re | ||
import textwrap | ||
|
||
from kfp_tekton import compiler | ||
|
||
|
@@ -26,6 +27,24 @@ | |
# in order to generate new "golden" YAML files | ||
GENERATE_GOLDEN_YAML = False | ||
|
||
# License header for Kubeflow project | ||
LICENSE_HEADER = textwrap.dedent("""\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, thanks :-) |
||
# Copyright 2020 kubeflow.org | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""") | ||
|
||
|
||
class TestTektonCompiler(unittest.TestCase): | ||
|
||
|
@@ -236,6 +255,8 @@ def _test_pipeline_workflow(self, | |
compiled = list(yaml.safe_load_all(f)) | ||
if GENERATE_GOLDEN_YAML: | ||
with open(golden_yaml_file, 'w') as f: | ||
f.write(LICENSE_HEADER) | ||
with open(golden_yaml_file, 'a+') as f: | ||
yaml.dump_all(compiled, f, default_flow_style=False) | ||
else: | ||
with open(golden_yaml_file, 'r') as f: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see the
copy-results
step in the compiled YAML and in a comment, does that come from somewhere else?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this into a different function, but somehow it get put back after the merge. We no longer need this over here because it is initiated at the beginning of this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, thanks :-)