mirror of https://github.com/k3s-io/k3s
Add conversion function from GCE storage units to kubernetes units.
parent
14b554cef6
commit
82638f8b29
|
@ -308,12 +308,26 @@ EOF
|
|||
if [[ "${ENABLE_CLUSTER_REGISTRY}" == true && -n "${CLUSTER_REGISTRY_DISK}" ]]; then
|
||||
cat <<EOF >>/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.
|
||||
|
|
Loading…
Reference in New Issue