Got stuck in:
File "/usr/lib/python3.7/site-packages/kubernetes/client/models/v1_binding.py", line 64, in __init__
self.target = target
File "/usr/lib/python3.7/site-packages/kubernetes/client/models/v1_binding.py", line 156, in target
raise ValueError("Invalid value for target, must not be None")
ValueError: Invalid value for target, must not be None
Could you write more about your use case? The target attribute is mandatory in this model.
I'm trying to create my own scheduler, started with random scheduler example found in net and edited it a bit.
#!/usr/bin/python
import time
import random
import json
from kubernetes import client, config, watch
config.load_kube_config()
v1 = client.CoreV1Api()
scheduler_name = "foobar"
def nodes_available():
ready_nodes = []
for n in v1.list_node().items:
for status in n.status.conditions:
if status.status == "True" and status.type == "Ready":
ready_nodes.append(n.metadata.name)
return ready_nodes
def scheduler(name, node, namespace='default'):
target = client.V1ObjectReference()
target.kind = "Node"
target.api_version = "v1"
target.name = node
meta = client.V1ObjectMeta()
meta.name = name
body = client.V1Binding(target = target)
body.metadata = meta
return v1.create_namespaced_binding(namespace, body)
def main():
print("Scheduler running... ")
w = watch.Watch()
for event in w.stream(v1.list_namespaced_pod, "default"):
if event['object'].status.phase == "Pending" and event['object'].spec.scheduler_name == scheduler_name:
try:
res = scheduler(event['object'].metadata.name, random.choice(nodes_available()))
except client.rest.ApiException as e:
print (json.loads(e.body)['message'])
if __name__ == '__main__':
main()
Here is my code, It looks like it tries to schedule pods which was already scheluded.
body = client.V1Binding(target = target)
this line throws exception that target is null, while it isn't. (Printed this for debug purposes)
Before it throws this exception it sucesfully schelude one pod from queue and then crash.
When I comment line 156, in this file:
"/usr/lib/python3.7/site-packages/kubernetes/client/models/v1_binding.py
It tries to schedule pods which was already scheluded and got message this pod is already on node xyz.
But do not crash in this case.
Kubectl version:"v1.14.1"
I meet same issues. Did you figure it out?
I think I've tracked this down. The file is too large for GitHub to render, but the errant code is in create_namespaced_pod_binding_with_http_info() in kubernetes/client/apis/core_v1_api.py. In that method, it creates the Binding via:
return self.api_client.call_api('/api/v1/namespaces/{namespace}/pods/{name}/binding', 'POST',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='V1Binding',
auth_settings=auth_settings,
async_req=params.get('async_req'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
Note the response_type='V1Binding': That's incorrect. The response from /api/v1/namespaces/{namespace}/pods/{name}/binding is {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success","code":201}
While trying to marshal the Status object into a Binding object, it fails validation due to a missing target attribute.
Unfortunately, this issue still exists in master, and this file is auto-generated from the Swagger definition. I have no idea where to attempt to PR this 馃槩
I can see the incorrect swagger definition in scripts/swagger.json starting at line 22902 in current master (again, file's too big to link to):
"/api/v1/namespaces/{namespace}/pods/{name}/binding": {
"parameters": [
... ],
"post": {
...
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.Binding"
}
},
That response schema should be a Status.
For anyone looking for a quick workaround:
v1 = client.CoreV1Api()
v1.api_client.call_api(f"/api/v1/namespaces/default/pods/{pod_name}/binding",
'POST',
body=binding,
response_type='V1Status',
auth_settings=['BearerToken'])
@tammersaleh my work around, I just catch exceptions thrown by this function. Despite the fact that this exception is being thrown, process of binding Pod to a Node is done.
try:
v1.create_namespaced_binding(namespace, body)
return True
except:
return False
I met the same issue.
Is there a plan to fix it?
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
/remove-lifecycle stale
i met the same problem here any solutions please ?
This looks to be the same issue as #547 (issue now closed, but problem was never resolved).
It has been present (at least) since Python client version 6.0. It seems to be caused by the Python client failing to deserialize the returned data. I have worked around the problem by ignoring the step of deserializing the returned data (suggested by @zhcf):
v1.create_namespaced_binding(namespace, body, _preload_content=False)
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close
@fejta-bot: Closing this issue.
In response to this:
Rotten issues close after 30d of inactivity.
Reopen the issue with/reopen.
Mark the issue as fresh with/remove-lifecycle rotten.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Most helpful comment
This looks to be the same issue as #547 (issue now closed, but problem was never resolved).
It has been present (at least) since Python client version 6.0. It seems to be caused by the Python client failing to deserialize the returned data. I have worked around the problem by ignoring the step of deserializing the returned data (suggested by @zhcf):