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

Failed to create namespaced custom object with new Kubenertes Client 11.0.0 #1112

Closed
jinchihe opened this issue Mar 13, 2020 · 13 comments
Closed
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@jinchihe
Copy link

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:

  • Kubernetes version (kubectl version): 11.0.0
  • OS (e.g., MacOS 10.13.6):
  • Python version (python --version)
  • Python client version (pip list | grep kubernetes)
@roycaihw
Copy link
Member

/assign

@jinchihe
Copy link
Author

@roycaihw Any plan to fix this? Thanks.

@pingsutw
Copy link

@jinchihe I got the same problem, did you solved it?

@jinchihe
Copy link
Author

@pingsutw I pined to old kubernetes python sdk to work around that.

kindly ping @roycaihw , any updates for this? Thanks!

@pingsutw
Copy link

@pingsutw I pined to old kubernetes python sdk to work around that.

Thanks, it works for me

@nearbody
Copy link

nearbody commented Aug 4, 2020

Add this to the api_client line ~215, solved the issue for now.
elif isinstance(obj, property):
return None

@jinchihe
Copy link
Author

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.

@jinchihe
Copy link
Author

Seems that's cuased by kubernetes client use openapi_types instead of swagger_types from 11.1?
5cddbde#diff-a5cb6b73e3f53f068885d905bd488023

@jinchihe
Copy link
Author

Need to update the generate openapi_types for the crd before calling k8s client.
Close the ticket. Thanks.

@roycaihw
Copy link
Member

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.

@jinchihe
Copy link
Author

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.

@riceluxs1t
Copy link

riceluxs1t commented Jan 15, 2021

@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.

@omlomloml
Copy link

Need to update the generate openapi_types for the crd before calling k8s client.
Close the ticket. Thanks.

@jinchihe
How do I do this?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

6 participants