From e8219bc6d86604747652492400a2a3a08968dd10 Mon Sep 17 00:00:00 2001
From: Pete Birley <pete@port.direct>
Date: Fri, 9 Mar 2018 01:32:22 +0000
Subject: [PATCH] Cinder: allow Ceph RBD pool params to be tuned

This PS exposes the Ceph RBD pool params to the cinder chart, allowing
them to be tuned.

Change-Id: I615e999928948193b24cc4978efb31bd1b36f8f7
Closes-Bug: #1754535
---
 cinder/templates/bin/_backup-storage-init.sh.tpl |  2 ++
 cinder/templates/bin/_storage-init.sh.tpl        |  2 ++
 cinder/templates/job-backup-storage-init.yaml    |  6 +++++-
 cinder/templates/job-storage-init.yaml           |  6 +++++-
 cinder/values.yaml                               |  9 +++++++++
 tools/deployment/developer/ceph/130-cinder.sh    | 14 ++++++++++++++
 6 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/cinder/templates/bin/_backup-storage-init.sh.tpl b/cinder/templates/bin/_backup-storage-init.sh.tpl
index 3d8214b542..2c619d060f 100644
--- a/cinder/templates/bin/_backup-storage-init.sh.tpl
+++ b/cinder/templates/bin/_backup-storage-init.sh.tpl
@@ -38,6 +38,8 @@ elif [ "x$STORAGE_BACKEND" == "xcinder.backup.drivers.ceph" ]; then
     if [[ ${test_luminous} -gt 0 ]]; then
       ceph osd pool application enable $1 $3
     fi
+    ceph osd pool set $1 size ${RBD_POOL_REPLICATION}
+    ceph osd pool set $1 crush_rule "${RBD_POOL_CRUSH_RULE}"
   }
   ensure_pool ${RBD_POOL_NAME} ${RBD_POOL_CHUNK_SIZE} "cinder-backup"
 
diff --git a/cinder/templates/bin/_storage-init.sh.tpl b/cinder/templates/bin/_storage-init.sh.tpl
index 76a4de46bb..ed3ec0a8d1 100644
--- a/cinder/templates/bin/_storage-init.sh.tpl
+++ b/cinder/templates/bin/_storage-init.sh.tpl
@@ -35,6 +35,8 @@ if [ "x$STORAGE_BACKEND" == "xcinder.volume.drivers.rbd.RBDDriver" ]; then
     if [[ ${test_luminous} -gt 0 ]]; then
       ceph osd pool application enable $1 $3
     fi
+    ceph osd pool set $1 size ${RBD_POOL_REPLICATION}
+    ceph osd pool set $1 crush_rule "${RBD_POOL_CRUSH_RULE}"
   }
   ensure_pool ${RBD_POOL_NAME} ${RBD_POOL_CHUNK_SIZE} "cinder-volume"
 
diff --git a/cinder/templates/job-backup-storage-init.yaml b/cinder/templates/job-backup-storage-init.yaml
index d6d23e334e..9f23112050 100644
--- a/cinder/templates/job-backup-storage-init.yaml
+++ b/cinder/templates/job-backup-storage-init.yaml
@@ -102,8 +102,12 @@ spec:
               value: {{ .Values.conf.cinder.DEFAULT.backup_ceph_pool | quote }}
             - name: RBD_POOL_USER
               value: {{ .Values.conf.cinder.DEFAULT.backup_ceph_user | quote }}
+            - name: RBD_POOL_CRUSH_RULE
+              value: {{ .Values.conf.ceph.pools.backup.crush_rule | quote }}
+            - name: RBD_POOL_REPLICATION
+              value: {{ .Values.conf.ceph.pools.backup.replication | quote }}
             - name: RBD_POOL_CHUNK_SIZE
-              value: "8"
+              value: {{ .Values.conf.ceph.pools.backup.chunk_size | quote }}
             - name: RBD_POOL_SECRET
               value: {{ .Values.secrets.rbd.backup | quote }}
             {{ end }}
diff --git a/cinder/templates/job-storage-init.yaml b/cinder/templates/job-storage-init.yaml
index 80b2b95bd7..dbc0f56eca 100644
--- a/cinder/templates/job-storage-init.yaml
+++ b/cinder/templates/job-storage-init.yaml
@@ -102,8 +102,12 @@ spec:
               value: {{ index (index .Values.conf.backends (include "cinder.ceph_volume_section_name" $envAll)) "rbd_pool" | quote }}
             - name: RBD_POOL_USER
               value: {{ index (index .Values.conf.backends (include "cinder.ceph_volume_section_name" $envAll)) "rbd_user" | quote }}
+            - name: RBD_POOL_CRUSH_RULE
+              value: {{ .Values.conf.ceph.pools.volume.crush_rule | quote }}
+            - name: RBD_POOL_REPLICATION
+              value: {{ .Values.conf.ceph.pools.volume.replication | quote }}
             - name: RBD_POOL_CHUNK_SIZE
-              value: "8"
+              value: {{ .Values.conf.ceph.pools.volume.chunk_size | quote }}
             - name: RBD_POOL_SECRET
               value: {{ .Values.secrets.rbd.volume | quote }}
             {{- end }}
diff --git a/cinder/values.yaml b/cinder/values.yaml
index 65b613bf3b..813ca9cec7 100644
--- a/cinder/values.yaml
+++ b/cinder/values.yaml
@@ -437,6 +437,15 @@ conf:
     append:
     monitors: []
     admin_keyring: null
+    pools:
+      backup:
+        replication: 3
+        crush_rule: replicated_rule
+        chunk_size: 8
+      volume:
+        replication: 3
+        crush_rule: replicated_rule
+        chunk_size: 8
   cinder:
     DEFAULT:
       use_syslog: false
diff --git a/tools/deployment/developer/ceph/130-cinder.sh b/tools/deployment/developer/ceph/130-cinder.sh
index 8d3053f57a..1dd7aef240 100755
--- a/tools/deployment/developer/ceph/130-cinder.sh
+++ b/tools/deployment/developer/ceph/130-cinder.sh
@@ -20,8 +20,22 @@ make pull-images cinder
 
 #NOTE: Deploy command
 : ${OSH_EXTRA_HELM_ARGS:=""}
+tee /tmp/cinder.yaml <<EOF
+conf:
+  ceph:
+    pools:
+      backup:
+        replication: 1
+        crush_rule: same_host
+        chunk_size: 8
+      volume:
+        replication: 1
+        crush_rule: same_host
+        chunk_size: 8
+EOF
 helm upgrade --install cinder ./cinder \
   --namespace=openstack \
+  --values=/tmp/cinder.yaml \
   ${OSH_EXTRA_HELM_ARGS} \
   ${OSH_EXTRA_HELM_ARGS_CINDER}