Jack Lucas | 45cb899 | 2018-08-22 19:29:40 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ================================================================================ |
Jack Lucas | a0a88be | 2019-03-06 17:58:58 -0500 | [diff] [blame] | 3 | # Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. |
Jack Lucas | 45cb899 | 2018-08-22 19:29:40 +0000 | [diff] [blame] | 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, |
Jack Lucas | a0a88be | 2019-03-06 17:58:58 -0500 | [diff] [blame] | 28 | # at the time this script runs, we have no guarantees about what other components are |
Jack Lucas | 45cb899 | 2018-08-22 19:29:40 +0000 | [diff] [blame] | 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 |
Jack Lucas | a0a88be | 2019-03-06 17:58:58 -0500 | [diff] [blame] | 36 | # 'stop' operation on every k8s node. |
Jack Lucas | 45cb899 | 2018-08-22 19:29:40 +0000 | [diff] [blame] | 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 | |
| 43 | set -x |
| 44 | set +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 |
| 49 | CMPASS=$(grep 'admin_password:' /etc/cloudify/config.yaml | cut -d ':' -f2 | tr -d ' ') |
Jack Lucas | a0a88be | 2019-03-06 17:58:58 -0500 | [diff] [blame] | 50 | TYPENAMES=[\\\"dcae.nodes.ContainerizedServiceComponent\\\",\\\"dcae.nodes.ContainerizedServiceComponentUsingDmaap\\\",\\\"dcae.nodes.ContainerizedPlatformComponent\\\",\\\"dcae.nodes.ContainerizedApplication\\\"] |
Jack Lucas | 45cb899 | 2018-08-22 19:29:40 +0000 | [diff] [blame] | 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 | |
| 60 | curl -Ss --user admin:$CMPASS -H "Tenant: default_tenant" "localhost/api/v3.1/deployments?_include=id" \ |
| 61 | | /bin/jq .items[].id \ |
Jack Lucas | a0a88be | 2019-03-06 17:58:58 -0500 | [diff] [blame] | 62 | | xargs -I % sh -c "cfy executions start -d % -p '{'\\\"type_names\\\":${TYPENAMES},\\\"operation\\\":\\\"cloudify.interfaces.lifecycle.stop\\\"'}' execute_operation" |