Thanks to visit codestin.com
Credit goes to github.com

Skip to content

create_namespaced_binding() method shows target.name: Required value #547

Open
@abushoeb

Description

@abushoeb

When calling the API create_namespaced_binding() method like so:

config.load_kube_config()
v1 = client.CoreV1Api()
v1.create_namespaced_binding(namespace, body)

The following error is thrown:

Exception when calling CoreV1Api->create_namespaced_binding: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Date': 'Wed, 06 Jun 2018 20:55:04 GMT', 'Content-Length': '120'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"target.name: Required value","code":500} 

Also when I use body = client.V1Binding() following error is thrown:

 File "/usr/lib/python2.7/site-packages/kubernetes/client/models/v1_binding.py", line 64, in __init__
    self.target = target
  File "/usr/lib/python2.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`

Environment is:

Both Python 2.7 and Python 3.6  
Metadata-Version: 2.1
Name: kubernetes
Version: 6.0.0

Full code for the custom scheduler

from kubernetes import client, config, watch
from kubernetes.client.rest import ApiException
config.load_kube_config()
v1 = client.CoreV1Api()

scheduler_name = 'custom-scheduler-test'

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'):
    body = client.V1ConfigMap()
    # or this # body = client.V1Binding() 
    target = client.V1ObjectReference()
    target.kind = 'Node'
    target.apiVersion = 'v1'
    target.name = node
    meta = client.V1ObjectMeta()
    meta.name = name
    body.target = target
    body.metadata = meta
    return v1.create_namespaced_binding(namespace, body)

def main():
    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 ApiException as e:
                print ("Exception when calling CoreV1Api->create_namespaced_binding: %s\n" % e)

if __name__ == '__main__':
    main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions