Skip to content

Commit 097bf6d

Browse files
Maxim Savamaximsava12
authored andcommitted
[multiple] Discover and configure Glance with Ceph RGW secrets
This patch enhances the cifmw_ceph_client/cifmw_cephadm roles to: - Automatically discover Ceph RGW (RADOS Gateway) endpoint and credentials - Create Glance secrets using the discovered RGW settings - Configure glance with Ceph RGW secrets - Creating a dedicated 'glance' S3 user in RGW (cifmw_cephadm role) This integration configures Glance with Ceph RGW access credentials, enabling it to use RGW as an Glance backend when object storage is enabled Changes: - Add RGW discovery playbook - Add logic to create Glance secrets with RGW config Signed-off-by: Maxim Sava <msava@redhat.com>
1 parent 052ccea commit 097bf6d

File tree

8 files changed

+217
-0
lines changed

8 files changed

+217
-0
lines changed

hooks/playbooks/ceph.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@
473473
name: cifmw_cephadm
474474
tasks_from: rbd_mirror
475475

476+
- name: Create RGW S3 user and fetch S3 user info
477+
when: cifmw_cephadm_rgw_s3_glance
478+
ansible.builtin.import_role:
479+
name: cifmw_cephadm
480+
tasks_from: glance_s3_info
481+
476482
- name: Create Cephx Keys for OpenStack
477483
ansible.builtin.import_role:
478484
name: cifmw_cephadm
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
# Copyright Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
- name: Set fact for glance S3 backend secrets
18+
ansible.builtin.set_fact:
19+
ceph_s3_access_key: "{{ cifmw_ceph_client_s3_glance_user['keys'][0]['access_key'] }}"
20+
ceph_s3_secret_key: "{{ cifmw_ceph_client_s3_glance_user['keys'][0]['secret_key'] }}"
21+
ceph_s3_bucket: "glance-s3-bucket"
22+
ceph_s3_endpoint: "{{ cifmw_ceph_client_s3_internal_swift_url }}"
23+
when:
24+
- cifmw_ceph_client_s3_glance_user is defined
25+
- cifmw_ceph_client_s3_internal_swift_url is defined
26+
no_log: true
27+
28+
- name: Generate Glance S3 backend secrets using Ceph RGW credentials
29+
ansible.builtin.template:
30+
src: templates/k8s_ceph_rgw_glance_secret.j2
31+
dest: k8s_ceph_rgw_glance_secret.yaml
32+
mode: "0600"
33+
force: true
34+
when:
35+
- ceph_s3_access_key is defined
36+
- ceph_s3_secret_key is defined
37+
no_log: true
38+
register: reg_k8s_ceph_rgw_glance_secret
39+
40+
- name: Create glance S3 backend secrets
41+
kubernetes.core.k8s:
42+
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
43+
api_key: "{{ cifmw_openshift_token | default(omit)}}"
44+
context: "{{ cifmw_openshift_context | default(omit) }}"
45+
namespace: openstack
46+
state: present
47+
apply: true
48+
force: true
49+
src: k8s_ceph_rgw_glance_secret.yaml
50+
register: k8s_glance_s3_secret
51+
delegate_to: localhost
52+
no_log: true
53+
when: reg_k8s_ceph_rgw_glance_secret is not skipped
54+
55+
- name: Delete the rendered secret file
56+
ansible.builtin.file:
57+
path: k8s_ceph_rgw_glance_secret.yaml
58+
state: absent
59+
delegate_to: localhost
60+
when: k8s_glance_s3_secret | default(true)

roles/cifmw_ceph_client/tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
mode: "0600"
7979
force: true
8080

81+
- name: Import glance Ceph RGW discovery playbook
82+
when: cifmw_ceph_client_s3_glance_user
83+
ansible.builtin.include_tasks: glance-rgw-discovery.yaml
84+
8185
- name: Create edpm-values-post-ceph ConfigMap if sample path provided
8286
ansible.builtin.include_tasks: edpm_values_post_ceph.yml
8387
when:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Glance secrets used to configure glance with ceph S3 backend
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: s3glance
6+
stringData:
7+
s3glance.conf: |
8+
[default_backend]
9+
s3_store_host = {{ ceph_s3_endpoint }}
10+
s3_store_access_key = {{ ceph_s3_access_key }}
11+
s3_store_secret_key = {{ ceph_s3_secret_key }}
12+
s3_store_bucket = {{ ceph_s3_bucket }}
13+
s3_store_cacert = "/etc/pki/tls/certs/ca-bundle.crt"

roles/cifmw_cephadm/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ that they do not need to be changed for a typical EDPM deployment.
108108
Squid). Set it to false if the target Ceph release is equal to or greater
109109
than Tentacle.
110110

