From 577dcd5d199510dd8bff894e52ec724a684e7b66 Mon Sep 17 00:00:00 2001 From: "Sphicas, Phil (ps3910)" Date: Fri, 5 Jun 2020 07:29:36 +0000 Subject: [PATCH] ceph-osd: Simplify failure domain config using map Using a subset of the characters in the hostname to determine the failure domain is not always possible, and using overrides based on hostnames is in some ways overkill. This change provides a simple way to map hostnames to failure domains. It is used only when 'failure_domain' is set other than 'host', and when 'failure_domain_by_hostname' is 'false'. Any hosts not referenced in the map will be given the default treatment (root=default host=hostname) Example usage: conf: storage: failure_domain: rack failure_domain_by_hostname_map: hostfoo: rack1 hostbar: rack1 hostbaz: rack2 hostqux: rack2 Change-Id: Ia98fec8c623486f80054877e40e0753e4b939e8e --- ceph-osd/templates/bin/osd/ceph-disk/_common.sh.tpl | 3 +++ ceph-osd/templates/bin/osd/ceph-volume/_common.sh.tpl | 3 +++ ceph-osd/values.yaml | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/ceph-osd/templates/bin/osd/ceph-disk/_common.sh.tpl b/ceph-osd/templates/bin/osd/ceph-disk/_common.sh.tpl index 6aa44d5a5..d06a23322 100644 --- a/ceph-osd/templates/bin/osd/ceph-disk/_common.sh.tpl +++ b/ceph-osd/templates/bin/osd/ceph-disk/_common.sh.tpl @@ -27,6 +27,7 @@ set -ex eval CRUSH_FAILURE_DOMAIN_TYPE=$(cat /etc/ceph/storage.json | python -c 'import sys, json; data = json.load(sys.stdin); print(json.dumps(data["failure_domain"]))') eval CRUSH_FAILURE_DOMAIN_NAME=$(cat /etc/ceph/storage.json | python -c 'import sys, json; data = json.load(sys.stdin); print(json.dumps(data["failure_domain_name"]))') eval CRUSH_FAILURE_DOMAIN_BY_HOSTNAME=$(cat /etc/ceph/storage.json | python -c 'import sys, json; data = json.load(sys.stdin); print(json.dumps(data["failure_domain_by_hostname"]))') +eval CRUSH_FAILURE_DOMAIN_FROM_HOSTNAME_MAP=$(cat /etc/ceph/storage.json | jq '.failure_domain_by_hostname_map."'$HOSTNAME'"') eval DEVICE_CLASS=$(cat /etc/ceph/storage.json | python -c 'import sys, json; data = json.load(sys.stdin); print(json.dumps(data["device_class"]))') if [[ $(ceph -v | egrep -q "nautilus|mimic|luminous"; echo $?) -ne 0 ]]; then @@ -102,6 +103,8 @@ function crush_location { crush_add_and_move "${CRUSH_FAILURE_DOMAIN_TYPE}" "${CRUSH_FAILURE_DOMAIN_NAME}" elif [ "x${CRUSH_FAILURE_DOMAIN_BY_HOSTNAME}" != "xfalse" ]; then crush_add_and_move "${CRUSH_FAILURE_DOMAIN_TYPE}" "$(echo ${CRUSH_FAILURE_DOMAIN_TYPE}_$(echo ${HOSTNAME} | cut -c ${CRUSH_FAILURE_DOMAIN_BY_HOSTNAME}))" + elif [ "x${CRUSH_FAILURE_DOMAIN_FROM_HOSTNAME_MAP}" != "xnull" ]; then + crush_add_and_move "${CRUSH_FAILURE_DOMAIN_TYPE}" "${CRUSH_FAILURE_DOMAIN_FROM_HOSTNAME_MAP}" else # NOTE(supamatt): neither variables are defined then we fall back to default behavior crush_create_or_move "${CRUSH_LOCATION}" diff --git a/ceph-osd/templates/bin/osd/ceph-volume/_common.sh.tpl b/ceph-osd/templates/bin/osd/ceph-volume/_common.sh.tpl index a1f61c50e..967f4e9d6 100644 --- a/ceph-osd/templates/bin/osd/ceph-volume/_common.sh.tpl +++ b/ceph-osd/templates/bin/osd/ceph-volume/_common.sh.tpl @@ -27,6 +27,7 @@ set -ex eval CRUSH_FAILURE_DOMAIN_TYPE=$(cat /etc/ceph/storage.json | python -c 'import sys, json; data = json.load(sys.stdin); print(json.dumps(data["failure_domain"]))') eval CRUSH_FAILURE_DOMAIN_NAME=$(cat /etc/ceph/storage.json | python -c 'import sys, json; data = json.load(sys.stdin); print(json.dumps(data["failure_domain_name"]))') eval CRUSH_FAILURE_DOMAIN_BY_HOSTNAME=$(cat /etc/ceph/storage.json | python -c 'import sys, json; data = json.load(sys.stdin); print(json.dumps(data["failure_domain_by_hostname"]))') +eval CRUSH_FAILURE_DOMAIN_FROM_HOSTNAME_MAP=$(cat /etc/ceph/storage.json | jq '.failure_domain_by_hostname_map."'$HOSTNAME'"') eval DEVICE_CLASS=$(cat /etc/ceph/storage.json | python -c 'import sys, json; data = json.load(sys.stdin); print(json.dumps(data["device_class"]))') if [[ $(ceph -v | egrep -q "nautilus|mimic|luminous"; echo $?) -ne 0 ]]; then @@ -102,6 +103,8 @@ function crush_location { crush_add_and_move "${CRUSH_FAILURE_DOMAIN_TYPE}" "${CRUSH_FAILURE_DOMAIN_NAME}" elif [ "x${CRUSH_FAILURE_DOMAIN_BY_HOSTNAME}" != "xfalse" ]; then crush_add_and_move "${CRUSH_FAILURE_DOMAIN_TYPE}" "$(echo ${CRUSH_FAILURE_DOMAIN_TYPE}_$(echo ${HOSTNAME} | cut -c ${CRUSH_FAILURE_DOMAIN_BY_HOSTNAME}))" + elif [ "x${CRUSH_FAILURE_DOMAIN_FROM_HOSTNAME_MAP}" != "xnull" ]; then + crush_add_and_move "${CRUSH_FAILURE_DOMAIN_TYPE}" "${CRUSH_FAILURE_DOMAIN_FROM_HOSTNAME_MAP}" else # NOTE(supamatt): neither variables are defined then we fall back to default behavior crush_create_or_move "${CRUSH_LOCATION}" diff --git a/ceph-osd/values.yaml b/ceph-osd/values.yaml index 5f4f3b6a2..38307dd46 100644 --- a/ceph-osd/values.yaml +++ b/ceph-osd/values.yaml @@ -203,10 +203,18 @@ conf: # `failure_domain`: Set the CRUSH bucket type for your OSD to reside in. See the supported CRUSH configuration # as listed here: Supported CRUSH configuration is listed here: http://docs.ceph.com/docs/nautilus/rados/operations/crush-map/ # `failure_domain_by_hostname`: Specify the portion of the hostname to use for your failure domain bucket name. + # `failure_domain_by_hostname_map`: Explicit mapping of hostname to failure domain, as a simpler alternative to overrides. # `failure_domain_name`: Manually name the failure domain bucket name. This configuration option should only be used # when using host based overrides. failure_domain: "host" failure_domain_by_hostname: "false" + failure_domain_by_hostname_map: {} + # Example: + # failure_domain_map_hostname_map: + # hostfoo: rack1 + # hostbar: rack1 + # hostbaz: rack2 + # hostqux: rack2 failure_domain_name: "false" # Note: You can override the device class by adding the value (e.g., hdd, ssd or nvme).