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

Error when trying to patch/replace an object #10

Closed
arikalon1 opened this issue May 15, 2021 · 7 comments
Closed

Error when trying to patch/replace an object #10

arikalon1 opened this issue May 15, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@arikalon1
Copy link

Thanks for the new version. It's great!

When trying yo patch/replace an existing Kubernetes object (configmap/deployment etc), the api returns an error regarding the creationTimestamp field (see the error below)
Removing this field from the generated 'clean_dict' before saving solved it, but I'm not sure this is the correct solution

Code sample:
dep: Deployment = Deployment.readNamespacedDeployment("my-deployment", "default").obj
dep.spec.replicas += 1
dep.patchNamespacedDeployment("my-deployment", "default")

error:
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"ConfigMap in version "v1" cannot be handled as a ConfigMap: v1.ConfigMap.Data: ObjectMeta: v1.ObjectMeta.UID: SelfLink: ResourceVersion: Namespace: Name: CreationTimestamp: unmarshalerDecoder: parsing time "2021-05-15T12:53:45" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "Z07:00", error found in #10 byte of ...|T12:53:45", "name": |..., bigger context ...|data": {"creationTimestamp": "2021-05-15T12:53:45", "name": "jobs-states", "namespace": "robusta", "|...","reason":"BadRequest","code":400}

stack trace:
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/hikaru/model/rel_1_16/v1/v1.py", line 12134, in replaceNamespacedConfigMap
result = the_method(**all_args)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kubernetes/client/api/core_v1_api.py", line 25568, in replace_namespaced_config_map_with_http_info
return self.api_client.call_api(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kubernetes/client/api_client.py", line 348, in call_api
return self.__call_api(resource_path, method,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kubernetes/client/api_client.py", line 180, in __call_api
response_data = self.request(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kubernetes/client/api_client.py", line 399, in request
return self.rest_client.PUT(url,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kubernetes/client/rest.py", line 284, in PUT
return self.request("PUT", url,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kubernetes/client/rest.py", line 233, in request
raise ApiException(http_resp=r)
kubernetes.client.exceptions.ApiException: (400)
Reason: Bad Request

@aantn
Copy link
Contributor

aantn commented May 15, 2021

I'm opening a PR fixing this. The fix is a temporary workaround - a better fix is probably appropriate.

@aantn
Copy link
Contributor

aantn commented May 15, 2021

Some relevant context: kubernetes-client/python#730

@haxsaw haxsaw added the bug Something isn't working label May 20, 2021
@haxsaw
Copy link
Owner

haxsaw commented May 20, 2021

This is interesting; since clean_dict() is only stripping out keys with None values, it would have left alone any datetimes that were supplied to it from the initial read. That means that the underlying client is providing values that itself cannot consume. I can replicate this problem in my integration tests; I'll have a look at the PR.

@aantn
Copy link
Contributor

aantn commented May 20, 2021

The problem is the roundtrip from APIServer -> Python Datatime -> APIServer. It's also worth pointing out the Hikaru doesn't have a concept of datatime fields at all, rather just str fields. Not sure if that is impacting this or not.

@haxsaw
Copy link
Owner

haxsaw commented May 20, 2021

I think we're saying the same thing here. Hikaru does nothing special regarding any field's type unless it is a nested object. So yes, it's due to the round trip, but again I find it interesting that a field that Hikaru doesn't touch is objected to when it goes back into the client that created it.

In terms of what's in the swagger, creationTimestamp's type is listed as 'string' but it's format is simply 'date-time'. I haven't been looking at format thus far as there have been few benefits in Python (int32 vs int64 for example). Even so, it appears to have something to do with timezones, and there's nothing in the format that let's us algorithmically determine that they are important. There are a few other fields that I imagine we'll run into similar problems (Quantity comes to mind), and we'll probably need solutions similar to the PR.

@aantn
Copy link
Contributor

aantn commented May 20, 2021

Yeah, understood.

@haxsaw
Copy link
Owner

haxsaw commented May 27, 2021

Added to 0.5b

@haxsaw haxsaw closed this as completed May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants