blob: a072dd4dc7f83f4d2d42a5800122fe00a2efdd05 [file] [log] [blame]
Jack Lucas45cb8992018-08-22 19:29:40 +00001#!/bin/bash
2# ================================================================================
3# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4# ================================================================================
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# ============LICENSE_END=========================================================
17
18# Clean up DCAE during ONAP uninstall
19#
20# When helm delete is being used to uninstall all of ONAP, helm does
21# not know about k8s entities that were created by Cloudify Manager.
22# This script--intended to run as a preUninstall hook when Cloudify Manager itself
23# is undeleted--uses Cloudify to clean up the k8s entities deployed by Cloudify.
24#
25# Rather than using the 'cfy uninstall' command to run a full 'uninstall' workflow
26# against the deployments, this script uses 'cfy executions' to run a 'stop'
27# stop operation against the nodes in each deployment. The reason for this is that,
28# at the time this script run, we have no# guarantees about what other components are
29# still running. In particular, a full 'uninstall' will cause API requests to Consul
30# and will raise RecoverableErrors if it cannot connect. RecoverableErrors send Cloudify
31# into a long retry loop. Instead, we invoke only the 'stop'
32# operation on each node, and the 'stop' operation uses the k8s API (guaranteed to be
33# present) but not the Consul API.
34#
35# Note that the script finds all of the deployments known to Cloudify and runs the
36# 'stop' operation on every node
37# The result of the script is that all of the k8s entities deployed by Cloudify
38# should be destroyed. Cloudify Manager itself isn't fully cleaned up (the deployments and
39# blueprints are left), but that doesn't matter because Cloudify Manager will be
40# destroyed by Helm.
41
42
43set -x
44set +e
45
46# Get the CM admin password from the config file
47# Brittle, but the container is built with an unchanging version of CM,
48# so no real risk of a breaking change
49CMPASS=$(grep 'admin_password:' /etc/cloudify/config.yaml | cut -d ':' -f2 | tr -d ' ')
50TYPENAMES='[dcae.nodes.ContainerizedServiceComponent,dcae.nodes.ContainerizedServiceComponent,dcae.nodes.ContainerizedServiceComponent,dcae.nodes.ContainerizedServiceComponent]'
51
52# Uninstall components managed by Cloudify
53# Get the list of deployment ids known to Cloudify via curl to Cloudify API.
54# The output of the curl is JSON that looks like {"items" :[{"id": "config_binding_service"}, ...], "metadata" :{...}}
55#
56# jq gives us the just the deployment ids (e.g., "config_binding_service"), one per line
57#
58# xargs -I lets us run the cfy executions command once for each deployment id extracted by jq
59
60curl -Ss --user admin:$CMPASS -H "Tenant: default_tenant" "localhost/api/v3.1/deployments?_include=id" \
61| /bin/jq .items[].id \
62| xargs -I % sh -c 'cfy executions start -d % -p type_names=${TYPENAMES} -p operation=cloudify.interfaces.lifecycle.stop execute_operation'