Support host delete for kubernetes nodes

When a host is deleted, the VIM will now use the kubernetes API
to delete the kubernetes node, if kubernetes is configured.

Story: 2002843
Task: 27032

Change-Id: I7528baabe9fff96b092871b5615d2aa75165fbee
Signed-off-by: Bart Wensley <barton.wensley@windriver.com>
This commit is contained in:
Bart Wensley 2018-10-12 09:26:59 -05:00
parent 7113af25ef
commit 5be8168832
2 changed files with 42 additions and 15 deletions

View File

@ -108,3 +108,17 @@ def untaint_node(node_name, effect, key):
response = kube_client.patch_node(node_name, body)
return Result(response)
def delete_node(node_name):
"""
Delete a node
"""
# Get the client.
kube_client = get_client()
# Delete the node
body = kubernetes.client.V1DeleteOptions()
response = kube_client.delete_node(node_name, body)
return Result(response)

View File

@ -1078,6 +1078,19 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI):
if httplib.NOT_FOUND != e.http_status_code:
raise
if self._host_supports_kubernetes(host_personality):
response['reason'] = 'failed to delete kubernetes services'
# Send the delete request to kubernetes.
future.work(kubernetes_client.delete_node, host_name)
future.result = (yield)
if not future.result.is_complete():
DLOG.error("Kubernetes delete_node failed, operation "
"did not complete, host_uuid=%s, host_name=%s."
% (host_uuid, host_name))
return
response['completed'] = True
response['reason'] = ''
@ -1148,6 +1161,21 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI):
self._platform_token = future.result.data
if self._host_supports_kubernetes(host_personality):
response['reason'] = 'failed to enable kubernetes services'
# To enable kubernetes we remove the NoExecute taint from the
# node. This allows new pods to be scheduled on the node.
future.work(kubernetes_client.untaint_node,
host_name, "NoExecute", "services")
future.result = (yield)
if not future.result.is_complete():
DLOG.error("Kubernetes untaint_node failed, operation "
"did not complete, host_uuid=%s, host_name=%s."
% (host_uuid, host_name))
return
if self._host_supports_neutron(host_personality):
response['reason'] = 'failed to get neutron extensions'
@ -1223,21 +1251,6 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI):
"did not complete, host_uuid=%s, host_name=%s."
% (host_uuid, host_name))
if self._host_supports_kubernetes(host_personality):
response['reason'] = 'failed to enable kubernetes services'
# To enable kubernetes we remove the NoExecute taint from the
# node. This allows new pods to be scheduled on the node.
future.work(kubernetes_client.untaint_node,
host_name, "NoExecute", "services")
future.result = (yield)
if not future.result.is_complete():
DLOG.error("Kubernetes untaint_node failed, operation "
"did not complete, host_uuid=%s, host_name=%s."
% (host_uuid, host_name))
return
response['completed'] = True
response['reason'] = ''