mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 04:27:54 +00:00
Heketi documentats incorrectly about sizes in GBs
Heketi documentation incorrectly says that volume size is created in GB but in fact is in GiB. Fix both resizing and create volume functions to relfect that.
This commit is contained in:
parent
2aeace402a
commit
fcfca65a54
@ -695,7 +695,7 @@ func (p *glusterfsVolumeProvisioner) Provision() (*v1.PersistentVolume, error) {
|
||||
|
||||
glog.V(2).Infof("Allocated GID [%d] for PVC %s", gid, p.options.PVC.Name)
|
||||
|
||||
glusterfs, sizeGB, err := p.CreateVolume(gid)
|
||||
glusterfs, sizeGiB, err := p.CreateVolume(gid)
|
||||
if err != nil {
|
||||
if releaseErr := gidTable.Release(gid); releaseErr != nil {
|
||||
glog.Errorf("error when releasing GID in storageclass: %s", scName)
|
||||
@ -724,7 +724,7 @@ func (p *glusterfsVolumeProvisioner) Provision() (*v1.PersistentVolume, error) {
|
||||
}
|
||||
|
||||
pv.Spec.Capacity = v1.ResourceList{
|
||||
v1.ResourceName(v1.ResourceStorage): resource.MustParse(fmt.Sprintf("%dG", sizeGB)),
|
||||
v1.ResourceName(v1.ResourceStorage): resource.MustParse(fmt.Sprintf("%dGi", sizeGiB)),
|
||||
}
|
||||
return pv, nil
|
||||
}
|
||||
@ -732,10 +732,9 @@ func (p *glusterfsVolumeProvisioner) Provision() (*v1.PersistentVolume, error) {
|
||||
func (p *glusterfsVolumeProvisioner) CreateVolume(gid int) (r *v1.GlusterfsVolumeSource, size int, err error) {
|
||||
var clusterIDs []string
|
||||
capacity := p.options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
|
||||
volSizeBytes := capacity.Value()
|
||||
// Glusterfs creates volumes in units of GBs
|
||||
sz := int(volume.RoundUpSize(volSizeBytes, 1000*1000*1000))
|
||||
glog.V(2).Infof("create volume of size: %d bytes and configuration %+v", volSizeBytes, p.provisionerConfig)
|
||||
// Glusterfs creates volumes in units of GiB, but heketi documentation incorrectly reports GBs
|
||||
sz := int(volume.RoundUpToGiB(capacity))
|
||||
glog.V(2).Infof("create volume of size: %d GiB and configuration %+v", sz, p.provisionerConfig)
|
||||
if p.url == "" {
|
||||
glog.Errorf("REST server endpoint is empty")
|
||||
return nil, 0, fmt.Errorf("failed to create glusterfs REST client, REST URL is empty")
|
||||
@ -1077,10 +1076,10 @@ func (plugin *glusterfsPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize res
|
||||
|
||||
// Find out delta size
|
||||
expansionSize := (newSize.Value() - oldSize.Value())
|
||||
expansionSizeGB := int(volume.RoundUpSize(expansionSize, 1000*1000*1000))
|
||||
expansionSizeGiB := int(volume.RoundUpSize(expansionSize, volume.GIB))
|
||||
|
||||
// Make volume expansion request
|
||||
volumeExpandReq := &gapi.VolumeExpandRequest{Size: expansionSizeGB}
|
||||
volumeExpandReq := &gapi.VolumeExpandRequest{Size: expansionSizeGiB}
|
||||
|
||||
// Expand the volume
|
||||
volumeInfoRes, err := cli.VolumeExpand(volumeID, volumeExpandReq)
|
||||
@ -1090,6 +1089,6 @@ func (plugin *glusterfsPlugin) ExpandVolumeDevice(spec *volume.Spec, newSize res
|
||||
}
|
||||
|
||||
glog.V(2).Infof("volume %s expanded to new size %d successfully", volumeName, volumeInfoRes.Size)
|
||||
newVolumeSize := resource.MustParse(fmt.Sprintf("%dG", volumeInfoRes.Size))
|
||||
newVolumeSize := resource.MustParse(fmt.Sprintf("%dGi", volumeInfoRes.Size))
|
||||
return newVolumeSize, nil
|
||||
}
|
||||
|
@ -38,6 +38,13 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
const (
|
||||
// GB - GigaByte size
|
||||
GB = 1000 * 1000 * 1000
|
||||
// GIB - GibiByte size
|
||||
GIB = 1024 * 1024 * 1024
|
||||
)
|
||||
|
||||
type RecycleEventRecorder func(eventtype, message string)
|
||||
|
||||
// RecycleVolumeByWatchingPodUntilCompletion is intended for use with volume
|
||||
@ -288,6 +295,18 @@ func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
|
||||
return (volumeSizeBytes + allocationUnitBytes - 1) / allocationUnitBytes
|
||||
}
|
||||
|
||||
// RoundUpToGB rounds up given quantity to chunks of GB
|
||||
func RoundUpToGB(size resource.Quantity) int64 {
|
||||
requestBytes := size.Value()
|
||||
return RoundUpSize(requestBytes, GB)
|
||||
}
|
||||
|
||||
// RoundUpToGiB rounds up given quantity upto chunks of GiB
|
||||
func RoundUpToGiB(size resource.Quantity) int64 {
|
||||
requestBytes := size.Value()
|
||||
return RoundUpSize(requestBytes, GIB)
|
||||
}
|
||||
|
||||
// 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
|
||||
// adds "<clusterName>-dynamic-" before the PV name, making sure the resulting
|
||||
|
Loading…
Reference in New Issue
Block a user