From 5be81688324581e5fa3629563392de2685b195b1 Mon Sep 17 00:00:00 2001 From: Bart Wensley Date: Fri, 12 Oct 2018 09:26:59 -0500 Subject: [PATCH] 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 --- .../nfvi_plugins/clients/kubernetes_client.py | 14 ++++++ .../nfvi_plugins/nfvi_infrastructure_api.py | 43 ++++++++++++------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/clients/kubernetes_client.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/clients/kubernetes_client.py index a2b556e2..ea54cff8 100644 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/clients/kubernetes_client.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/clients/kubernetes_client.py @@ -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) diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py index c3bca7b4..a9b9b72f 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py @@ -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'] = ''