From 82638f8b29232ac654f328aaead97d78824c85ca Mon Sep 17 00:00:00 2001 From: Muhammed Uluyol Date: Wed, 19 Aug 2015 17:19:37 -0700 Subject: [PATCH] Add conversion function from GCE storage units to kubernetes units. --- cluster/gce/configure-vm.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cluster/gce/configure-vm.sh b/cluster/gce/configure-vm.sh index bfed226d4c..6e41453649 100644 --- a/cluster/gce/configure-vm.sh +++ b/cluster/gce/configure-vm.sh @@ -308,12 +308,26 @@ EOF if [[ "${ENABLE_CLUSTER_REGISTRY}" == true && -n "${CLUSTER_REGISTRY_DISK}" ]]; then cat <>/srv/salt-overlay/pillar/cluster-params.sls cluster_registry_disk_type: gce -cluster_registry_disk_size: ${CLUSTER_REGISTRY_DISK_SIZE//GB/Gi} +cluster_registry_disk_size: $(convert-bytes-gce-kube ${CLUSTER_REGISTRY_DISK_SIZE}) cluster_registry_disk_name: ${CLUSTER_REGISTRY_DISK} EOF fi } +# The job of this function is simple, but the basic regular expression syntax makes +# this difficult to read. What we want to do is convert from [0-9]+B, KB, KiB, MB, etc +# into [0-9]+, Ki, Mi, Gi, etc. +# This is done in two steps: +# 1. Convert from [0-9]+X?i?B into [0-9]X? (X denotes the prefix, ? means the field +# is optional. +# 2. Attach an 'i' to the end of the string if we find a letter. +# The two step process is needed to handle the edge case in which we want to convert +# a raw byte count, as the result should be a simple number (e.g. 5B -> 5). +function convert-bytes-gce-kube() { + local -r storage_space=$1 + echo "${storage_space}" | sed -e 's/^\([0-9]\+\)\([A-Z]\)\?i\?B$/\1\2/g' -e 's/\([A-Z]\)$/\1i/' +} + # This should only happen on cluster initialization. # # - Uses KUBE_PASSWORD and KUBE_USER to generate basic_auth.csv.