Fix GCE CreateVolume allocates in chunks of GiB incorrectly

This commit is contained in:
edisonxiang 2017-11-30 09:28:13 +08:00
parent cab439b20f
commit d80dbe7fea
4 changed files with 21 additions and 13 deletions

View File

@ -423,7 +423,7 @@ func (c *gcePersistentDiskProvisioner) Provision() (*v1.PersistentVolume, error)
PersistentVolumeReclaimPolicy: c.options.PersistentVolumeReclaimPolicy, PersistentVolumeReclaimPolicy: c.options.PersistentVolumeReclaimPolicy,
AccessModes: c.options.PVC.Spec.AccessModes, AccessModes: c.options.PVC.Spec.AccessModes,
Capacity: v1.ResourceList{ Capacity: v1.ResourceList{
v1.ResourceName(v1.ResourceStorage): resource.MustParse(fmt.Sprintf("%dGi", sizeGB)), v1.ResourceName(v1.ResourceStorage): resource.MustParse(fmt.Sprintf("%dG", sizeGB)),
}, },
PersistentVolumeSource: v1.PersistentVolumeSource{ PersistentVolumeSource: v1.PersistentVolumeSource{
GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{ GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{

View File

@ -183,7 +183,7 @@ func TestPlugin(t *testing.T) {
} }
cap := persistentSpec.Spec.Capacity[v1.ResourceStorage] cap := persistentSpec.Spec.Capacity[v1.ResourceStorage]
size := cap.Value() size := cap.Value()
if size != 100*1024*1024*1024 { if size != 100*volume.GB {
t.Errorf("Provision() returned unexpected volume size: %v", size) t.Errorf("Provision() returned unexpected volume size: %v", size)
} }

View File

@ -82,8 +82,8 @@ func (gceutil *GCEDiskUtil) CreateVolume(c *gcePersistentDiskProvisioner) (strin
name := volume.GenerateVolumeName(c.options.ClusterName, c.options.PVName, 63) // GCE PD name can have up to 63 characters name := volume.GenerateVolumeName(c.options.ClusterName, c.options.PVName, 63) // GCE PD name can have up to 63 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() requestBytes := capacity.Value()
// GCE works with gigabytes, convert to GiB with rounding up // GCE PDs are allocated in chunks of GBs (not GiBs)
requestGB := volume.RoundUpSize(requestBytes, 1024*1024*1024) requestGB := volume.RoundUpSize(requestBytes, volume.GB)
// Apply Parameters (case-insensitive). We leave validation of // Apply Parameters (case-insensitive). We leave validation of
// the values to the cloud provider. // the values to the cloud provider.

View File

@ -256,8 +256,8 @@ var _ = SIGDescribe("Dynamic Provisioning", func() {
"type": "pd-ssd", "type": "pd-ssd",
"zone": cloudZone, "zone": cloudZone,
}, },
"1.5Gi", "1.5G",
"2Gi", "2G",
func(volume *v1.PersistentVolume) error { func(volume *v1.PersistentVolume) error {
return checkGCEPD(volume, "pd-ssd") return checkGCEPD(volume, "pd-ssd")
}, },
@ -269,8 +269,8 @@ var _ = SIGDescribe("Dynamic Provisioning", func() {
map[string]string{ map[string]string{
"type": "pd-standard", "type": "pd-standard",
}, },
"1.5Gi", "1.5G",
"2Gi", "2G",
func(volume *v1.PersistentVolume) error { func(volume *v1.PersistentVolume) error {
return checkGCEPD(volume, "pd-standard") return checkGCEPD(volume, "pd-standard")
}, },
@ -435,8 +435,8 @@ var _ = SIGDescribe("Dynamic Provisioning", func() {
map[string]string{ map[string]string{
"type": "pd-standard", "type": "pd-standard",
}, },
"1Gi", "1G",
"1Gi", "1G",
func(volume *v1.PersistentVolume) error { func(volume *v1.PersistentVolume) error {
return checkGCEPD(volume, "pd-standard") return checkGCEPD(volume, "pd-standard")
}, },
@ -469,8 +469,8 @@ var _ = SIGDescribe("Dynamic Provisioning", func() {
map[string]string{ map[string]string{
"type": "pd-standard", "type": "pd-standard",
}, },
"1Gi", "1G",
"1Gi", "1G",
func(volume *v1.PersistentVolume) error { func(volume *v1.PersistentVolume) error {
return checkGCEPD(volume, "pd-standard") return checkGCEPD(volume, "pd-standard")
}, },
@ -520,7 +520,7 @@ var _ = SIGDescribe("Dynamic Provisioning", func() {
name: "unmanaged_zone", name: "unmanaged_zone",
provisioner: "kubernetes.io/gce-pd", provisioner: "kubernetes.io/gce-pd",
parameters: map[string]string{"zone": unmanagedZone}, parameters: map[string]string{"zone": unmanagedZone},
claimSize: "1Gi", claimSize: "1G",
} }
sc := newStorageClass(test, ns, suffix) sc := newStorageClass(test, ns, suffix)
sc, err = c.StorageV1().StorageClasses().Create(sc) sc, err = c.StorageV1().StorageClasses().Create(sc)
@ -640,6 +640,14 @@ var _ = SIGDescribe("Dynamic Provisioning", func() {
claimSize: "2Gi", claimSize: "2Gi",
expectedSize: "2Gi", expectedSize: "2Gi",
} }
// gce or gke
if getDefaultPluginName() == "kubernetes.io/gce-pd" {
// using GB not GiB as e2e test unit since gce-pd returns GB,
// or expectedSize may be greater than claimSize.
test.claimSize = "2G"
test.expectedSize = "2G"
}
claim := newClaim(test, ns, "default") claim := newClaim(test, ns, "default")
testDynamicProvisioning(test, c, claim, nil) testDynamicProvisioning(test, c, claim, nil)
}) })