Skip to content

Commit 3c094b9

Browse files
fix(image-upload): Harden the image-upload ansible against upload failures and restarts
1 parent c43bd14 commit 3c094b9

4 files changed

Lines changed: 65 additions & 6 deletions

File tree

ansible/roles/openstack_glance_image_upload/tasks/main.yml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,29 @@
4545
- understack_images | length > 0
4646
- item.images | length == 0
4747

48-
- name: Build list of images that were successfully reserved (newly created)
48+
- name: Build list of images that need data upload (newly reserved or incomplete)
4949
ansible.builtin.set_fact:
5050
_reserved_image_uuids: >-
51-
{{ reserve_result.results
51+
{{
52+
(reserve_result.results
5253
| default([])
5354
| selectattr('changed', 'defined')
5455
| selectattr('changed')
5556
| map(attribute='item')
5657
| map(attribute='item')
5758
| map(attribute='uuid')
58-
| list }}
59+
| list)
60+
+
61+
(existing_image_info.results
62+
| default([])
63+
| selectattr('images', 'defined')
64+
| selectattr('images')
65+
| map(attribute='images')
66+
| map('first')
67+
| selectattr('status', 'in', ['queued', 'uploading'])
68+
| map(attribute='id')
69+
| list)
70+
}}
5971
6072
- name: Download images that still need data upload
6173
ansible.builtin.get_url:
@@ -83,7 +95,7 @@
8395
- understack_images | length > 0
8496
- item.uuid in _reserved_image_uuids
8597

86-
- name: Upload image data to queued Glance images
98+
- name: Upload image data to queued or uploading Glance images
8799
openstack.cloud.image:
88100
cloud: "{{ openstack_cloud | default(omit) }}"
89101
name: "{{ item.images[0].name }}"
@@ -100,7 +112,20 @@
100112
- understack_images | length > 0
101113
- item is not skipped
102114
- item.images | length > 0
103-
- item.images[0].status == 'queued'
115+
- item.images[0].status in ['queued', 'uploading']
116+
117+
- name: Look up target Glance images after uploading data
118+
openstack.cloud.image_info:
119+
cloud: "{{ openstack_cloud | default(omit) }}"
120+
filters:
121+
id: "{{ item.uuid }}"
122+
register: target_image_info_2
123+
loop: "{{ understack_images }}"
124+
loop_control:
125+
label: "{{ item.name }}"
126+
when:
127+
- understack_images | length > 0
128+
- item.uuid in _reserved_image_uuids
104129

105130
- name: Tell Glance to import the image data (using use_import and glance-direct)
106131
openstack.cloud.image:
@@ -110,7 +135,7 @@
110135
use_import: true
111136
state: present
112137
wait: true
113-
loop: "{{ target_image_info.results | default([]) }}"
138+
loop: "{{ target_image_info_2.results | default([]) }}"
114139
loop_control:
115140
label: "{{ item.item.name }}"
116141
when:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: v1
3+
kind: PersistentVolumeClaim
4+
metadata:
5+
labels:
6+
undercloud.local/purpose: glance-staging
7+
name: glance-staging
8+
namespace: openstack
9+
spec:
10+
accessModes:
11+
- ReadWriteMany
12+
storageClassName: ceph-fs-ec
13+
resources:
14+
requests:
15+
storage: 20Gi

components/glance/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ kind: Kustomization
55
resources:
66
- glance-mariadb-db.yaml
77
- glance-rabbitmq-queue.yaml
8+
- glance-staging-pvc.yaml

components/glance/values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,35 @@ pod:
7373
- secret:
7474
name: glance-ks-etc
7575
glance_api:
76+
init_container:
77+
volumeMounts:
78+
- name: glance-staging
79+
mountPath: /var/lib/glance/tmp/
80+
volumes:
81+
- name: glance-staging
82+
persistentVolumeClaim:
83+
claimName: glance-staging
7684
glance_api:
7785
volumeMounts:
7886
- name: glance-etc-snippets
7987
mountPath: /etc/glance/glance.conf.d/
8088
readOnly: true
89+
- name: glance-staging
90+
mountPath: /var/lib/glance/tmp/
8191
volumes:
8292
- name: glance-etc-snippets
8393
projected:
8494
sources:
8595
- secret:
8696
name: glance-ks-etc
97+
- name: glance-staging
98+
persistentVolumeClaim:
99+
claimName: glance-staging
100+
security_context:
101+
glance:
102+
pod:
103+
runAsUser: 42424
104+
fsGroup: 42424
87105
lifecycle:
88106
disruption_budget:
89107
api:

0 commit comments

Comments
 (0)