111+
* `cifmw_cephadm_rgw_s3_glance`: (Bool) If this is value is `true`, then
112+
cephadm will create glance secrets using the discovered RGW settings
113+
111114
Use the `cifmw_cephadm_pools` list of dictionaries to define pools for
112115
Nova (vms), Cinder (volumes), Cinder-backups (backups), and Glance (images).
113116
```

roles/cifmw_cephadm/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,4 @@ cifmw_cephadm_rgw_ingress_service_id: "rgw.default"
156156
# set ssl_backward compatibily to False if ceph version is equal or greater
157157
# than Tentacle
158158
cifmw_rgw_ssl_backward_compatibility: true
159+
cifmw_cephadm_rgw_s3_glance: false
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
# Copyright 2025 Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
- name: Create glance S3 RGW user and fetch object-store endpoint
18+
when: cifmw_edpm_deploy_hci | default('false') | bool
19+
block:
20+
- name: Refresh ceph_cli
21+
ansible.builtin.include_tasks: ceph_cli.yml
22+
vars:
23+
ceph_command: "radosgw-admin"
24+
25+
- name: Wait for RGW daemons to be running
26+
ansible.builtin.command:
27+
cmd: "{{ cifmw_cephadm_ceph_cli }} orch ps --daemon-type rgw --format json"
28+
register: rgw_daemon_status
29+
become: true
30+
changed_when: false
31+
failed_when: false
32+
until: >
33+
rgw_daemon_status.rc == 0 and
34+
(rgw_daemon_status.stdout | default('[]') | from_json | default([], true)) |
35+
selectattr('status_desc', 'equalto', 'running') |
36+
list | length > 0
37+
retries: 30
38+
delay: 10
39+
40+
- name: Check if Ceph S3 glance user exists
41+
ansible.builtin.command:
42+
cmd: >-
43+
{{ cifmw_cephadm_ceph_cli }} user info --uid glance
44+
no_log: true
45+
become: true
46+
ignore_errors: true
47+
changed_when: false
48+
register: cifmw_ceph_s3_glance_user_check
49+
when: cifmw_cephadm_ceph_cli is defined
50+
51+
- name: Create Ceph S3 glance user
52+
ansible.builtin.command:
53+
cmd: >-
54+
{{ cifmw_cephadm_ceph_cli }} user create
55+
--uid="glance"
56+
--display-name="Glance S3 User"
57+
become: true
58+
when:
59+
- cifmw_ceph_s3_glance_user_check is not skipped
60+
- cifmw_ceph_s3_glance_user_check.rc != 0
61+
register: glance_rgw_user_create
62+
retries: 3
63+
delay: 5
64+
until: glance_rgw_user_create.rc == 0
65+
66+
- name: Get RGW glance user info
67+
ansible.builtin.command:
68+
cmd: >-
69+
{{ cifmw_cephadm_ceph_cli }} user info --uid="glance"
70+
become: true
71+
no_log: true
72+
changed_when: false
73+
register: ceph_rgw_glance_user_info
74+
75+
- name: Show RGW daemon status on failure
76+
when: ceph_rgw_glance_user_info.rc != 0
77+
block:
78+
- name: Get RGW daemon status for debugging
79+
ansible.builtin.command:
80+
cmd: "{{ cifmw_cephadm_ceph_cli }} orch ps --daemon-type rgw"
81+
become: true
82+
register: rgw_debug_status
83+
changed_when: false
84+
85+
- name: Display RGW status
86+
ansible.builtin.debug:
87+
msg: "RGW daemon status: {{ rgw_debug_status.stdout }}"
88+
89+
- name: Fail with context
90+
ansible.builtin.fail:
91+
msg: |
92+
Failed to fetch glance user info after creation.
93+
User creation result: {{ glance_rgw_user_create | default('not attempted') }}
94+
RGW daemon status shown above.
95+
96+
- name: Set facts RGW glance user
97+
ansible.builtin.set_fact:
98+
cifmw_ceph_s3_glance_user: "{{ ceph_rgw_glance_user_info.stdout | from_json }}"
99+
when:
100+
- ceph_rgw_glance_user_info is defined
101+
- ceph_rgw_glance_user_info.rc == 0
102+
no_log: true
103+
104+
- name: Get OpenStack internal object-store endpoints
105+
cifmw.general.ci_script:
106+
extra_args:
107+
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
108+
output_dir: "{{ cifmw_cephadm_basedir }}/artifacts"
109+
script: |-
110+
oc -n {{ cifmw_cephadm_ns }} rsh openstackclient openstack endpoint list --service object-store --interface internal -f value -c URL
111+
delegate_to: localhost
112+
register: object_store_endpoint_raw
113+
when:
114+
- cifmw_openshift_kubeconfig is defined
115+
- cifmw_cephadm_basedir is defined
116+
- cifmw_cephadm_rgw_s3_glance
117+
118+
- name: Extract base URL without path
119+
ansible.builtin.set_fact:
120+
rgw_internal_url: >-
121+
{{
122+
object_store_endpoint_raw.stdout
123+
| regex_replace('(/swift.*)$', '')
124+
}}

roles/cifmw_cephadm/templates/ceph_client.yaml.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
---
2+
{% if cifmw_cephadm_rgw_s3_glance is defined %}
3+
cifmw_ceph_client_s3_glance_user: {{ cifmw_cephadm_rgw_s3_glance }}
4+
{% endif %}
5+
{% if rgw_internal_url is defined %}
6+
cifmw_ceph_client_s3_internal_swift_url: {{ rgw_internal_url }}
7+
{% endif %}
28
cifmw_ceph_client_fsid: {{ cifmw_cephadm_fsid }}
39
cifmw_ceph_client_cluster: {{ cifmw_cephadm_cluster }}
410
cifmw_ceph_client_external_cluster_mon_ips: "{{ cifmw_ceph_client_external_cluster_mon_ips }}"

0 commit comments

Comments
 (0)