From e307108c460fd02bdf6ab8affa047805985f33ac Mon Sep 17 00:00:00 2001 From: Tyler Smith Date: Wed, 28 Nov 2018 19:58:33 -0500 Subject: [PATCH] Cleaning up after application removal This commit adds commands that run after the armada removal to delete the pvs that are linked to pvcs from the openstack namespace and then deletes the namespace. The ceph-etc configmap was also added to the rdb-provisioner chart to remove the manual workaround. Change-Id: I546cebee549bc3ef81693692579596d2d72ebf95 Story: 2003908 Task: 28130 Signed-off-by: Tyler Smith --- .../templates/pre-install-check-ceph.yaml | 18 ++++++++- .../sysinv/sysinv/conductor/kube_app.py | 40 ++++++++++++++----- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/kubernetes/helm-charts/rbd-provisioner/templates/pre-install-check-ceph.yaml b/kubernetes/helm-charts/rbd-provisioner/templates/pre-install-check-ceph.yaml index 32f25129ab..8bd386e276 100644 --- a/kubernetes/helm-charts/rbd-provisioner/templates/pre-install-check-ceph.yaml +++ b/kubernetes/helm-charts/rbd-provisioner/templates/pre-install-check-ceph.yaml @@ -178,4 +178,20 @@ spec: - name: config-volume-{{- $root.Values.global.name }} mountPath: {{ $mount }} {{- end }} -{{- end }} \ No newline at end of file +--- +# This ConfigMap is needed because we're not using ceph's helm chart +apiVersion: v1 +kind: ConfigMap +metadata: + name: ceph-etc + # This is the name of the openstack application's namespace + namespace: openstack +data: + ceph.conf: | + [global] + auth_supported = none + {{ $monitors := $defaults.monitors }}{{ range $index, $element := $monitors}} + [mon.{{- $index }}] + mon_addr = {{ $element }} + {{- end }} +{{- end }} diff --git a/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py b/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py index d3f45a05f0..2fa0664168 100644 --- a/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py +++ b/sysinv/sysinv/sysinv/sysinv/conductor/kube_app.py @@ -719,25 +719,43 @@ class AppOperator(object): if self._make_armada_request_with_monitor(app, constants.APP_DELETE_OP): if app.system_app: try: - p1 = subprocess.Popen(['kubectl', 'get', 'pods', '-n', - 'openstack'], - stdout=subprocess.PIPE) - p2 = subprocess.Popen(['awk', '/osh-.*-test/{print $1}'], + # TODO convert these kubectl commands to use the k8s api + p1 = subprocess.Popen( + ['kubectl', '--kubeconfig=/etc/kubernetes/admin.conf', + 'get', 'pvc', '--no-headers', '-n', 'openstack'], + stdout=subprocess.PIPE) + p2 = subprocess.Popen(['awk', '{print $3}'], stdin=p1.stdout, stdout=subprocess.PIPE) - p3 = subprocess.Popen(['xargs', '-i', 'kubectl', - 'delete', 'pods', '-n', 'openstack', - '{}'], stdin=p2.stdout, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + p3 = subprocess.Popen( + ['xargs', '-i', 'kubectl', + '--kubeconfig=/etc/kubernetes/admin.conf', 'delete', + 'pv', '{}', '--wait=false'], + stdin=p2.stdout, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + p1.stdout.close() p2.stdout.close() out, err = p3.communicate() if not err: - LOG.info("Old test pods cleanup completed.") + LOG.info("Persistent Volumes marked for deletion.") except Exception as e: - LOG.exception("Failed to clean up test pods after app " + LOG.exception("Failed to clean up PVs after app " "removal: %s" % e) + + try: + p1 = subprocess.Popen( + ['kubectl', '--kubeconfig=/etc/kubernetes/admin.conf', + 'delete', 'namespace', 'openstack'], + stdout=subprocess.PIPE) + out, err = p1.communicate() + if not err: + LOG.info("Openstack namespace delete completed.") + except Exception as e: + LOG.exception("Failed to clean up openstack namespace " + "after app removal: %s" % e) + self._update_app_status(app, constants.APP_UPLOAD_SUCCESS) LOG.info("Application (%s) remove completed." % app.name) else: