mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
azuredisk size grow feature
fix comments fix comments
This commit is contained in:
parent
2b26234003
commit
880b7a3bda
@ -42,6 +42,7 @@ go_library(
|
|||||||
"//pkg/controller:go_default_library",
|
"//pkg/controller:go_default_library",
|
||||||
"//pkg/version:go_default_library",
|
"//pkg/version:go_default_library",
|
||||||
"//pkg/volume:go_default_library",
|
"//pkg/volume:go_default_library",
|
||||||
|
"//pkg/volume/util:go_default_library",
|
||||||
"//vendor/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute:go_default_library",
|
"//vendor/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute:go_default_library",
|
||||||
"//vendor/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network:go_default_library",
|
"//vendor/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network:go_default_library",
|
||||||
"//vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage:go_default_library",
|
"//vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage:go_default_library",
|
||||||
@ -55,6 +56,7 @@ go_library(
|
|||||||
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
||||||
"//vendor/github.com/rubiojr/go-vhd/vhd:go_default_library",
|
"//vendor/github.com/rubiojr/go-vhd/vhd:go_default_library",
|
||||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||||
|
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||||
|
@ -17,13 +17,17 @@ limitations under the License.
|
|||||||
package azure
|
package azure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute"
|
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute"
|
||||||
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
|
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
kwait "k8s.io/apimachinery/pkg/util/wait"
|
kwait "k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
"k8s.io/kubernetes/pkg/volume/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
//ManagedDiskController : managed disk controller struct
|
//ManagedDiskController : managed disk controller struct
|
||||||
@ -131,3 +135,41 @@ func (c *ManagedDiskController) getDisk(diskName string) (string, string, error)
|
|||||||
|
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResizeDisk Expand the disk to new size
|
||||||
|
func (c *ManagedDiskController) ResizeDisk(diskName string, oldSize resource.Quantity, newSize resource.Quantity) (resource.Quantity, error) {
|
||||||
|
ctx, cancel := getContextWithCancel()
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
result, err := c.common.cloud.DisksClient.Get(ctx, c.common.resourceGroup, diskName)
|
||||||
|
if err != nil {
|
||||||
|
return oldSize, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.DiskProperties == nil || result.DiskProperties.DiskSizeGB == nil {
|
||||||
|
return oldSize, fmt.Errorf("DiskProperties of disk(%s) is nil", diskName)
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBytes := newSize.Value()
|
||||||
|
// Azure resizes in chunks of GiB (not GB)
|
||||||
|
requestGiB := int32(util.RoundUpSize(requestBytes, 1024*1024*1024))
|
||||||
|
newSizeQuant := resource.MustParse(fmt.Sprintf("%dGi", requestGiB))
|
||||||
|
|
||||||
|
glog.V(2).Infof("azureDisk - begin to resize disk(%s) with new size(%d), old size(%v)", diskName, requestGiB, oldSize)
|
||||||
|
// If disk already of greater or equal size than requested we return
|
||||||
|
if *result.DiskProperties.DiskSizeGB >= requestGiB {
|
||||||
|
return newSizeQuant, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
result.DiskProperties.DiskSizeGB = &requestGiB
|
||||||
|
|
||||||
|
ctx, cancel = getContextWithCancel()
|
||||||
|
defer cancel()
|
||||||
|
if _, err := c.common.cloud.DisksClient.CreateOrUpdate(ctx, c.common.resourceGroup, diskName, result); err != nil {
|
||||||
|
return oldSize, err
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.V(2).Infof("azureDisk - resize disk(%s) with new size(%d) completed", diskName, requestGiB)
|
||||||
|
|
||||||
|
return newSizeQuant, nil
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
|
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider/providers/azure"
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/azure"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
@ -55,6 +56,9 @@ type DiskController interface {
|
|||||||
CreateVolume(name, storageAccount, storageAccountType, location string, requestGB int) (string, string, int, error)
|
CreateVolume(name, storageAccount, storageAccountType, location string, requestGB int) (string, string, int, error)
|
||||||
// Delete a VHD blob
|
// Delete a VHD blob
|
||||||
DeleteVolume(diskURI string) error
|
DeleteVolume(diskURI string) error
|
||||||
|
|
||||||
|
// Expand the disk to new size
|
||||||
|
ResizeDisk(diskName string, oldSize resource.Quantity, newSize resource.Quantity) (resource.Quantity, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type azureDataDiskPlugin struct {
|
type azureDataDiskPlugin struct {
|
||||||
@ -67,6 +71,7 @@ var _ volume.DeletableVolumePlugin = &azureDataDiskPlugin{}
|
|||||||
var _ volume.ProvisionableVolumePlugin = &azureDataDiskPlugin{}
|
var _ volume.ProvisionableVolumePlugin = &azureDataDiskPlugin{}
|
||||||
var _ volume.AttachableVolumePlugin = &azureDataDiskPlugin{}
|
var _ volume.AttachableVolumePlugin = &azureDataDiskPlugin{}
|
||||||
var _ volume.VolumePluginWithAttachLimits = &azureDataDiskPlugin{}
|
var _ volume.VolumePluginWithAttachLimits = &azureDataDiskPlugin{}
|
||||||
|
var _ volume.ExpandableVolumePlugin = &azureDataDiskPlugin{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
azureDataDiskPluginName = "kubernetes.io/azure-disk"
|
azureDataDiskPluginName = "kubernetes.io/azure-disk"
|
||||||
@ -210,6 +215,26 @@ func (plugin *azureDataDiskPlugin) NewUnmounter(volName string, podUID types.UID
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (plugin *azureDataDiskPlugin) RequiresFSResize() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (plugin *azureDataDiskPlugin) ExpandVolumeDevice(
|
||||||
|
spec *volume.Spec,
|
||||||
|
newSize resource.Quantity,
|
||||||
|
oldSize resource.Quantity) (resource.Quantity, error) {
|
||||||
|
if spec.PersistentVolume == nil || spec.PersistentVolume.Spec.AzureDisk == nil {
|
||||||
|
return oldSize, fmt.Errorf("invalid PV spec")
|
||||||
|
}
|
||||||
|
|
||||||
|
diskController, err := getDiskController(plugin.host)
|
||||||
|
if err != nil {
|
||||||
|
return oldSize, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return diskController.ResizeDisk(spec.PersistentVolume.Spec.AzureDisk.DiskName, oldSize, newSize)
|
||||||
|
}
|
||||||
|
|
||||||
func (plugin *azureDataDiskPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) {
|
func (plugin *azureDataDiskPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) {
|
||||||
mounter := plugin.host.GetMounter(plugin.GetPluginName())
|
mounter := plugin.host.GetMounter(plugin.GetPluginName())
|
||||||
pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName())
|
pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName())
|
||||||
|
@ -164,5 +164,9 @@ func (pvcr *persistentVolumeClaimResize) checkVolumePlugin(pv *api.PersistentVol
|
|||||||
if pv.Spec.AzureFile != nil {
|
if pv.Spec.AzureFile != nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pv.Spec.AzureDisk != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user