What happened (please include outputs or screenshots):
Failed to create namespaced custom object with new Kubenertes Client 11.0.0
/usr/local/lib/python3.5/dist-packages/kubernetes/client/api/custom_objects_api.py:183: in create_namespaced_custom_object
(data) = self.create_namespaced_custom_object_with_http_info(group, version, namespace, plural, body, **kwargs) # noqa: E501
/usr/local/lib/python3.5/dist-packages/kubernetes/client/api/custom_objects_api.py:289: in create_namespaced_custom_object_with_http_info
collection_formats=collection_formats)
/usr/local/lib/python3.5/dist-packages/kubernetes/client/api_client.py:345: in call_api
_preload_content, _request_timeout)
/usr/local/lib/python3.5/dist-packages/kubernetes/client/api_client.py:166: in __call_api
body = self.sanitize_for_serialization(body)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <kubernetes.client.api_client.ApiClient object at 0x7f81a5f375f8>
obj = {'api_version': 'kubeflow.org/v1',
'kind': 'TFJob',
'metadata': {'annotations': None,
'cluster_name': ... 'volumes': None}}}},
'ttl_seconds_after_finished': None},
'status': None}
def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
If obj is list, sanitize each element in the list.
If obj is dict, return the dict.
If obj is OpenAPI model, return the properties dict.
:param obj: The data to serialize.
:return: The serialized form of data.
"""
if obj is None:
return None
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
return [self.sanitize_for_serialization(sub_obj)
for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj)
for sub_obj in obj)
elif isinstance(obj, (datetime.datetime, datetime.date)):
return obj.isoformat()
if isinstance(obj, dict):
obj_dict = obj
else:
# Convert model obj to dict except
# attributes `openapi_types`, `attribute_map`
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
> for attr, _ in six.iteritems(obj.openapi_types)
if getattr(obj, attr) is not None}
E AttributeError: 'V1TFJob' object has no attribute 'openapi_types'
/usr/local/lib/python3.5/dist-packages/kubernetes/client/api_client.py:230: AttributeError
What you expected to happen:
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know?:
Environment:
kubectl version): 11.0.0 python --version)pip list | grep kubernetes)/assign
@roycaihw Any plan to fix this? Thanks.
@jinchihe I got the same problem, did you solved it?
@pingsutw I pined to old kubernetes python sdk to work around that.
kindly ping @roycaihw , any updates for this? Thanks!
@pingsutw I pined to old kubernetes python sdk to work around that.
Thanks, it works for me
Add this to the api_client line ~215, solved the issue for now.
elif isinstance(obj, property):
return None
hello @roycaihw and all,
I found the problem still exists in 12.0.0, any plan to fix the problem? this is a block issue. Thanks.
Seems that's cuased by kubernetes client use openapi_types instead of swagger_types from 11.1?
https://github.com/kubernetes-client/python/commit/5cddbde0bfa2c8e10488978b0294f69c75fe0889#diff-a5cb6b73e3f53f068885d905bd488023
Need to update the generate openapi_types for the crd before calling k8s client.
Close the ticket. Thanks.
Sorry for the late response. Yes we've switch the code generator from swagger codegen to openapi generator, and the attribute was renamed from swagger_types to openapi_types. If you generated models for your custom resources, you need to regenerate them using openapi-generator. You could also use the dynamic client to access custom resources, which do not have this issue.
Sorry for the late response. Yes we've switch the code generator from swagger codegen to openapi generator, and the attribute was renamed from swagger_types to openapi_types. If you generated models for your custom resources, you need to regenerate them using openapi-generator. You could also use the dynamic client to access custom resources, which do not have this issue.
Yeah, I already did that. Thanks.
@roycaihw
I am simply using
client.CoreV1Api().create_namespaced_secret
client.CoreV1Api().create_namespaced_config_map
method and this method also has this issue in version 11.0.0 and 12.0.0. Note that these are not custom resources.