mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: update kubernetes and libraries to v1.22.0 version
Kubernetes v1.22 version has been released and this update ceph csi dependencies to use the same version. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
e077c1fdf5
commit
aa698bc3e1
138
vendor/k8s.io/cloud-provider/volume/helpers/rounding.go
generated
vendored
138
vendor/k8s.io/cloud-provider/volume/helpers/rounding.go
generated
vendored
@ -18,10 +18,22 @@ package helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/bits"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
||||
/*
|
||||
The Cloud Provider's volume plugins provision disks for corresponding
|
||||
PersistentVolumeClaims. Cloud Providers use different allocation unit for their
|
||||
disk sizes. AWS allows you to specify the size as an integer amount of GiB,
|
||||
while Portworx expects bytes for example. On AWS, if you want a volume of
|
||||
1500MiB, the actual call to the AWS API should therefore be for a 2GiB disk.
|
||||
This file contains functions that help rounding a storage request based on a
|
||||
Cloud Provider's allocation unit.
|
||||
*/
|
||||
|
||||
const (
|
||||
// GB - GigaByte size
|
||||
GB = 1000 * 1000 * 1000
|
||||
@ -41,139 +53,113 @@ const (
|
||||
|
||||
// RoundUpToGiB rounds up given quantity upto chunks of GiB
|
||||
func RoundUpToGiB(size resource.Quantity) (int64, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSize(requestBytes, GiB), nil
|
||||
return roundUpSizeInt64(size, GiB)
|
||||
}
|
||||
|
||||
// RoundUpToMB rounds up given quantity to chunks of MB
|
||||
func RoundUpToMB(size resource.Quantity) (int64, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSize(requestBytes, MB), nil
|
||||
return roundUpSizeInt64(size, MB)
|
||||
}
|
||||
|
||||
// RoundUpToMiB rounds up given quantity upto chunks of MiB
|
||||
func RoundUpToMiB(size resource.Quantity) (int64, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSize(requestBytes, MiB), nil
|
||||
return roundUpSizeInt64(size, MiB)
|
||||
}
|
||||
|
||||
// RoundUpToKB rounds up given quantity to chunks of KB
|
||||
func RoundUpToKB(size resource.Quantity) (int64, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSize(requestBytes, KB), nil
|
||||
return roundUpSizeInt64(size, KB)
|
||||
}
|
||||
|
||||
// RoundUpToKiB rounds up given quantity upto chunks of KiB
|
||||
// RoundUpToKiB rounds up given quantity to chunks of KiB
|
||||
func RoundUpToKiB(size resource.Quantity) (int64, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSize(requestBytes, KiB), nil
|
||||
return roundUpSizeInt64(size, KiB)
|
||||
}
|
||||
|
||||
// RoundUpToB rounds up given quantity to chunks of bytes
|
||||
func RoundUpToB(size resource.Quantity) (int64, error) {
|
||||
return roundUpSizeInt64(size, 1)
|
||||
}
|
||||
|
||||
// RoundUpToGiBInt rounds up given quantity upto chunks of GiB. It returns an
|
||||
// int instead of an int64 and an error if there's overflow
|
||||
func RoundUpToGiBInt(size resource.Quantity) (int, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSizeInt(requestBytes, GiB)
|
||||
return roundUpSizeInt(size, GiB)
|
||||
}
|
||||
|
||||
// RoundUpToMBInt rounds up given quantity to chunks of MB. It returns an
|
||||
// int instead of an int64 and an error if there's overflow
|
||||
func RoundUpToMBInt(size resource.Quantity) (int, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSizeInt(requestBytes, MB)
|
||||
return roundUpSizeInt(size, MB)
|
||||
}
|
||||
|
||||
// RoundUpToMiBInt rounds up given quantity upto chunks of MiB. It returns an
|
||||
// int instead of an int64 and an error if there's overflow
|
||||
func RoundUpToMiBInt(size resource.Quantity) (int, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSizeInt(requestBytes, MiB)
|
||||
return roundUpSizeInt(size, MiB)
|
||||
}
|
||||
|
||||
// RoundUpToKBInt rounds up given quantity to chunks of KB. It returns an
|
||||
// int instead of an int64 and an error if there's overflow
|
||||
func RoundUpToKBInt(size resource.Quantity) (int, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSizeInt(requestBytes, KB)
|
||||
return roundUpSizeInt(size, KB)
|
||||
}
|
||||
|
||||
// RoundUpToKiBInt rounds up given quantity upto chunks of KiB. It returns an
|
||||
// int instead of an int64 and an error if there's overflow
|
||||
func RoundUpToKiBInt(size resource.Quantity) (int, error) {
|
||||
requestBytes := size.Value()
|
||||
return roundUpSizeInt(requestBytes, KiB)
|
||||
return roundUpSizeInt(size, KiB)
|
||||
}
|
||||
|
||||
// RoundUpToGiBInt32 rounds up given quantity up to chunks of GiB. It returns an
|
||||
// int32 instead of an int64 and an error if there's overflow
|
||||
func RoundUpToGiBInt32(size resource.Quantity) (int32, error) {
|
||||
requestBytes, ok := size.AsInt64()
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
return roundUpSizeInt32(requestBytes, GiB)
|
||||
return roundUpSizeInt32(size, GiB)
|
||||
}
|
||||
|
||||
// roundUpSizeInt calculates how many allocation units are needed to accommodate
|
||||
// a volume of given size. It returns an int instead of an int64 and an error if
|
||||
// there's overflow
|
||||
func roundUpSizeInt(volumeSizeBytes int64, allocationUnitBytes int64) (int, error) {
|
||||
roundedUp := roundUpSize(volumeSizeBytes, allocationUnitBytes)
|
||||
roundedUpInt := int(roundedUp)
|
||||
if int64(roundedUpInt) != roundedUp {
|
||||
return 0, fmt.Errorf("capacity %v is too great, casting results in integer overflow", roundedUp)
|
||||
// a volume of a given size. It returns an int and an error if there's overflow
|
||||
func roundUpSizeInt(size resource.Quantity, allocationUnitBytes int64) (int, error) {
|
||||
if bits.UintSize == 32 {
|
||||
res, err := roundUpSizeInt32(size, allocationUnitBytes)
|
||||
return int(res), err
|
||||
}
|
||||
return roundedUpInt, nil
|
||||
res, err := roundUpSizeInt64(size, allocationUnitBytes)
|
||||
return int(res), err
|
||||
}
|
||||
|
||||
// roundUpSizeInt32 calculates how many allocation units are needed to accommodate
|
||||
// a volume of given size. It returns an int32 instead of an int64 and an error if
|
||||
// there's overflow
|
||||
func roundUpSizeInt32(volumeSizeBytes int64, allocationUnitBytes int64) (int32, error) {
|
||||
roundedUp := roundUpSize(volumeSizeBytes, allocationUnitBytes)
|
||||
roundedUpInt32 := int32(roundedUp)
|
||||
if int64(roundedUpInt32) != roundedUp {
|
||||
return 0, fmt.Errorf("quantity %v is too great, overflows int32", roundedUp)
|
||||
// a volume of a given size. It returns an int32 and an error if there's overflow
|
||||
func roundUpSizeInt32(size resource.Quantity, allocationUnitBytes int64) (int32, error) {
|
||||
roundedUpInt32, err := roundUpSizeInt64(size, allocationUnitBytes)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return roundedUpInt32, nil
|
||||
if roundedUpInt32 > math.MaxInt32 {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int32", size.String())
|
||||
}
|
||||
return int32(roundedUpInt32), nil
|
||||
}
|
||||
|
||||
// roundUpSize calculates how many allocation units are needed to accommodate
|
||||
// a volume of given size. E.g. when user wants 1500MiB volume, while AWS EBS
|
||||
// allocates volumes in gibibyte-sized chunks,
|
||||
// RoundUpSize(1500 * 1024*1024, 1024*1024*1024) returns '2'
|
||||
// (2 GiB is the smallest allocatable volume that can hold 1500MiB)
|
||||
func roundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
|
||||
// roundUpSizeInt64 calculates how many allocation units are needed to accommodate
|
||||
// a volume of a given size. It returns an int64 and an error if there's overflow
|
||||
func roundUpSizeInt64(size resource.Quantity, allocationUnitBytes int64) (int64, error) {
|
||||
// Use CmpInt64() to find out if the value of "size" would overflow an
|
||||
// int64 and therefore have Value() return a wrong result. Then, retrieve
|
||||
// the value as int64 and perform the rounding.
|
||||
// It's not convenient to use AsScale() and related functions as they don't
|
||||
// support BinarySI format, nor can we use AsInt64() directly since it's
|
||||
// only implemented for int64 scaled numbers (int64Amount).
|
||||
|
||||
// CmpInt64() actually returns 0 when comparing an amount bigger than MaxInt64.
|
||||
if size.CmpInt64(math.MaxInt64) >= 0 {
|
||||
return 0, fmt.Errorf("quantity %s is too great, overflows int64", size.String())
|
||||
}
|
||||
volumeSizeBytes := size.Value()
|
||||
|
||||
roundedUp := volumeSizeBytes / allocationUnitBytes
|
||||
if volumeSizeBytes%allocationUnitBytes > 0 {
|
||||
roundedUp++
|
||||
}
|
||||
return roundedUp
|
||||
return roundedUp, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user