Skip to content

Commit

Permalink
SDK - Support kubernetes client v11 (kubeflow#3319)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun authored and Jeffwan committed Dec 9, 2020
1 parent c8e8aaf commit 82141b0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 42 deletions.
4 changes: 1 addition & 3 deletions sdk/python/kfp/compiler/_k8s_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ def convert_k8s_obj_to_json(k8s_obj):
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
attr_types = (k8s_obj.swagger_types if hasattr(k8s_obj, "swagger_types")
else k8s_obj.openapi_types)
obj_dict = {k8s_obj.attribute_map[attr]: getattr(k8s_obj, attr)
for attr, _ in iteritems(attr_types)
for attr in k8s_obj.attribute_map
if getattr(k8s_obj, attr) is not None}

return {key: convert_k8s_obj_to_json(val)
Expand Down
12 changes: 2 additions & 10 deletions sdk/python/kfp/compiler/_op_to_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,9 @@ def _process_obj(obj: Any, map_to_tmpl_var: dict):
return map_to_tmpl_var.get(str(obj), '{{inputs.parameters.%s}}' % obj.full_name)

# k8s objects (generated from swaggercodegen)
if hasattr(obj, 'swagger_types') and isinstance(obj.swagger_types, dict):
if hasattr(obj, 'attribute_map') and isinstance(obj.attribute_map, dict):
# process everything inside recursively
for key in obj.swagger_types.keys():
setattr(obj, key, _process_obj(getattr(obj, key), map_to_tmpl_var))
# return json representation of the k8s obj
return convert_k8s_obj_to_json(obj)

# k8s objects (generated from openapi)
if hasattr(obj, 'openapi_types') and isinstance(obj.openapi_types, dict):
# process everything inside recursively
for key in obj.openapi_types.keys():
for key in obj.attribute_map.keys():
setattr(obj, key, _process_obj(getattr(obj, key), map_to_tmpl_var))
# return json representation of the k8s obj
return convert_k8s_obj_to_json(obj)
Expand Down
28 changes: 18 additions & 10 deletions sdk/python/kfp/dsl/_container_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,21 @@ class Container(V1Container):
"""
"""
Attributes:
swagger_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
# remove `name` from swagger_types so `name` is not generated in the JSON
swagger_types = {
key: value
for key, value in V1Container.swagger_types.items() if key != 'name'
}
# remove `name` from attribute_map, swagger_types and openapi_types so `name` is not generated in the JSON

if hasattr(V1Container, 'swagger_types'):
swagger_types = {
key: value
for key, value in V1Container.swagger_types.items() if key != 'name'
}
if hasattr(V1Container, 'openapi_types'):
openapi_types = {
key: value
for key, value in V1Container.openapi_types.items() if key != 'name'
}
attribute_map = {
key: value
for key, value in V1Container.attribute_map.items() if key != 'name'
Expand Down Expand Up @@ -572,9 +577,12 @@ class UserContainer(Container):
# adds `mirror_volume_mounts` to `UserContainer` swagger definition
# NOTE inherits definition from `V1Container` rather than `Container`
# because `Container` has no `name` property.
swagger_types = dict(
**V1Container.swagger_types, mirror_volume_mounts='bool')

if hasattr(V1Container, 'swagger_types'):
swagger_types = dict(
**V1Container.swagger_types, mirror_volume_mounts='bool')
if hasattr(V1Container, 'openapi_types'):
openapi_types = dict(
**V1Container.openapi_types, mirror_volume_mounts='bool')
attribute_map = dict(
**V1Container.attribute_map, mirror_volume_mounts='mirrorVolumeMounts')

Expand Down
14 changes: 3 additions & 11 deletions sdk/python/kfp/dsl/_pipeline_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,10 @@ def extract_pipelineparams_from_any(payload) -> List['PipelineParam']:
pipeline_params += extract_pipelineparams_from_any(item)
return list(set(pipeline_params))

# k8s swagger object
if hasattr(payload, 'swagger_types') and isinstance(payload.swagger_types, dict):
# k8s OpenAPI object
if hasattr(payload, 'attribute_map') and isinstance(payload.attribute_map, dict):
pipeline_params = []
for key in payload.swagger_types.keys():
pipeline_params += extract_pipelineparams_from_any(getattr(payload, key))

return list(set(pipeline_params))

# k8s openapi object
if hasattr(payload, 'openapi_types') and isinstance(payload.openapi_types, dict):
pipeline_params = []
for key in payload.openapi_types.keys():
for key in payload.attribute_map:
pipeline_params += extract_pipelineparams_from_any(getattr(payload, key))

return list(set(pipeline_params))
Expand Down
14 changes: 7 additions & 7 deletions sdk/python/kfp/dsl/_resource_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ class Resource(object):
which is used to represent the `resource` property in argo's workflow
template (io.argoproj.workflow.v1alpha1.Template).
"""
"""
Attributes:
swagger_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
swagger_types = {
"action": "str",
"merge_strategy": "str",
"success_condition": "str",
"failure_condition": "str",
"manifest": "str"
}
openapi_types = {
"action": "str",
"merge_strategy": "str",
"success_condition": "str",
"failure_condition": "str",
"manifest": "str"
}
attribute_map = {
"action": "action",
"merge_strategy": "mergeStrategy",
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'python-dateutil',
'PyYAML',
'google-cloud-storage>=1.13.0',
'kubernetes>=8.0.0, <=10.0.0',
'kubernetes>=8.0.0, <12.0.0',
'PyJWT>=1.6.4',
'cryptography>=2.4.2',
'google-auth>=1.6.1',
Expand Down

0 comments on commit 82141b0

Please sign in to comment.