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 <tyler.smith@windriver.com>
This commit is contained in:
Tyler Smith 2018-11-28 19:58:33 -05:00
parent 37f0d72439
commit e307108c46
2 changed files with 46 additions and 12 deletions

View File

@ -178,4 +178,20 @@ spec:
- name: config-volume-{{- $root.Values.global.name }}
mountPath: {{ $mount }}
{{- end }}
{{- end }}
---
# 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 }}

View File

@ -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: