Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch] Improve uninstall pipeline #182

Merged
merged 17 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 61 additions & 13 deletions image/cli/mascli/functions/uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ EOM
function check_mas_project_exists() {
MAS_NS="mas-$MAS_INSTANCE_ID-core"

check_project_exists $MAS_NS

if [ "$?" == "0" ]; then
if check_project_exists $MAS_NS; then
export MAS_NS
else
echo -e "${COLOR_RED}Error: The project \"${MAS_NS}\"${COLOR_RESET} does not exist.\n"
Expand Down Expand Up @@ -60,11 +58,61 @@ function uninstall_noninteractive() {
[[ -z "$MAS_INSTANCE_ID" ]] && uninstall_help "MAS_INSTANCE_ID is not set"
}

# This function checks if dependencies are set to "uninstall"
function deps_prompt_conditions() {
key="$1"
case $key in
SLS_ACTION)
if [[ ${IBM_CATALOGS_ACTION} == "uninstall" ]] || [[ ${COMMON_SERVICES_ACTION} == "uninstall" ]] || [[ ${CERT_MANAGER_ACTION} == "uninstall" ]]; then
true
else
false
fi
;;
MONGODB_ACTION)
if [[ ${IBM_CATALOGS_ACTION} == "uninstall" ]] || [[ ${COMMON_SERVICES_ACTION} == "uninstall" ]] || [[ ${CERT_MANAGER_ACTION} == "uninstall" ]]; then
true
else
false
fi
;;
UDS_ACTION)
if [[ ${IBM_CATALOGS_ACTION} == "uninstall" ]] || [[ ${COMMON_SERVICES_ACTION} == "uninstall" ]]; then
true
else
false
fi
;;
CERT_MANAGER_ACTION)
if [[ ${IBM_CATALOGS_ACTION} == "uninstall" ]] || [[ ${COMMON_SERVICES_ACTION} == "uninstall" ]]; then
true
else
false
fi
;;
COMMON_SERVICES_ACTION)
if [[ ${IBM_CATALOGS_ACTION} == "uninstall" ]]; then
true
else
false
fi
;;
*)
# unknown key
false
;;
esac
}

