Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
---
- 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 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
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 90 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: 90
delay: 90
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 }}"
Loading
Loading