Skip to content

Commit 84a4ae8

Browse files
authored
MULTIARCH-4696: deprovision issues and cleanup prior are resolved (openshift#58979)
* MULTIARCH-4696: refactor the deprovision routine and fix security-group-delete Signed-off-by: Paul Bastide <[email protected]> * MULTIARCH-4696: refactor the deprovision Signed-off-by: Paul Bastide <[email protected]> --------- Signed-off-by: Paul Bastide <[email protected]>
1 parent 68dbc03 commit 84a4ae8

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

ci-operator/step-registry/upi/deprovision/powervs/cluster/upi-deprovision-powervs-cluster-commands.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,6 @@ function download_terraform_binary() {
9999
terraform version
100100
}
101101

102-
# facilitates scp copy from inside the contianer
103-
function fix_user_permissions() {
104-
# Dev Note: scp in a container needs this fix-up
105-
if ! whoami &> /dev/null
106-
then
107-
if [[ -w /etc/passwd ]]
108-
then
109-
echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd
110-
fi
111-
fi
112-
}
113-
114102
# Cleanup prior runs
115103
# VPC: Load Balancers, images, vm instances
116104
# PowerVS: images, pvm instances
@@ -168,7 +156,7 @@ function cleanup_prior() {
168156
echo "Cleaning up the Security Groups"
169157
ibmcloud is security-groups --vpc "${VPC_NAME}" --resource-group-name "${RESOURCE_GROUP}" --output json \
170158
| jq -r '[.[] | select(.name | contains("ocp-sec-group"))] | .[]?.name' \
171-
| xargs --no-run-if-empty -I {} ibmcloud security-group-delete {} --vpc "${VPC_NAME}" --force\
159+
| xargs --no-run-if-empty -I {} ibmcloud is security-group-delete {} --vpc "${VPC_NAME}" --force\
172160
|| true
173161

174162
echo "Cleaning up the VPC Load Balancers"
@@ -202,14 +190,31 @@ function cleanup_prior() {
202190
# Destroy the cluster based on the set configuration / tfvars
203191
function destroy_upi_cluster() {
204192
echo "destroy terraform to build PowerVS UPI cluster"
205-
cp "${SHARED_DIR}"/var-multi-arch-upi.tfvars "${IBMCLOUD_HOME}"/ocp4-upi-powervs/var-multi-arch-upi.tfvars
206-
echo "UPI TFVARS copied: ${IBMCLOUD_HOME}"/ocp4-upi-powervs/data/var-multi-arch-upi.tfvars
207193

208194
cp "${CLUSTER_PROFILE_DIR}"/ssh-privatekey "${IBMCLOUD_HOME}"/ocp4-upi-powervs/data/id_rsa
209195
cp "${CLUSTER_PROFILE_DIR}"/ssh-publickey "${IBMCLOUD_HOME}"/ocp4-upi-powervs/data/id_rsa.pub
210196
chmod 0600 "${IBMCLOUD_HOME}"/ocp4-upi-powervs/data/id_rsa
211197

198+
# Loads the tfvars if it exists in the shared directory
199+
if [ ! -f "${SHARED_DIR}"/var-multi-arch-upi.tfvars ]
200+
then
201+
echo "No tfvars provided. exiting..."
202+
exit 0
203+
fi
204+
205+
cp "${SHARED_DIR}"/var-multi-arch-upi.tfvars "${IBMCLOUD_HOME}"/ocp4-upi-powervs/var-multi-arch-upi.tfvars
206+
echo "UPI TFVARS copied: ${IBMCLOUD_HOME}"/ocp4-upi-powervs/data/var-multi-arch-upi.tfvars
207+
208+
# Loads the tfstate if it exists in the shared directory
209+
if [ ! -f "${SHARED_DIR}"/terraform.tfstate ]
210+
then
211+
echo "No tfstate file provided"
212+
exit 0
213+
fi
214+
212215
cp "${SHARED_DIR}"/terraform.tfstate "${IBMCLOUD_HOME}"/ocp4-upi-powervs/data/terraform.tfstate
216+
217+
# Destroys the current installation for this run
213218
cd "${IBMCLOUD_HOME}"/ocp-install-dir/ocp4-upi-powervs && \
214219
"${IBMCLOUD_HOME}"/ocp-install-dir/terraform init && \
215220
"${IBMCLOUD_HOME}"/ocp-install-dir/terraform destroy -auto-approve \
@@ -229,13 +234,8 @@ setup_ibmcloud_cli
229234
download_terraform_binary
230235
download_automation_code
231236
login_ibmcloud
232-
233-
if [ -f "${SHARED_DIR}"/var-multi-arch-upi.tfvars ]
234-
then
235-
cleanup_prior
236-
fix_user_permissions
237-
destroy_upi_cluster
238-
fi
237+
cleanup_prior
238+
destroy_upi_cluster
239239

240240
echo "IBM Cloud PowerVS resources destroyed successfully $(date)"
241241

ci-operator/step-registry/upi/install/powervs/cluster/upi-install-powervs-cluster-commands.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function cleanup_prior() {
204204
echo "Cleaning up the Security Groups"
205205
ibmcloud is security-groups --vpc "${VPC_NAME}" --resource-group-name "${RESOURCE_GROUP}" --output json \
206206
| jq -r '[.[] | select(.name | contains("ocp-sec-group"))] | .[]?.name' \
207-
| xargs --no-run-if-empty -I {} ibmcloud security-group-delete {} --vpc "${VPC_NAME}" --force\
207+
| xargs --no-run-if-empty -I {} ibmcloud is security-group-delete {} --vpc "${VPC_NAME}" --force\
208208
|| true
209209
210210
echo "Cleaning up the VPC Load Balancers"

0 commit comments

Comments
 (0)