|
@@ -1,99 +0,0 @@
|
|
|
----
|
|
|
-- name: Check to see if PVC exists in an old namespace
|
|
|
- oc_obj:
|
|
|
- state: list
|
|
|
- kind: pvc
|
|
|
- name: "{{ openshift_metrics_cassandra_pvc_prefix }}-{{ metrics_pvc_index }}"
|
|
|
- namespace: "{{openshift_metrics_old_project}}"
|
|
|
- register: openshift_metrics_cassandra_old_pvc
|
|
|
-
|
|
|
-- name: Set PVC vars
|
|
|
- set_fact:
|
|
|
- pvc_name: "{{ openshift_metrics_cassandra_pvc_prefix }}-{{ metrics_pvc_index }}"
|
|
|
- pvc_exists: "{{ openshift_metrics_cassandra_old_pvc.results.results[0] | length > 0 }}"
|
|
|
-
|
|
|
-- name: Set fact if we need to move to another namespace
|
|
|
- set_fact:
|
|
|
- openshift_metrics_migrate_namespace: "{{ pvc_exists and openshift_metrics_cassandra_old_pvc.results.results[0]['metadata']['name'] == pvc_name }}"
|
|
|
-
|
|
|
-- name: Migrate cassandra PV and PVC to another namespace
|
|
|
- when: openshift_metrics_migrate_namespace
|
|
|
- block:
|
|
|
- - name: Get PV name attached to cassandra PVC
|
|
|
- set_fact:
|
|
|
- openshift_metrics_pv_name: "{{ openshift_metrics_cassandra_old_pvc['results']['results'][0]['spec']['volumeName'] }}"
|
|
|
-
|
|
|
- - name: Get PV object attached to cassandra PVC.
|
|
|
- oc_obj:
|
|
|
- state: list
|
|
|
- kind: pv
|
|
|
- name: "{{ openshift_metrics_pv_name }}"
|
|
|
- namespace: "{{ openshift_metrics_old_project }}"
|
|
|
- register: metrics_pv
|
|
|
-
|
|
|
- - name: Get PV persistent policy attached to cassandra PVC.
|
|
|
- set_fact:
|
|
|
- openshift_metrics_cassandra_pvc_persistent_policy: "{{ metrics_pv['results']['results'][0]['spec']['persistentVolumeReclaimPolicy'] }}"
|
|
|
-
|
|
|
- - name: Set PV persistent volume reclaim policy to Retain
|
|
|
- command: >
|
|
|
- {{ openshift_client_binary }} -n {{ openshift_metrics_old_project }}
|
|
|
- --config={{ mktemp.stdout }}/admin.kubeconfig
|
|
|
- patch pv {{ openshift_metrics_pv_name }} -p '{"spec": {"persistentVolumeReclaimPolicy": "Retain"}}'
|
|
|
-
|
|
|
- - name: Generate persistent volume claim templates for namespace {{ openshift_metrics_project }}
|
|
|
- template:
|
|
|
- src: pvc.j2
|
|
|
- dest: "{{ mktemp.stdout }}/templates/hawkular-cassandra-pvc{{ metrics_pvc_index }}.yaml"
|
|
|
- vars:
|
|
|
- obj_name: "{{ openshift_metrics_cassandra_pvc_prefix }}-{{ metrics_pvc_index }}"
|
|
|
- labels:
|
|
|
- metrics-infra: hawkular-cassandra
|
|
|
- access_modes: "{{ openshift_metrics_cassandra_pvc_access | list }}"
|
|
|
- size: "{{ openshift_metrics_cassandra_pvc_size }}"
|
|
|
- pv_selector: "{{ openshift_metrics_cassandra_pv_selector }}"
|
|
|
- storage_class_name: "{{ openshift_metrics_cassanda_pvc_storage_class_name | default('', true) }}"
|
|
|
- volume_name: "{{ openshift_metrics_pv_name }}"
|
|
|
-
|
|
|
- - name: Create PVC persistent volume claim {{ openshift_metrics_cassandra_pvc_prefix }}-{{ metrics_pvc_index }} for {{ openshift_metrics_project }}
|
|
|
- oc_obj:
|
|
|
- state: present
|
|
|
- name: "{{ openshift_metrics_cassandra_pvc_prefix }}-{{ metrics_pvc_index }}"
|
|
|
- namespace: "{{ openshift_metrics_project }}"
|
|
|
- kind: persistentvolumeclaim
|
|
|
- files:
|
|
|
- - "{{ mktemp.stdout }}/templates/hawkular-cassandra-pvc{{ metrics_pvc_index }}.yaml"
|
|
|
- delete_after: true
|
|
|
-
|
|
|
- - name: Wait for Cassandra persistent volume claim to be created on {{ openshift_metrics_project }}
|
|
|
- oc_obj:
|
|
|
- state: list
|
|
|
- kind: pvc
|
|
|
- name: "{{ openshift_metrics_cassandra_pvc_prefix }}-{{ metrics_pvc_index }}"
|
|
|
- namespace: "{{openshift_metrics_project}}"
|
|
|
- register: openshift_metrics_new_pvc
|
|
|
- until: openshift_metrics_new_pvc.results.results[0] | length > 0
|
|
|
-
|
|
|
- - set_fact:
|
|
|
- openshift_metrics_pvc_uuid: "{{openshift_metrics_new_pvc['results']['results'][0]['metadata']['uid']}}"
|
|
|
-
|
|
|
- - name: Attach PV to the new PVC
|
|
|
- command: >
|
|
|
- {{ openshift_client_binary }} -n {{ openshift_metrics_project }}
|
|
|
- --config={{ mktemp.stdout }}/admin.kubeconfig
|
|
|
- patch pv {{ openshift_metrics_pv_name }} -p '{"spec": {"claimRef": { "namespace": "{{ openshift_metrics_project }}", "name": "{{ openshift_metrics_cassandra_pvc_prefix }}-{{ metrics_pvc_index }}", "uid": "{{ openshift_metrics_pvc_uuid }}" }}}'
|
|
|
-
|
|
|
- - name: Wait until the PV is attached to new PVC
|
|
|
- oc_obj:
|
|
|
- state: list
|
|
|
- kind: pvc
|
|
|
- name: "{{ openshift_metrics_cassandra_pvc_prefix }}-{{ metrics_pvc_index }}"
|
|
|
- namespace: "{{openshift_metrics_project}}"
|
|
|
- register: openshift_metrics_new_pvc
|
|
|
- until: openshift_metrics_new_pvc.results.results[0].spec.volumeName == openshift_metrics_pv_name
|
|
|
-
|
|
|
- - name: Restore persistent volume reclaim policy
|
|
|
- command: >
|
|
|
- {{ openshift_client_binary }} -n {{ openshift_metrics_old_project }}
|
|
|
- --config={{ mktemp.stdout }}/admin.kubeconfig
|
|
|
- patch pv {{ openshift_metrics_pv_name }} -p '{"spec": {"persistentVolumeReclaimPolicy": "{{openshift_metrics_cassandra_pvc_persistent_policy}}"}}'
|