[rook-ceph] Fix VolumeSnapshotClass creation

[1] added a VolumeSnapshot creation to stx-openstack app to support the
mariadb update process. However, based on [2] the VolumeSnapshotClass
driver and parameters used for rook ceph deployments are different from
the ones used for host ceph. Because of this, the VolumeSnaphost
creation is not behaving as expected for rook ceph deployments, making
the app to stuck in the "system application-remove" operation.

This change dynamically configures the VolumeSnapshotClass based on the
storage backend type (host ceph vs rook ceph).

[1]https://review.opendev.org/c/starlingx/openstack-armada-app/+/945094
[2]https://docs.starlingx.io/kube-virt/vm-snapshot-and-restore-21158b60cd56.html

Test Plan:
[PASS] build stx-openstack packages and tarball

Rook ceph storage backend:
[PASS] apply stx-openstack tarball to a standard system
[PASS] check volumesnapshotclass and volumesnapshot k8s resources
[PASS] remove the application

Host ceph storage backend:
[PASS] apply stx-openstack tarball to a vbox AIO-SX system
[PASS] check volumesnapshotclass and volumesnapshot k8s resources
[PASS] remove the application

Closes-Bug: #2110310

Change-Id: Ie2b41557caf25072e42c19010db85663b8c50ffc
Signed-off-by: Johnny Chia <johnny.chialun@windriver.com>
Co-authored-by: Alex Figueiredo <alex.fernandesfigueiredo@windriver.com>
This commit is contained in:
jchialun
2025-05-08 10:29:30 -05:00
committed by Alex Figueiredo
parent 80414c49b1
commit 384e05cd62
2 changed files with 26 additions and 8 deletions

View File

@@ -106,6 +106,12 @@ CEPH_ROOK_IMAGE_OVERRIDE = 'rook_ceph_config_helper'
CEPH_ROOK_MANAGER_APP = 'rook-ceph-mgr'
CEPH_ROOK_MANAGER_SVC = 'rook-ceph-mgr-restful'
CEPH_ROOK_POLL_CRUSH_RULE = 'kube-rbd'
CEPH_ROOK_RBD_SECRET_NAME = 'rook-csi-rbd-provisioner'
CEPH_ROOK_RBD_DRIVER = 'rook-ceph.rbd.csi.ceph.com'
CEPH_RBD_SECRET_NAME = 'ceph-pool-kube-rbd'
CEPH_RBD_DRIVER = 'rbd.csi.ceph.com'
CEPH_RBD_SNAPSHOT_PREFIX = 'rbd-snap-'
CEPH_RBD_POOL_USER_CINDER = "cinder"
CEPH_RBD_POOL_USER_GLANCE = 'images'

View File

@@ -862,7 +862,8 @@ def check_and_create_snapshot_class(snapshot_class: str, path: str):
cmd = [
"kubectl", "--kubeconfig", kubernetes.KUBERNETES_ADMIN_CONF,
"-n", app_constants.HELM_NS_OPENSTACK,
"get", "volumesnapshotclasses.snapshot.storage.k8s.io", snapshot_class
"get", "volumesnapshotclasses.snapshot.storage.k8s.io",
snapshot_class
]
send_cmd_read_response(cmd)
@@ -870,19 +871,29 @@ def check_and_create_snapshot_class(snapshot_class: str, path: str):
# Create class
LOG.info(f"Trying to create snapshot class {snapshot_class}")
try:
if is_rook_ceph_backend_available():
secret_name = app_constants.CEPH_ROOK_RBD_SECRET_NAME
secret_ns = app_constants.HELM_NS_ROOK_CEPH
driver = app_constants.CEPH_ROOK_RBD_DRIVER
cluster_id = app_constants.HELM_APP_ROOK_CEPH
else:
secret_name = app_constants.CEPH_RBD_SECRET_NAME
secret_ns = helm_common.HELM_NS_RBD_PROVISIONER
driver = app_constants.CEPH_RBD_DRIVER
cluster_id = get_ceph_uuid()
snapclass_dict = {
"apiVersion": "snapshot.storage.k8s.io/v1",
"apiVersion": 'snapshot.storage.k8s.io/v1',
"kind": "VolumeSnapshotClass",
"deletionPolicy": "Delete",
"driver": "rbd.csi.ceph.com",
"driver": driver,
"metadata": {
"name": snapshot_class,
},
"parameters": {
"clusterID": get_ceph_uuid(),
"csi.storage.k8s.io/snapshotter-secret-name": "ceph-pool-kube-rbd",
"csi.storage.k8s.io/snapshotter-secret-namespace": "kube-system",
"snapshotNamePrefix": "rbd-snap-",
"clusterID": cluster_id,
"csi.storage.k8s.io/snapshotter-secret-name": secret_name,
"csi.storage.k8s.io/snapshotter-secret-namespace": secret_ns,
"snapshotNamePrefix": app_constants.CEPH_RBD_SNAPSHOT_PREFIX,
},
}
@@ -902,7 +913,8 @@ def check_and_create_snapshot_class(snapshot_class: str, path: str):
LOG.info(f"Created new snapshot class '{snapshot_class}'")
except Exception as e:
LOG.error(f"Unexpected error while checking/creating snapshot class {snapshot_class}: {e}")
LOG.error("Unexpected error while checking/creating snapshot"
f"class {snapshot_class}: {e}")
def create_pvc_snapshot(snapshot_name: str, pvc_name: str, snapshot_class: str, path: str = "/tmp"):