Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
093e2312
Commit
093e2312
authored
Jul 20, 2018
by
Matthew Wong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid overflowing int64 in RoundUpSize and return error if overflow int
parent
d08e68e7
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
94 additions
and
36 deletions
+94
-36
aws.go
pkg/cloudprovider/providers/aws/aws.go
+1
-2
gce_disks.go
pkg/cloudprovider/providers/gce/gce_disks.go
+1
-2
openstack_volumes.go
pkg/cloudprovider/providers/openstack/openstack_volumes.go
+7
-5
aws_util.go
pkg/volume/aws_ebs/aws_util.go
+6
-4
azure_provision.go
pkg/volume/azure_dd/azure_provision.go
+8
-6
cinder_util.go
pkg/volume/cinder/cinder_util.go
+7
-4
flocker_util.go
pkg/volume/flocker/flocker_util.go
+5
-2
glusterfs.go
pkg/volume/glusterfs/glusterfs.go
+4
-1
photon_util.go
pkg/volume/photon_pd/photon_util.go
+5
-3
quobyte_util.go
pkg/volume/quobyte/quobyte_util.go
+4
-1
rbd_util.go
pkg/volume/rbd/rbd_util.go
+4
-1
storageos.go
pkg/volume/storageos/storageos.go
+5
-1
util.go
pkg/volume/util/util.go
+31
-1
vsphere_volume_util.go
pkg/volume/vsphere_volume/vsphere_volume_util.go
+6
-3
No files found.
pkg/cloudprovider/providers/aws/aws.go
View file @
093e2312
...
@@ -2510,9 +2510,8 @@ func (c *Cloud) ResizeDisk(
...
@@ -2510,9 +2510,8 @@ func (c *Cloud) ResizeDisk(
descErr
:=
fmt
.
Errorf
(
"AWS.ResizeDisk Error describing volume %s with %v"
,
diskName
,
err
)
descErr
:=
fmt
.
Errorf
(
"AWS.ResizeDisk Error describing volume %s with %v"
,
diskName
,
err
)
return
oldSize
,
descErr
return
oldSize
,
descErr
}
}
requestBytes
:=
newSize
.
Value
()
// AWS resizes in chunks of GiB (not GB)
// AWS resizes in chunks of GiB (not GB)
requestGiB
:=
volumeutil
.
RoundUp
Size
(
requestBytes
,
1024
*
1024
*
1024
)
requestGiB
:=
volumeutil
.
RoundUp
ToGiB
(
newSize
)
newSizeQuant
:=
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
requestGiB
))
newSizeQuant
:=
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
requestGiB
))
// If disk already if of greater or equal size than requested we return
// If disk already if of greater or equal size than requested we return
...
...
pkg/cloudprovider/providers/gce/gce_disks.go
View file @
093e2312
...
@@ -746,9 +746,8 @@ func (gce *GCECloud) ResizeDisk(diskToResize string, oldSize resource.Quantity,
...
@@ -746,9 +746,8 @@ func (gce *GCECloud) ResizeDisk(diskToResize string, oldSize resource.Quantity,
return
oldSize
,
err
return
oldSize
,
err
}
}
requestBytes
:=
newSize
.
Value
()
// GCE resizes in chunks of GiBs
// GCE resizes in chunks of GiBs
requestGIB
:=
volumeutil
.
RoundUp
Size
(
requestBytes
,
volumeutil
.
GIB
)
requestGIB
:=
volumeutil
.
RoundUp
ToGiB
(
newSize
)
newSizeQuant
:=
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
requestGIB
))
newSizeQuant
:=
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
requestGIB
))
// If disk is already of size equal or greater than requested size, we simply return
// If disk is already of size equal or greater than requested size, we simply return
...
...
pkg/cloudprovider/providers/openstack/openstack_volumes.go
View file @
093e2312
...
@@ -411,13 +411,15 @@ func (os *OpenStack) ExpandVolume(volumeID string, oldSize resource.Quantity, ne
...
@@ -411,13 +411,15 @@ func (os *OpenStack) ExpandVolume(volumeID string, oldSize resource.Quantity, ne
return
oldSize
,
fmt
.
Errorf
(
"volume status is not available"
)
return
oldSize
,
fmt
.
Errorf
(
"volume status is not available"
)
}
}
volSizeBytes
:=
newSize
.
Value
()
// Cinder works with gigabytes, convert to GiB with rounding up
// Cinder works with gigabytes, convert to GiB with rounding up
volSizeGB
:=
int
(
volumeutil
.
RoundUpSize
(
volSizeBytes
,
1024
*
1024
*
1024
))
volSizeGiB
,
err
:=
volumeutil
.
RoundUpToGiBInt
(
newSize
)
newSizeQuant
:=
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
volSizeGB
))
if
err
!=
nil
{
return
oldSize
,
err
}
newSizeQuant
:=
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
volSizeGiB
))
// if volume size equals to or greater than the newSize, return nil
// if volume size equals to or greater than the newSize, return nil
if
volume
.
Size
>=
volSizeGB
{
if
volume
.
Size
>=
volSizeG
i
B
{
return
newSizeQuant
,
nil
return
newSizeQuant
,
nil
}
}
...
@@ -426,7 +428,7 @@ func (os *OpenStack) ExpandVolume(volumeID string, oldSize resource.Quantity, ne
...
@@ -426,7 +428,7 @@ func (os *OpenStack) ExpandVolume(volumeID string, oldSize resource.Quantity, ne
return
oldSize
,
err
return
oldSize
,
err
}
}
err
=
volumes
.
expandVolume
(
volumeID
,
volSizeGB
)
err
=
volumes
.
expandVolume
(
volumeID
,
volSizeG
i
B
)
if
err
!=
nil
{
if
err
!=
nil
{
return
oldSize
,
err
return
oldSize
,
err
}
}
...
...
pkg/volume/aws_ebs/aws_util.go
View file @
093e2312
...
@@ -83,11 +83,13 @@ func (util *AWSDiskUtil) CreateVolume(c *awsElasticBlockStoreProvisioner) (aws.K
...
@@ -83,11 +83,13 @@ func (util *AWSDiskUtil) CreateVolume(c *awsElasticBlockStoreProvisioner) (aws.K
tags
[
"Name"
]
=
volumeutil
.
GenerateVolumeName
(
c
.
options
.
ClusterName
,
c
.
options
.
PVName
,
255
)
// AWS tags can have 255 characters
tags
[
"Name"
]
=
volumeutil
.
GenerateVolumeName
(
c
.
options
.
ClusterName
,
c
.
options
.
PVName
,
255
)
// AWS tags can have 255 characters
capacity
:=
c
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
c
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
requestBytes
:=
capacity
.
Value
()
// AWS works with gigabytes, convert to GiB with rounding up
// AWS works with gigabytes, convert to GiB with rounding up
requestGB
:=
int
(
volumeutil
.
RoundUpSize
(
requestBytes
,
1024
*
1024
*
1024
))
requestGiB
,
err
:=
volumeutil
.
RoundUpToGiBInt
(
capacity
)
if
err
!=
nil
{
return
""
,
0
,
nil
,
""
,
err
}
volumeOptions
:=
&
aws
.
VolumeOptions
{
volumeOptions
:=
&
aws
.
VolumeOptions
{
CapacityGB
:
requestGB
,
CapacityGB
:
requestG
i
B
,
Tags
:
tags
,
Tags
:
tags
,
PVCName
:
c
.
options
.
PVC
.
Name
,
PVCName
:
c
.
options
.
PVC
.
Name
,
}
}
...
@@ -147,7 +149,7 @@ func (util *AWSDiskUtil) CreateVolume(c *awsElasticBlockStoreProvisioner) (aws.K
...
@@ -147,7 +149,7 @@ func (util *AWSDiskUtil) CreateVolume(c *awsElasticBlockStoreProvisioner) (aws.K
glog
.
Errorf
(
"error building labels for new EBS volume %q: %v"
,
name
,
err
)
glog
.
Errorf
(
"error building labels for new EBS volume %q: %v"
,
name
,
err
)
}
}
return
name
,
int
(
requestGB
)
,
labels
,
fstype
,
nil
return
name
,
requestGiB
,
labels
,
fstype
,
nil
}
}
// Returns the first path that exists, or empty string if none exist.
// Returns the first path that exists, or empty string if none exist.
...
...
pkg/volume/azure_dd/azure_provision.go
View file @
093e2312
...
@@ -100,8 +100,10 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
...
@@ -100,8 +100,10 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
// maxLength = 79 - (4 for ".vhd") = 75
// maxLength = 79 - (4 for ".vhd") = 75
name
:=
util
.
GenerateVolumeName
(
p
.
options
.
ClusterName
,
p
.
options
.
PVName
,
75
)
name
:=
util
.
GenerateVolumeName
(
p
.
options
.
ClusterName
,
p
.
options
.
PVName
,
75
)
capacity
:=
p
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
p
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
requestBytes
:=
capacity
.
Value
()
requestGiB
,
err
:=
util
.
RoundUpToGiBInt
(
capacity
)
requestGB
:=
int
(
util
.
RoundUpSize
(
requestBytes
,
1024
*
1024
*
1024
))
if
err
!=
nil
{
return
nil
,
err
}
for
k
,
v
:=
range
p
.
options
.
Parameters
{
for
k
,
v
:=
range
p
.
options
.
Parameters
{
switch
strings
.
ToLower
(
k
)
{
switch
strings
.
ToLower
(
k
)
{
...
@@ -157,18 +159,18 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
...
@@ -157,18 +159,18 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
if
p
.
options
.
CloudTags
!=
nil
{
if
p
.
options
.
CloudTags
!=
nil
{
tags
=
*
(
p
.
options
.
CloudTags
)
tags
=
*
(
p
.
options
.
CloudTags
)
}
}
diskURI
,
err
=
diskController
.
CreateManagedDisk
(
name
,
skuName
,
resourceGroup
,
requestGB
,
tags
)
diskURI
,
err
=
diskController
.
CreateManagedDisk
(
name
,
skuName
,
resourceGroup
,
requestG
i
B
,
tags
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
else
{
}
else
{
if
kind
==
v1
.
AzureDedicatedBlobDisk
{
if
kind
==
v1
.
AzureDedicatedBlobDisk
{
_
,
diskURI
,
_
,
err
=
diskController
.
CreateVolume
(
name
,
account
,
storageAccountType
,
location
,
requestGB
)
_
,
diskURI
,
_
,
err
=
diskController
.
CreateVolume
(
name
,
account
,
storageAccountType
,
location
,
requestG
i
B
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
else
{
}
else
{
diskURI
,
err
=
diskController
.
CreateBlobDisk
(
name
,
skuName
,
requestGB
)
diskURI
,
err
=
diskController
.
CreateBlobDisk
(
name
,
skuName
,
requestG
i
B
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -196,7 +198,7 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
...
@@ -196,7 +198,7 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
PersistentVolumeReclaimPolicy
:
p
.
options
.
PersistentVolumeReclaimPolicy
,
PersistentVolumeReclaimPolicy
:
p
.
options
.
PersistentVolumeReclaimPolicy
,
AccessModes
:
supportedModes
,
AccessModes
:
supportedModes
,
Capacity
:
v1
.
ResourceList
{
Capacity
:
v1
.
ResourceList
{
v1
.
ResourceName
(
v1
.
ResourceStorage
)
:
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
requestGB
)),
v1
.
ResourceName
(
v1
.
ResourceStorage
)
:
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
requestG
i
B
)),
},
},
VolumeMode
:
volumeMode
,
VolumeMode
:
volumeMode
,
PersistentVolumeSource
:
v1
.
PersistentVolumeSource
{
PersistentVolumeSource
:
v1
.
PersistentVolumeSource
{
...
...
pkg/volume/cinder/cinder_util.go
View file @
093e2312
...
@@ -169,9 +169,12 @@ func (util *DiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID string,
...
@@ -169,9 +169,12 @@ func (util *DiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID string,
}
}
capacity
:=
c
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
c
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
volSizeBytes
:=
capacity
.
Value
()
// Cinder works with gigabytes, convert to GiB with rounding up
// Cinder works with gigabytes, convert to GiB with rounding up
volSizeGB
:=
int
(
volutil
.
RoundUpSize
(
volSizeBytes
,
1024
*
1024
*
1024
))
volSizeGiB
,
err
:=
volutil
.
RoundUpToGiBInt
(
capacity
)
if
err
!=
nil
{
return
""
,
0
,
nil
,
""
,
err
}
name
:=
volutil
.
GenerateVolumeName
(
c
.
options
.
ClusterName
,
c
.
options
.
PVName
,
255
)
// Cinder volume name can have up to 255 characters
name
:=
volutil
.
GenerateVolumeName
(
c
.
options
.
ClusterName
,
c
.
options
.
PVName
,
255
)
// Cinder volume name can have up to 255 characters
vtype
:=
""
vtype
:=
""
availability
:=
""
availability
:=
""
...
@@ -208,7 +211,7 @@ func (util *DiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID string,
...
@@ -208,7 +211,7 @@ func (util *DiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID string,
}
}
}
}
volumeID
,
volumeAZ
,
volumeRegion
,
IgnoreVolumeAZ
,
err
:=
cloud
.
CreateVolume
(
name
,
volSizeGB
,
vtype
,
availability
,
c
.
options
.
CloudTags
)
volumeID
,
volumeAZ
,
volumeRegion
,
IgnoreVolumeAZ
,
err
:=
cloud
.
CreateVolume
(
name
,
volSizeG
i
B
,
vtype
,
availability
,
c
.
options
.
CloudTags
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
V
(
2
)
.
Infof
(
"Error creating cinder volume: %v"
,
err
)
glog
.
V
(
2
)
.
Infof
(
"Error creating cinder volume: %v"
,
err
)
return
""
,
0
,
nil
,
""
,
err
return
""
,
0
,
nil
,
""
,
err
...
@@ -221,7 +224,7 @@ func (util *DiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID string,
...
@@ -221,7 +224,7 @@ func (util *DiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID string,
volumeLabels
[
kubeletapis
.
LabelZoneFailureDomain
]
=
volumeAZ
volumeLabels
[
kubeletapis
.
LabelZoneFailureDomain
]
=
volumeAZ
volumeLabels
[
kubeletapis
.
LabelZoneRegion
]
=
volumeRegion
volumeLabels
[
kubeletapis
.
LabelZoneRegion
]
=
volumeRegion
}
}
return
volumeID
,
volSizeGB
,
volumeLabels
,
fstype
,
nil
return
volumeID
,
volSizeG
i
B
,
volumeLabels
,
fstype
,
nil
}
}
func
probeAttachedVolume
()
error
{
func
probeAttachedVolume
()
error
{
...
...
pkg/volume/flocker/flocker_util.go
View file @
093e2312
...
@@ -49,7 +49,7 @@ func (util *FlockerUtil) DeleteVolume(d *flockerVolumeDeleter) error {
...
@@ -49,7 +49,7 @@ func (util *FlockerUtil) DeleteVolume(d *flockerVolumeDeleter) error {
return
d
.
flockerClient
.
DeleteDataset
(
datasetUUID
)
return
d
.
flockerClient
.
DeleteDataset
(
datasetUUID
)
}
}
func
(
util
*
FlockerUtil
)
CreateVolume
(
c
*
flockerVolumeProvisioner
)
(
datasetUUID
string
,
volumeSizeGB
int
,
labels
map
[
string
]
string
,
err
error
)
{
func
(
util
*
FlockerUtil
)
CreateVolume
(
c
*
flockerVolumeProvisioner
)
(
datasetUUID
string
,
volumeSizeG
i
B
int
,
labels
map
[
string
]
string
,
err
error
)
{
if
c
.
flockerClient
==
nil
{
if
c
.
flockerClient
==
nil
{
c
.
flockerClient
,
err
=
c
.
plugin
.
newFlockerClient
(
""
)
c
.
flockerClient
,
err
=
c
.
plugin
.
newFlockerClient
(
""
)
...
@@ -74,7 +74,10 @@ func (util *FlockerUtil) CreateVolume(c *flockerVolumeProvisioner) (datasetUUID
...
@@ -74,7 +74,10 @@ func (util *FlockerUtil) CreateVolume(c *flockerVolumeProvisioner) (datasetUUID
capacity
:=
c
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
c
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
requestBytes
:=
capacity
.
Value
()
requestBytes
:=
capacity
.
Value
()
volumeSizeGB
=
int
(
volutil
.
RoundUpSize
(
requestBytes
,
1024
*
1024
*
1024
))
volumeSizeGiB
,
err
=
volutil
.
RoundUpToGiBInt
(
capacity
)
if
err
!=
nil
{
return
}
createOptions
:=
&
flockerapi
.
CreateDatasetOptions
{
createOptions
:=
&
flockerapi
.
CreateDatasetOptions
{
MaximumSize
:
requestBytes
,
MaximumSize
:
requestBytes
,
...
...
pkg/volume/glusterfs/glusterfs.go
View file @
093e2312
...
@@ -744,7 +744,10 @@ func (p *glusterfsVolumeProvisioner) CreateVolume(gid int) (r *v1.GlusterfsVolum
...
@@ -744,7 +744,10 @@ func (p *glusterfsVolumeProvisioner) CreateVolume(gid int) (r *v1.GlusterfsVolum
capacity
:=
p
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
p
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
// GlusterFS/heketi creates volumes in units of GiB.
// GlusterFS/heketi creates volumes in units of GiB.
sz
:=
int
(
volutil
.
RoundUpToGiB
(
capacity
))
sz
,
err
:=
volutil
.
RoundUpToGiBInt
(
capacity
)
if
err
!=
nil
{
return
nil
,
0
,
""
,
err
}
glog
.
V
(
2
)
.
Infof
(
"create volume of size %dGiB"
,
sz
)
glog
.
V
(
2
)
.
Infof
(
"create volume of size %dGiB"
,
sz
)
if
p
.
url
==
""
{
if
p
.
url
==
""
{
...
...
pkg/volume/photon_pd/photon_util.go
View file @
093e2312
...
@@ -88,9 +88,11 @@ func (util *PhotonDiskUtil) CreateVolume(p *photonPersistentDiskProvisioner) (pd
...
@@ -88,9 +88,11 @@ func (util *PhotonDiskUtil) CreateVolume(p *photonPersistentDiskProvisioner) (pd
}
}
capacity
:=
p
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
p
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
volSizeBytes
:=
capacity
.
Value
()
// PhotonController works with GiB, convert to GiB with rounding up
// PhotonController works with GB, convert to GB with rounding up
volSizeGB
,
err
:=
volumeutil
.
RoundUpToGiBInt
(
capacity
)
volSizeGB
:=
int
(
volumeutil
.
RoundUpSize
(
volSizeBytes
,
1024
*
1024
*
1024
))
if
err
!=
nil
{
return
""
,
0
,
""
,
err
}
name
:=
volumeutil
.
GenerateVolumeName
(
p
.
options
.
ClusterName
,
p
.
options
.
PVName
,
255
)
name
:=
volumeutil
.
GenerateVolumeName
(
p
.
options
.
ClusterName
,
p
.
options
.
PVName
,
255
)
volumeOptions
:=
&
photon
.
VolumeOptions
{
volumeOptions
:=
&
photon
.
VolumeOptions
{
CapacityGB
:
volSizeGB
,
CapacityGB
:
volSizeGB
,
...
...
pkg/volume/quobyte/quobyte_util.go
View file @
093e2312
...
@@ -35,7 +35,10 @@ type quobyteVolumeManager struct {
...
@@ -35,7 +35,10 @@ type quobyteVolumeManager struct {
func
(
manager
*
quobyteVolumeManager
)
createVolume
(
provisioner
*
quobyteVolumeProvisioner
,
createQuota
bool
)
(
quobyte
*
v1
.
QuobyteVolumeSource
,
size
int
,
err
error
)
{
func
(
manager
*
quobyteVolumeManager
)
createVolume
(
provisioner
*
quobyteVolumeProvisioner
,
createQuota
bool
)
(
quobyte
*
v1
.
QuobyteVolumeSource
,
size
int
,
err
error
)
{
capacity
:=
provisioner
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
provisioner
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
volumeSize
:=
int
(
util
.
RoundUpSize
(
capacity
.
Value
(),
1024
*
1024
*
1024
))
volumeSize
,
err
:=
util
.
RoundUpToGiBInt
(
capacity
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
// Quobyte has the concept of Volumes which doen't have a specific size (they can grow unlimited)
// Quobyte has the concept of Volumes which doen't have a specific size (they can grow unlimited)
// to simulate a size constraint we set here a Quota for logical space
// to simulate a size constraint we set here a Quota for logical space
volumeRequest
:=
&
quobyteapi
.
CreateVolumeRequest
{
volumeRequest
:=
&
quobyteapi
.
CreateVolumeRequest
{
...
...
pkg/volume/rbd/rbd_util.go
View file @
093e2312
...
@@ -579,7 +579,10 @@ func (util *RBDUtil) CreateImage(p *rbdVolumeProvisioner) (r *v1.RBDPersistentVo
...
@@ -579,7 +579,10 @@ func (util *RBDUtil) CreateImage(p *rbdVolumeProvisioner) (r *v1.RBDPersistentVo
capacity
:=
p
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
p
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
volSizeBytes
:=
capacity
.
Value
()
volSizeBytes
:=
capacity
.
Value
()
// Convert to MB that rbd defaults on.
// Convert to MB that rbd defaults on.
sz
:=
int
(
volutil
.
RoundUpSize
(
volSizeBytes
,
1024
*
1024
))
sz
,
err
:=
volutil
.
RoundUpSizeInt
(
volSizeBytes
,
1024
*
1024
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
volSz
:=
fmt
.
Sprintf
(
"%d"
,
sz
)
volSz
:=
fmt
.
Sprintf
(
"%d"
,
sz
)
mon
:=
util
.
kernelRBDMonitorsOpt
(
p
.
Mon
)
mon
:=
util
.
kernelRBDMonitorsOpt
(
p
.
Mon
)
if
p
.
rbdMounter
.
imageFormat
==
rbdImageFormat2
{
if
p
.
rbdMounter
.
imageFormat
==
rbdImageFormat2
{
...
...
pkg/volume/storageos/storageos.go
View file @
093e2312
...
@@ -602,7 +602,11 @@ func (c *storageosProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
...
@@ -602,7 +602,11 @@ func (c *storageosProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
c
.
labels
[
k
]
=
v
c
.
labels
[
k
]
=
v
}
}
capacity
:=
c
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
c
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
c
.
sizeGB
=
int
(
util
.
RoundUpSize
(
capacity
.
Value
(),
1024
*
1024
*
1024
))
var
err
error
c
.
sizeGB
,
err
=
util
.
RoundUpToGiBInt
(
capacity
)
if
err
!=
nil
{
return
nil
,
err
}
apiCfg
,
err
:=
parsePVSecret
(
adminSecretNamespace
,
adminSecretName
,
c
.
plugin
.
host
.
GetKubeClient
())
apiCfg
,
err
:=
parsePVSecret
(
adminSecretNamespace
,
adminSecretName
,
c
.
plugin
.
host
.
GetKubeClient
())
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/volume/util/util.go
View file @
093e2312
...
@@ -361,7 +361,11 @@ func CalculateTimeoutForVolume(minimumTimeout, timeoutIncrement int, pv *v1.Pers
...
@@ -361,7 +361,11 @@ func CalculateTimeoutForVolume(minimumTimeout, timeoutIncrement int, pv *v1.Pers
// RoundUpSize(1500 * 1024*1024, 1024*1024*1024) returns '2'
// RoundUpSize(1500 * 1024*1024, 1024*1024*1024) returns '2'
// (2 GiB is the smallest allocatable volume that can hold 1500MiB)
// (2 GiB is the smallest allocatable volume that can hold 1500MiB)
func
RoundUpSize
(
volumeSizeBytes
int64
,
allocationUnitBytes
int64
)
int64
{
func
RoundUpSize
(
volumeSizeBytes
int64
,
allocationUnitBytes
int64
)
int64
{
return
(
volumeSizeBytes
+
allocationUnitBytes
-
1
)
/
allocationUnitBytes
roundedUp
:=
volumeSizeBytes
/
allocationUnitBytes
if
volumeSizeBytes
%
allocationUnitBytes
>
0
{
roundedUp
+=
1
}
return
roundedUp
}
}
// RoundUpToGB rounds up given quantity to chunks of GB
// RoundUpToGB rounds up given quantity to chunks of GB
...
@@ -376,6 +380,32 @@ func RoundUpToGiB(size resource.Quantity) int64 {
...
@@ -376,6 +380,32 @@ func RoundUpToGiB(size resource.Quantity) int64 {
return
RoundUpSize
(
requestBytes
,
GIB
)
return
RoundUpSize
(
requestBytes
,
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
)
}
return
roundedUpInt
,
nil
}
// RoundUpToGBInt rounds up given quantity to chunks of GB. It returns an
// int instead of an int64 and an error if there's overflow
func
RoundUpToGBInt
(
size
resource
.
Quantity
)
(
int
,
error
)
{
requestBytes
:=
size
.
Value
()
return
RoundUpSizeInt
(
requestBytes
,
GB
)
}
// 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
:=
size
.
Value
()
return
RoundUpSizeInt
(
requestBytes
,
GIB
)
}
// GenerateVolumeName returns a PV name with clusterName prefix. The function
// GenerateVolumeName returns a PV name with clusterName prefix. The function
// should be used to generate a name of GCE PD or Cinder volume. It basically
// should be used to generate a name of GCE PD or Cinder volume. It basically
// adds "<clusterName>-dynamic-" before the PV name, making sure the resulting
// adds "<clusterName>-dynamic-" before the PV name, making sure the resulting
...
...
pkg/volume/vsphere_volume/vsphere_volume_util.go
View file @
093e2312
...
@@ -93,10 +93,13 @@ func (util *VsphereDiskUtil) CreateVolume(v *vsphereVolumeProvisioner) (volSpec
...
@@ -93,10 +93,13 @@ func (util *VsphereDiskUtil) CreateVolume(v *vsphereVolumeProvisioner) (volSpec
capacity
:=
v
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
capacity
:=
v
.
options
.
PVC
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
volSizeBytes
:=
capacity
.
Value
()
volSizeBytes
:=
capacity
.
Value
()
// vSphere works with kilobytes, convert to KiB with rounding up
// vSphere works with kilobytes, convert to KiB with rounding up
volSizeKB
:=
int
(
volumeutil
.
RoundUpSize
(
volSizeBytes
,
1024
))
volSizeKiB
,
err
:=
volumeutil
.
RoundUpSizeInt
(
volSizeBytes
,
1024
)
if
err
!=
nil
{
return
nil
,
err
}
name
:=
volumeutil
.
GenerateVolumeName
(
v
.
options
.
ClusterName
,
v
.
options
.
PVName
,
255
)
name
:=
volumeutil
.
GenerateVolumeName
(
v
.
options
.
ClusterName
,
v
.
options
.
PVName
,
255
)
volumeOptions
:=
&
vclib
.
VolumeOptions
{
volumeOptions
:=
&
vclib
.
VolumeOptions
{
CapacityKB
:
volSizeKB
,
CapacityKB
:
volSizeK
i
B
,
Tags
:
*
v
.
options
.
CloudTags
,
Tags
:
*
v
.
options
.
CloudTags
,
Name
:
name
,
Name
:
name
,
}
}
...
@@ -146,7 +149,7 @@ func (util *VsphereDiskUtil) CreateVolume(v *vsphereVolumeProvisioner) (volSpec
...
@@ -146,7 +149,7 @@ func (util *VsphereDiskUtil) CreateVolume(v *vsphereVolumeProvisioner) (volSpec
}
}
volSpec
=
&
VolumeSpec
{
volSpec
=
&
VolumeSpec
{
Path
:
vmDiskPath
,
Path
:
vmDiskPath
,
Size
:
volSizeKB
,
Size
:
volSizeK
i
B
,
Fstype
:
fstype
,
Fstype
:
fstype
,
StoragePolicyName
:
volumeOptions
.
StoragePolicyName
,
StoragePolicyName
:
volumeOptions
.
StoragePolicyName
,
StoragePolicyID
:
volumeOptions
.
StoragePolicyID
,
StoragePolicyID
:
volumeOptions
.
StoragePolicyID
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment