mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 02:08:13 +00:00 
			
		
		
		
	Merge pull request #56600 from edisonxiang/fixvolumesize
Automatic merge from submit-queue (batch tested with PRs 56600, 56814). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix volume size allocation in gcd_pd **What this PR does / why we need it**: GCE PDs are allocated in chunks of GBs not GiB but CreateVolume function incorrectly creates volume in chunks of GiB. 1 GiB = 1024 * 1024 * 1024 Bytes 1 GB = 1000 * 1000 * 1000 Bytes **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #56081 **Special notes for your reviewer**: **Release note**: ```release-note Fixed dynamic provisioning of GCE PDs to round to the next GB instead of GiB ```
This commit is contained in:
		| @@ -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{ | ||||||
|   | |||||||
| @@ -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) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -81,9 +81,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() | 	// GCE PDs are allocated in chunks of GBs (not GiBs) | ||||||
| 	// GCE works with gigabytes, convert to GiB with rounding up | 	requestGB := volume.RoundUpToGB(capacity) | ||||||
| 	requestGB := volume.RoundUpSize(requestBytes, 1024*1024*1024) |  | ||||||
|  |  | ||||||
| 	// 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. | ||||||
|   | |||||||
| @@ -257,8 +257,8 @@ var _ = utils.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") | ||||||
| 					}, | 					}, | ||||||
| @@ -270,8 +270,8 @@ var _ = utils.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") | ||||||
| 					}, | 					}, | ||||||
| @@ -436,8 +436,8 @@ var _ = utils.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") | ||||||
| 				}, | 				}, | ||||||
| @@ -470,8 +470,8 @@ var _ = utils.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") | ||||||
| 				}, | 				}, | ||||||
| @@ -521,7 +521,7 @@ var _ = utils.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) | ||||||
| @@ -641,6 +641,14 @@ var _ = utils.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) | ||||||
| 		}) | 		}) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Submit Queue
					Kubernetes Submit Queue