From c71cea744f302fc4302684b9ac7171d088f5f051 Mon Sep 17 00:00:00 2001 From: Brendan More O'Ferrall Date: Wed, 6 Nov 2024 12:05:19 +0000 Subject: [PATCH 1/5] [patch] MAXMIS-886: disable stitching deploy when civil is not enabled2 --- .../tasks/configure-stitching.yml | 193 +++++++++++++++++ .../tasks/main.yml | 196 +----------------- 2 files changed, 199 insertions(+), 190 deletions(-) create mode 100644 ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml diff --git a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml new file mode 100644 index 0000000000..cd870d2c49 --- /dev/null +++ b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml @@ -0,0 +1,193 @@ +--- +- name: "Load default storage class information" + include_vars: "{{ role_path }}/../../common_vars/default_storage_classes.yml" + +- name: Lookup storage classes + kubernetes.core.k8s_info: + api_version: storage.k8s.io/v1 + kind: StorageClass + register: lookup_storageclasses + +- name: "Debug available storage classes" + debug: + msg: "{{ lookup_storageclasses | ibm.mas_devops.getResourceNames }}" + +- name: Storage class if not set by user (ReadWriteMany) + when: stitching_storage_class is not defined or stitching_storage_class == "" + vars: + set_fact: + stitching_storage_class: "{{ lookup_storageclasses | ibm.mas_devops.defaultStorageClass(default_storage_classes_rwx) }}" + +- name: Assert that a storage class has been defined + assert: + that: stitching_storage_class is defined and stitching_storage_class != "" + fail_msg: "stitching_storage_class must be defined" + +- name: "Fail if stitching_pvcname is not provided" + assert: + that: stitching_pvcname is defined and stitching_pvcname != "" + fail_msg: "stitching_pvcname property is required" + +- name: "Fail if stitching_storage_mountpath is not provided" + assert: + that: stitching_storage_mountpath is defined and stitching_storage_mountpath != "" + fail_msg: "stitching_storage_mountpath property is required" + +- name: "Fail if stitching_storage_size is not provided" + assert: + that: stitching_storage_size is defined and stitching_storage_size != "" + fail_msg: "stitching_storage_size property is required" + +- name: "Fail if stitching_storage_mode is not provided" + assert: + that: stitching_storage_mode is defined and stitching_storage_mode != "" + fail_msg: "stitching_storage_mode property is required" + +- name: "Get MAS instance domain" + kubernetes.core.k8s_info: + api_version: "core.mas.ibm.com/v1" + kind: "Suite" + name: "{{ mas_instance_id }}" + namespace: "mas-{{mas_instance_id}}-core" + register: suite_cr_result + retries: 3 + delay: 0 + until: + - suite_cr_result.resources[0].spec.domain is defined + - suite_cr_result.resources[0].spec.domain | length > 0 + +- name: Set MAS domain + set_fact: + mas_domain: "{{ suite_cr_result.resources[0].spec.domain }}" + when: mas_domain is not defined or mas_domain == "" + +- name: "Run Manage image stitching post-configuration: Debug" + debug: + msg: + - "Stitching PVC name ......................... {{ stitching_pvcname }}" + - "Stitching storage class .................... {{ stitching_storage_class }}" + - "Stitching storage size ..................... {{ stitching_storage_size }}" + - "Stitching storage mode ..................... {{ stitching_storage_mode }}" + - "Stitching storage mountpath ................ {{ stitching_storage_mountpath }}" + - "Instance ID ................................ {{ mas_instance_id }}" + - "Workspace ID ............................... {{ mas_workspace_id }}" + - "Manage namespace ........................... {{ manage_namespace }}" + - "MAS domain ................................. {{ mas_domain }}" + - "MAS workspace CR name ...................... {{ mas_ws_cr_name }}" + +- name: Retrieve Manage workspace CR + kubernetes.core.k8s_info: + api_version: apps.mas.ibm.com/v1 + name: "{{ mas_ws_cr_name }}" + namespace: "{{ manage_namespace }}" + kind: ManageWorkspace + register: manageWorkspace + +- name: Retrieve Image Stitching CR if available + kubernetes.core.k8s_info: + api_version: apps.mas.ibm.com/v1 + kind: Imagestitching + register: stitchingCR + +- name: Retrieve current stitching status + set_fact: + deployimagestitching: "{{ manageWorkspace.resources[0].status.components.civil is defined and manageWorkspace.resources[0].status.components.civil.deployimagestitching }}" + stitchingcrReady: "{{ stitchingCR is defined and stitchingCR.resources | length > 0 }}" + +- name: Debug + debug: + msg: "Stitching CR ready: {{ stitchingcrReady }}, deployimagestitching: {{ deployimagestitching }}" + +- name: Check if stitching PVC has already been created + kubernetes.core.k8s_info: + api_version: v1 + kind: PersistentVolumeClaim + name: "{{ mas_instance_id }}-{{ mas_workspace_id }}-{{ stitching_pvcname }}" + namespace: "{{ manage_namespace }}" + register: stitchingPvc + +- name: Create stitching PVC + when: + - stitchingPvc.resources | length == 0 + kubernetes.core.k8s: + state: present + template: templates/imagestitching-pvc.yml.j2 + +- name: Check if PV has been defined in workspace + set_fact: + stitchingpvAdded: "{{ manageWorkspace.resources | length > 0 and manageWorkspace.resources[0].spec.settings.deployment.persistentVolumes is defined and manageWorkspace.resources[0].spec.settings.deployment.persistentVolumes|selectattr('mountPath', 'contains', stitching_storage_mountpath)|length > 0 }}" + +- name: Get current PV count + set_fact: + pvcount: "{{ manageWorkspace.resources[0].spec.settings.deployment.persistentVolumes|length }}" + +- name: Patch Manage Workspace CR with persistent volume definition + when: not stitchingpvAdded + kubernetes.core.k8s_json_patch: + api_version: apps.mas.ibm.com/v1 + name: "{{ mas_ws_cr_name }}" + namespace: "{{ manage_namespace }}" + kind: ManageWorkspace + patch: + - op: add + path: "/spec/settings/deployment/persistentVolumes/{{ pvcount }}" + value: + accessModes: + - "{{ stitching_storage_mode }}" + mountPath: "/{{ stitching_storage_mountpath }}" + pvcName: "{{ stitching_pvcname }}" + size: "{{ stitching_storage_size }}" + storageClassName: "{{ stitching_storage_class }}" + register: patchWorkspace + retries: 10 + delay: 10 + until: + - patchWorkspace.result is defined + - patchWorkspace.result | length > 0 + +- name: Patch Manage Workspace CR with stitching pvc name + when: + - not deployimagestitching + - not stitchingcrReady + kubernetes.core.k8s: + api_version: apps.mas.ibm.com/v1 + name: "{{ mas_ws_cr_name }}" + namespace: "{{ manage_namespace }}" + kind: ManageWorkspace + definition: + spec: + components: + civil: + imagestitchingpvcname: "{{ stitching_pvcname }}" + register: manageWorkspaceUpdate + retries: 10 + delay: 10 + until: + - manageWorkspaceUpdate.result is defined + - manageWorkspaceUpdate.result | length > 0 + +- name: Set system properties for stitching + include_tasks: tasks/set-imagestitching-properties.yml + +- name: Wait 60 mins for image stitching deployment to complete + ignore_errors: true + kubernetes.core.k8s_info: + api_version: v1 + label_selectors: mas.ibm.com/appType=serverBundle + namespace: "{{ manage_namespace }}" + kind: Pod + register: managePodCheck + retries: 60 + delay: 60 + until: + - managePodCheck.resources | length > 0 + - managePodCheck.resources[0].spec.containers | length > 0 + - managePodCheck.resources[0].spec.containers[0].volumeMounts | selectattr('mountPath', 'contains', stitching_storage_mountpath) | length > 0 + +- name: Get stitching status + set_fact: + stitchingDeployed: "{{ managePodCheck.resources | length > 0 and managePodCheck.resources[0].spec.containers | length > 0 and managePodCheck.resources[0].spec.containers[0].volumeMounts | selectattr('mountPath', 'contains', stitching_storage_mountpath) | length > 0 }}" + +- name: Debug + debug: + msg: "Stitching deployed successfully: {{ stitchingDeployed }}" diff --git a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml index feea8c1dac..eef22af3cc 100644 --- a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml +++ b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml @@ -1,201 +1,17 @@ --- -- name: "Load default storage class information" - include_vars: "{{ role_path }}/../../common_vars/default_storage_classes.yml" - -- name: Lookup storage classes - kubernetes.core.k8s_info: - api_version: storage.k8s.io/v1 - kind: StorageClass - register: lookup_storageclasses - -- name: "Debug available storage classes" - debug: - msg: "{{ lookup_storageclasses | ibm.mas_devops.getResourceNames }}" - -- name: Storage class if not set by user (ReadWriteMany) - when: stitching_storage_class is not defined or stitching_storage_class == "" - vars: - set_fact: - stitching_storage_class: "{{ lookup_storageclasses | ibm.mas_devops.defaultStorageClass(default_storage_classes_rwx) }}" - -- name: Assert that a storage class has been defined - assert: - that: stitching_storage_class is defined and stitching_storage_class != "" - fail_msg: "stitching_storage_class must be defined" - -- name: "Fail if stitching_pvcname is not provided" - assert: - that: stitching_pvcname is defined and stitching_pvcname != "" - fail_msg: "stitching_pvcname property is required" - -- name: "Fail if stitching_storage_mountpath is not provided" - assert: - that: stitching_storage_mountpath is defined and stitching_storage_mountpath != "" - fail_msg: "stitching_storage_mountpath property is required" - -- name: "Fail if stitching_storage_size is not provided" - assert: - that: stitching_storage_size is defined and stitching_storage_size != "" - fail_msg: "stitching_storage_size property is required" - -- name: "Fail if stitching_storage_mode is not provided" - assert: - that: stitching_storage_mode is defined and stitching_storage_mode != "" - fail_msg: "stitching_storage_mode property is required" - -- name: "Get MAS instance domain" - kubernetes.core.k8s_info: - api_version: "core.mas.ibm.com/v1" - kind: "Suite" - name: "{{ mas_instance_id }}" - namespace: "mas-{{mas_instance_id}}-core" - register: suite_cr_result - retries: 3 - delay: 0 - until: - - suite_cr_result.resources[0].spec.domain is defined - - suite_cr_result.resources[0].spec.domain | length > 0 - -- name: Set MAS domain - set_fact: - mas_domain: "{{ suite_cr_result.resources[0].spec.domain }}" - when: mas_domain is not defined or mas_domain == "" - -- name: "Run Manage image stitching post-configuration: Debug" - debug: - msg: - - "Stitching PVC name ......................... {{ stitching_pvcname }}" - - "Stitching storage class .................... {{ stitching_storage_class }}" - - "Stitching storage size ..................... {{ stitching_storage_size }}" - - "Stitching storage mode ..................... {{ stitching_storage_mode }}" - - "Stitching storage mountpath ................ {{ stitching_storage_mountpath }}" - - "Instance ID ................................ {{ mas_instance_id }}" - - "Workspace ID ............................... {{ mas_workspace_id }}" - - "Manage namespace ........................... {{ manage_namespace }}" - - "MAS domain ................................. {{ mas_domain }}" - - "MAS workspace CR name ...................... {{ mas_ws_cr_name }}" - - name: Retrieve Manage workspace CR kubernetes.core.k8s_info: api_version: apps.mas.ibm.com/v1 name: "{{ mas_ws_cr_name }}" namespace: "{{ manage_namespace }}" - kind: ManageWorkspace - register: manageWorkspace - -- name: Retrieve Image Stitching CR if available - kubernetes.core.k8s_info: - api_version: apps.mas.ibm.com/v1 - kind: Imagestitching - register: stitchingCR - -- name: Check if Civil is enabled and retrieve current stitching status - set_fact: - civilEnabled: "{{ manageWorkspace.resources[0].status.components.civil is defined and manageWorkspace.resources[0].status.components.civil.enabled }}" - deployimagestitching: "{{ manageWorkspace.resources[0].status.components.civil is defined and manageWorkspace.resources[0].status.components.civil.deployimagestitching }}" - stitchingcrReady: "{{ stitchingCR is defined and stitchingCR.resources | length > 0 }}" - -- name: Debug - debug: - msg: "Civil enabled: {{ civilEnabled }}, Stitching CR ready: {{ stitchingcrReady }}, deployimagestitching: {{ deployimagestitching }}" - -- name: Check if stitching PVC has already been created - kubernetes.core.k8s_info: - api_version: v1 - kind: PersistentVolumeClaim - name: "{{ mas_instance_id }}-{{ mas_workspace_id }}-{{ stitching_pvcname }}" - namespace: "{{ manage_namespace }}" - register: stitchingPvc - -- name: Create stitching PVC - when: - - civilEnabled - - stitchingPvc.resources | length == 0 - kubernetes.core.k8s: - state: present - template: templates/imagestitching-pvc.yml.j2 - -- name: Check if PV has been defined in workspace - set_fact: - stitchingpvAdded: "{{ manageWorkspace.resources | length > 0 and manageWorkspace.resources[0].spec.settings.deployment.persistentVolumes is defined and manageWorkspace.resources[0].spec.settings.deployment.persistentVolumes|selectattr('mountPath', 'contains', stitching_storage_mountpath)|length > 0 }}" + kind: workspaceCR + register: workspaceCR -- name: Get current PV count +- name: Check if Civil is enabled set_fact: - pvcount: "{{ manageWorkspace.resources[0].spec.settings.deployment.persistentVolumes|length }}" - -- name: Patch Manage Workspace CR with persistent volume definition - when: civilEnabled and not stitchingpvAdded - kubernetes.core.k8s_json_patch: - api_version: apps.mas.ibm.com/v1 - name: "{{ mas_ws_cr_name }}" - namespace: "{{ manage_namespace }}" - kind: ManageWorkspace - patch: - - op: add - path: "/spec/settings/deployment/persistentVolumes/{{ pvcount }}" - value: - accessModes: - - "{{ stitching_storage_mode }}" - mountPath: "/{{ stitching_storage_mountpath }}" - pvcName: "{{ stitching_pvcname }}" - size: "{{ stitching_storage_size }}" - storageClassName: "{{ stitching_storage_class }}" - register: patchWorkspace - retries: 10 - delay: 10 - until: - - patchWorkspace.result is defined - - patchWorkspace.result | length > 0 + civilEnabled: "{{ workspaceCR.resources[0].status.components.civil is defined and workspaceCR.resources[0].status.components.civil.enabled }}" -- name: Patch Manage Workspace CR with stitching pvc name +- name: Configure stitching + include_tasks: tasks/configure-stitching.yml when: - civilEnabled - - not deployimagestitching - - not stitchingcrReady - kubernetes.core.k8s: - api_version: apps.mas.ibm.com/v1 - name: "{{ mas_ws_cr_name }}" - namespace: "{{ manage_namespace }}" - kind: ManageWorkspace - definition: - spec: - components: - civil: - imagestitchingpvcname: "{{ stitching_pvcname }}" - register: manageWorkspaceUpdate - retries: 10 - delay: 10 - until: - - manageWorkspaceUpdate.result is defined - - manageWorkspaceUpdate.result | length > 0 - -- name: Set system properties for stitching - include_tasks: tasks/set-imagestitching-properties.yml - when: - - civilEnabled - -- name: Wait 60 mins for image stitching deployment to complete - ignore_errors: true - when: civilEnabled - kubernetes.core.k8s_info: - api_version: v1 - label_selectors: mas.ibm.com/appType=serverBundle - namespace: "{{ manage_namespace }}" - kind: Pod - register: managePodCheck - retries: 60 - delay: 60 - until: - - managePodCheck.resources | length > 0 - - managePodCheck.resources[0].spec.containers | length > 0 - - managePodCheck.resources[0].spec.containers[0].volumeMounts | selectattr('mountPath', 'contains', stitching_storage_mountpath) | length > 0 - -- name: Get stitching status - when: civilEnabled - set_fact: - stitchingDeployed: "{{ managePodCheck.resources | length > 0 and managePodCheck.resources[0].spec.containers | length > 0 and managePodCheck.resources[0].spec.containers[0].volumeMounts | selectattr('mountPath', 'contains', stitching_storage_mountpath) | length > 0 }}" - -- name: Debug - when: civilEnabled - debug: - msg: "Stitching deployed successfully: {{ stitchingDeployed }}" From b1920ee561bab69b5440fbedea99e7c4a47e8c89 Mon Sep 17 00:00:00 2001 From: Brendan More O'Ferrall Date: Wed, 6 Nov 2024 13:07:08 +0000 Subject: [PATCH 2/5] [patch] MAXMIS-886: fix cr name --- .../roles/suite_manage_imagestitching_config/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml index eef22af3cc..fbf7716cc8 100644 --- a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml +++ b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml @@ -4,7 +4,7 @@ api_version: apps.mas.ibm.com/v1 name: "{{ mas_ws_cr_name }}" namespace: "{{ manage_namespace }}" - kind: workspaceCR + kind: ManageWorkspace register: workspaceCR - name: Check if Civil is enabled From cf716436db4c6ff7236a59a21958bce862a47804 Mon Sep 17 00:00:00 2001 From: Brendan More O'Ferrall Date: Wed, 6 Nov 2024 13:59:32 +0000 Subject: [PATCH 3/5] [patch] MAXMIS-886: retries --- .../roles/suite_manage_imagestitching_config/tasks/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml index fbf7716cc8..9db08aec8e 100644 --- a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml +++ b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/main.yml @@ -6,6 +6,10 @@ namespace: "{{ manage_namespace }}" kind: ManageWorkspace register: workspaceCR + retries: 3 + delay: 10 + until: + - workspaceCR.resources | length > 0 - name: Check if Civil is enabled set_fact: From 38de22e469f3c60dec0b35c81a75ac064837c40c Mon Sep 17 00:00:00 2001 From: Brendan More O'Ferrall Date: Wed, 6 Nov 2024 19:38:29 +0000 Subject: [PATCH 4/5] Additional wait for slow environments --- .../tasks/configure-stitching.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml index cd870d2c49..40183494a8 100644 --- a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml +++ b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml @@ -83,6 +83,14 @@ kind: ManageWorkspace register: manageWorkspace +- name: Retrieve Manage workspace CR + kubernetes.core.k8s_info: + api_version: apps.mas.ibm.com/v1 + name: "{{ mas_ws_cr_name }}" + namespace: "{{ manage_namespace }}" + kind: ManageWorkspace + register: workspaceCR + - name: Retrieve Image Stitching CR if available kubernetes.core.k8s_info: api_version: apps.mas.ibm.com/v1 @@ -169,7 +177,7 @@ - name: Set system properties for stitching include_tasks: tasks/set-imagestitching-properties.yml -- name: Wait 60 mins for image stitching deployment to complete +- name: Wait 90 mins for image stitching deployment to complete ignore_errors: true kubernetes.core.k8s_info: api_version: v1 @@ -177,8 +185,8 @@ namespace: "{{ manage_namespace }}" kind: Pod register: managePodCheck - retries: 60 - delay: 60 + retries: 90 + delay: 90 until: - managePodCheck.resources | length > 0 - managePodCheck.resources[0].spec.containers | length > 0 From 1e8a47dbea4b11f7a878c77ee31cda8418646868 Mon Sep 17 00:00:00 2001 From: Brendan More O'Ferrall Date: Wed, 6 Nov 2024 19:42:30 +0000 Subject: [PATCH 5/5] [patch] lint: Remove trailing spaces --- .../tasks/configure-stitching.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml index 40183494a8..c75bd0daba 100644 --- a/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml +++ b/ibm/mas_devops/roles/suite_manage_imagestitching_config/tasks/configure-stitching.yml @@ -90,7 +90,7 @@ namespace: "{{ manage_namespace }}" kind: ManageWorkspace register: workspaceCR - + - name: Retrieve Image Stitching CR if available kubernetes.core.k8s_info: api_version: apps.mas.ibm.com/v1