function validate_action_param() {
msg=$1
action=$2

if [[ -z ${!action} ]] || [[ ${!action} != "none" ]] && [[ ${!action} != "uninstall" ]]; then
if deps_prompt_conditions $action; then
export $action="uninstall"
return
fi
if prompt_for_confirm "$msg"; then
export $action="uninstall"
else
Expand All @@ -77,13 +125,13 @@ function prompt_for_deps_to_uninstall() {
echo
echo_h2 "2. Uninstall MAS Dependencies"

validate_action_param "Uninstall IBM User Data Services?" UDS_ACTION
validate_action_param "Uninstall IBM Suite Licensing Service?" SLS_ACTION
validate_action_param "Uninstall MongoDB?" MONGODB_ACTION
validate_action_param "Uninstall Cluster Monitoring?" CLUSTER_MONITORING_ACTION
validate_action_param "Uninstall IBM Cert Manager?" CERT_MANAGER_ACTION
validate_action_param "Uninstall IBM Common Services?" COMMON_SERVICES_ACTION
validate_action_param "Uninstall IBM Catalogs?" IBM_CATALOGS_ACTION
validate_action_param "Uninstall IBM Common Services?" COMMON_SERVICES_ACTION
validate_action_param "Uninstall IBM Cert Manager?" CERT_MANAGER_ACTION
validate_action_param "Uninstall IBM User Data Services?" UDS_ACTION
validate_action_param "Uninstall MongoDB?" MONGODB_ACTION
validate_action_param "Uninstall IBM Suite Licensing Service?" SLS_ACTION
}

function review_uninstall_settings() {
Expand All @@ -101,13 +149,13 @@ function review_uninstall_settings() {
echo "${TEXT_DIM}"
echo_h2 "MAS Dependencies"

echo_reset_dim "IBM User Data Services .......... Action: ${COLOR_MAGENTA}${UDS_ACTION}"
echo_reset_dim "IBM Suite Licensing Service ..... Action: ${COLOR_MAGENTA}${SLS_ACTION}"
echo_reset_dim "MongoDB ......................... Action: ${COLOR_MAGENTA}${MONGODB_ACTION}"
echo_reset_dim "Cluster Monitoring .............. Action: ${COLOR_MAGENTA}${CLUSTER_MONITORING_ACTION}"
echo_reset_dim "IBM Cert Manager ................ Action: ${COLOR_MAGENTA}${CERT_MANAGER_ACTION}"
echo_reset_dim "IBM Common Services ............. Action: ${COLOR_MAGENTA}${COMMON_SERVICES_ACTION}"
echo_reset_dim "IBM Catalogs .................... Action: ${COLOR_MAGENTA}${IBM_CATALOGS_ACTION}"
echo_reset_dim "IBM Common Services ............. Action: ${COLOR_MAGENTA}${COMMON_SERVICES_ACTION}"
echo_reset_dim "IBM Cert Manager ................ Action: ${COLOR_MAGENTA}${CERT_MANAGER_ACTION}"
echo_reset_dim "IBM User Data Services .......... Action: ${COLOR_MAGENTA}${UDS_ACTION}"
echo_reset_dim "MongoDB ......................... Action: ${COLOR_MAGENTA}${MONGODB_ACTION}"
echo_reset_dim "IBM Suite Licensing Service ..... Action: ${COLOR_MAGENTA}${SLS_ACTION}"

echo
reset_colors
Expand Down
11 changes: 5 additions & 6 deletions tekton/generate-tekton-pipelineruns.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- hosts: localhost
- name: Generate Tekton PipelineRuns
hosts: localhost
any_errors_fatal: true
vars:
mas_tekton_version: latest
Expand All @@ -15,15 +16,14 @@
# 1. Prepare tmp and target directory for the pipeline build
# -------------------------------------------------------------------------
- name: Create tmp directory
file:
ansible.builtin.file:
path: "{{ params_tmp_dir }}"
state: directory
- name: Create target directory
file:
ansible.builtin.file:
path: "{{ pipelinerun_target_dir }}"
state: directory


# 2. Load parameter lists into Ansible variables
# -------------------------------------------------------------------------
# This could be done in one step, but using a template lookup, but generating
Expand All @@ -43,7 +43,7 @@
- upgrade

- name: "Load intermediate files to variables"
include_vars:
ansible.builtin.include_vars:
file: "{{ params_tmp_dir }}/{{ item }}.yml"
name: "{{ item }}_params_definition"
with_items:
Expand All @@ -55,7 +55,6 @@
- uninstall
- upgrade


# 3. Generate PipelineRun templates
# -------------------------------------------------------------------------
- name: Generate install PipelineRun templates
Expand Down
5 changes: 3 additions & 2 deletions tekton/generate-tekton-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- hosts: localhost
- name: Generate Tekton Pipelines
hosts: localhost
any_errors_fatal: true
vars:
mas_tekton_version: latest
Expand All @@ -13,7 +14,7 @@
# 1. Prepare tmp and target directory for the pipeline build
# -------------------------------------------------------------------------
- name: Create target directory
file:
ansible.builtin.file:
path: "{{ pipeline_target_dir }}"
state: directory

Expand Down
11 changes: 5 additions & 6 deletions tekton/generate-tekton-tasks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- hosts: localhost
- name: Generate Tekton Tasks
hosts: localhost
any_errors_fatal: true
vars:
mas_tekton_version: latest
Expand All @@ -10,11 +11,10 @@
# 1. Prepare tmp and target directory for the tasks build
# -------------------------------------------------------------------------
- name: Create target directory
file:
ansible.builtin.file:
path: "{{ task_target_dir }}"
state: directory


# 2. Generate Tasks (Dependencies)
# -------------------------------------------------------------------------
- name: Generate Tasks (Dependencies)
Expand All @@ -38,7 +38,7 @@
- sls
- uds

# 2. Generate Tasks (FVT)
# 3. Generate Tasks (FVT)
# -------------------------------------------------------------------------
- name: Generate Tasks (FVT)
ansible.builtin.template:
Expand All @@ -51,8 +51,7 @@
- fvt-core-ui
- fvt-run-suite


# 3. Generate Tasks (Suite)
# 4. Generate Tasks (Suite)
# -------------------------------------------------------------------------
- name: Generate Tasks (Suite)
ansible.builtin.template:
Expand Down
39 changes: 16 additions & 23 deletions tekton/generate-tekton-upgrade-with-fvt.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- hosts: localhost
- name: Generate Tekton Upgrade with FVT
hosts: localhost
any_errors_fatal: true
vars:
mas_tekton_version: latest
Expand All @@ -16,23 +17,22 @@
task_target_dir: target/tasks
tasks:

# 0. Prepare tmp and target directory for the pipeline build
# 1. Prepare tmp and target directory for the pipeline build
# -------------------------------------------------------------------------
- name: Create tmp directory
file:
ansible.builtin.file:
path: "{{ params_tmp_dir }}"
state: directory
- name: Create target directory (pipelines)
file:
ansible.builtin.file:
path: "{{ pipeline_target_dir }}"
state: directory
- name: Create target directory (tasks)
file:
ansible.builtin.file:
path: "{{ task_target_dir }}"
state: directory


# 1. Load parameter lists into Ansible variables
# 2. Load parameter lists into Ansible variables
# -------------------------------------------------------------------------
# This could be done in one step, but using a template lookup, but generating
# the intermediate files and processing this in two steps allows for easier
Expand All @@ -50,7 +50,7 @@
- upgrade

- name: "Load intermediate files to variables"
include_vars:
ansible.builtin.include_vars:
file: "{{ params_tmp_dir }}/{{ item }}.yml"
name: "{{ item }}_params_definition"
with_items:
Expand All @@ -61,33 +61,29 @@
- install
- upgrade


# 2. Combine common + install + fvt + upgrade lists for upgrade-with-fvt
# 3. Combine common + install + fvt + upgrade lists for upgrade-with-fvt
# -------------------------------------------------------------------------
- name: "Load upgrade-test raw parameters list into a variable"
ansible.builtin.set_fact:
upgrade_test_raw_params_definition: "{{ common_params_definition.params + install_params_definition.params + fvt_params_definition.params + upgrade_params_definition.params }}"


# 3. Load Source & Target Upgrade Test attributes
# 4. Load Source & Target Upgrade Test attributes
# -------------------------------------------------------------------------
# Used to rename from/to parameters properly in upgrade-test pipeline
- name: "Load source target parameters"
ansible.builtin.set_fact:
params_source_target_list: "{{ params_source_target_list | default([]) + [item] }}"
with_lines: cat "{{ params_src_dir }}/upgrade-test-helper/source-target.txt"


# 4. Not sure what this means
# 5. Not sure what this means
# -------------------------------------------------------------------------
# Run-pipeline task parameters that should not be created in run-pipeline/taskdefs because they will be manually set
- name: "Load manual setting run-pipeline parameters"
ansible.builtin.set_fact:
param_manual_setting_list: "{{ param_manual_setting_list | default([]) + [item] }}"
with_lines: cat "{{ pipeline_src_dir }}/taskdefs/run-pipeline/manual-setting.txt"


# 5. Load parameter list for upgrade-with-fvt into Ansible variables
# 6. Load parameter list for upgrade-with-fvt into Ansible variables
# -------------------------------------------------------------------------
- name: "Generate intermediate files"
ansible.builtin.template:
Expand All @@ -97,23 +93,21 @@
- upgrade-test

- name: "Load intermediate files to variables"
include_vars:
ansible.builtin.include_vars:
file: "{{ params_tmp_dir }}/{{ item }}.yml"
name: "{{ item }}_params_definition"
with_items:
- upgrade-test


# 6. Generate Upgrade Test Pipeline
# 7. Generate Upgrade Test Pipeline
# -------------------------------------------------------------------------
# This pipeline requires the upgrade_test_raw_params_definition variable generated in step 1.5
- name: Generate Upgrade Test Pipeline
ansible.builtin.template:
src: "{{ pipeline_src_dir }}/upgrade-with-fvt.yml.j2"
dest: "{{ pipeline_target_dir }}/upgrade-with-fvt.yaml"


# 7. Generate Upgrade Test PipelineRun template
# 8. Generate Upgrade Test PipelineRun template
# -------------------------------------------------------------------------
- name: Generate install PipelineRun template
ansible.builtin.template:
Expand All @@ -122,8 +116,7 @@
with_items:
- upgrade-with-fvt


# 8. Generate Upgrade Test Tasks
# 9. Generate Upgrade Test Tasks
# -------------------------------------------------------------------------
# These tasks require the *_params_definition variables generated in step 1.1 - 1.4
- name: "Generate Tasks"
Expand Down
Loading