mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
feat: add SSE+CMK support for azure disk
add logging fix comment
This commit is contained in:
parent
f10d44bad2
commit
b26467b344
@ -98,6 +98,7 @@ func (c *controllerCommon) getNodeVMSet(nodeName types.NodeName, crt cacheReadTy
|
|||||||
// AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI.
|
// AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI.
|
||||||
// return (lun, error)
|
// return (lun, error)
|
||||||
func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error) {
|
func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error) {
|
||||||
|
diskEncryptionSetID := ""
|
||||||
if isManagedDisk {
|
if isManagedDisk {
|
||||||
diskName := path.Base(diskURI)
|
diskName := path.Base(diskURI)
|
||||||
resourceGroup, err := getResourceGroupFromDiskURI(diskURI)
|
resourceGroup, err := getResourceGroupFromDiskURI(diskURI)
|
||||||
@ -122,6 +123,11 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
|
|||||||
danglingErr := volerr.NewDanglingError(attachErr, types.NodeName(attachedNode), "")
|
danglingErr := volerr.NewDanglingError(attachErr, types.NodeName(attachedNode), "")
|
||||||
return -1, danglingErr
|
return -1, danglingErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if disk.DiskProperties != nil && disk.DiskProperties.Encryption != nil &&
|
||||||
|
disk.DiskProperties.Encryption.DiskEncryptionSetID != nil {
|
||||||
|
diskEncryptionSetID = *disk.DiskProperties.Encryption.DiskEncryptionSetID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vmset, err := c.getNodeVMSet(nodeName, cacheReadTypeUnsafe)
|
vmset, err := c.getNodeVMSet(nodeName, cacheReadTypeUnsafe)
|
||||||
@ -145,7 +151,7 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
klog.V(2).Infof("Trying to attach volume %q lun %d to node %q.", diskURI, lun, nodeName)
|
klog.V(2).Infof("Trying to attach volume %q lun %d to node %q.", diskURI, lun, nodeName)
|
||||||
return lun, vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode)
|
return lun, vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode, diskEncryptionSetID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DetachDisk detaches a disk from host. The vhd can be identified by diskName or diskURI.
|
// DetachDisk detaches a disk from host. The vhd can be identified by diskName or diskURI.
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
|
|
||||||
// AttachDisk attaches a vhd to vm
|
// AttachDisk attaches a vhd to vm
|
||||||
// the vhd must exist, can be identified by diskName, diskURI, and lun.
|
// the vhd must exist, can be identified by diskName, diskURI, and lun.
|
||||||
func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes) error {
|
func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error {
|
||||||
vm, err := as.getVirtualMachine(nodeName, cacheReadTypeDefault)
|
vm, err := as.getVirtualMachine(nodeName, cacheReadTypeDefault)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -46,15 +46,17 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
|
|||||||
copy(disks, *vm.StorageProfile.DataDisks)
|
copy(disks, *vm.StorageProfile.DataDisks)
|
||||||
|
|
||||||
if isManagedDisk {
|
if isManagedDisk {
|
||||||
|
managedDisk := &compute.ManagedDiskParameters{ID: &diskURI}
|
||||||
|
if diskEncryptionSetID != "" {
|
||||||
|
managedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: &diskEncryptionSetID}
|
||||||
|
}
|
||||||
disks = append(disks,
|
disks = append(disks,
|
||||||
compute.DataDisk{
|
compute.DataDisk{
|
||||||
Name: &diskName,
|
Name: &diskName,
|
||||||
Lun: &lun,
|
Lun: &lun,
|
||||||
Caching: cachingMode,
|
Caching: cachingMode,
|
||||||
CreateOption: "attach",
|
CreateOption: "attach",
|
||||||
ManagedDisk: &compute.ManagedDiskParameters{
|
ManagedDisk: managedDisk,
|
||||||
ID: &diskURI,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
disks = append(disks,
|
disks = append(disks,
|
||||||
@ -77,7 +79,7 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s, %s)", nodeResourceGroup, vmName, diskName, diskURI)
|
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s, %s) with DiskEncryptionSetID(%s)", nodeResourceGroup, vmName, diskName, diskURI, diskEncryptionSetID)
|
||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func TestStandardAttachDisk(t *testing.T) {
|
|||||||
setTestVirtualMachines(testCloud, map[string]string{"vm1": "PowerState/Running"}, false)
|
setTestVirtualMachines(testCloud, map[string]string{"vm1": "PowerState/Running"}, false)
|
||||||
|
|
||||||
err := vmSet.AttachDisk(true, "",
|
err := vmSet.AttachDisk(true, "",
|
||||||
"uri", test.nodeName, 0, compute.CachingTypesReadOnly)
|
"uri", test.nodeName, 0, compute.CachingTypesReadOnly, "")
|
||||||
assert.Equal(t, test.expectedErr, err != nil, "TestCase[%d]: %s", i, test.desc)
|
assert.Equal(t, test.expectedErr, err != nil, "TestCase[%d]: %s", i, test.desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
|
|
||||||
// AttachDisk attaches a vhd to vm
|
// AttachDisk attaches a vhd to vm
|
||||||
// the vhd must exist, can be identified by diskName, diskURI, and lun.
|
// the vhd must exist, can be identified by diskName, diskURI, and lun.
|
||||||
func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes) error {
|
func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error {
|
||||||
vmName := mapNodeNameToVMName(nodeName)
|
vmName := mapNodeNameToVMName(nodeName)
|
||||||
ssName, instanceID, vm, err := ss.getVmssVM(vmName, cacheReadTypeDefault)
|
ssName, instanceID, vm, err := ss.getVmssVM(vmName, cacheReadTypeDefault)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,15 +48,17 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
|
|||||||
copy(disks, *vm.StorageProfile.DataDisks)
|
copy(disks, *vm.StorageProfile.DataDisks)
|
||||||
}
|
}
|
||||||
if isManagedDisk {
|
if isManagedDisk {
|
||||||
|
managedDisk := &compute.ManagedDiskParameters{ID: &diskURI}
|
||||||
|
if diskEncryptionSetID != "" {
|
||||||
|
managedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: &diskEncryptionSetID}
|
||||||
|
}
|
||||||
disks = append(disks,
|
disks = append(disks,
|
||||||
compute.DataDisk{
|
compute.DataDisk{
|
||||||
Name: &diskName,
|
Name: &diskName,
|
||||||
Lun: &lun,
|
Lun: &lun,
|
||||||
Caching: compute.CachingTypes(cachingMode),
|
Caching: compute.CachingTypes(cachingMode),
|
||||||
CreateOption: "attach",
|
CreateOption: "attach",
|
||||||
ManagedDisk: &compute.ManagedDiskParameters{
|
ManagedDisk: managedDisk,
|
||||||
ID: &diskURI,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
disks = append(disks,
|
disks = append(disks,
|
||||||
@ -90,7 +92,7 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s, %s)", nodeResourceGroup, nodeName, diskName, diskURI)
|
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s, %s) with DiskEncryptionSetID(%s)", nodeResourceGroup, nodeName, diskName, diskURI, diskEncryptionSetID)
|
||||||
_, err = ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, newVM, "attach_disk")
|
_, err = ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, newVM, "attach_disk")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
detail := err.Error()
|
detail := err.Error()
|
||||||
|
@ -942,7 +942,7 @@ func (f *fakeVMSet) EnsureBackendPoolDeleted(service *v1.Service, backendPoolID,
|
|||||||
return fmt.Errorf("unimplemented")
|
return fmt.Errorf("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fakeVMSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes) error {
|
func (f *fakeVMSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error {
|
||||||
return fmt.Errorf("unimplemented")
|
return fmt.Errorf("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ const (
|
|||||||
// default IOPS Caps & Throughput Cap (MBps) per https://docs.microsoft.com/en-us/azure/virtual-machines/linux/disks-ultra-ssd
|
// default IOPS Caps & Throughput Cap (MBps) per https://docs.microsoft.com/en-us/azure/virtual-machines/linux/disks-ultra-ssd
|
||||||
defaultDiskIOPSReadWrite = 500
|
defaultDiskIOPSReadWrite = 500
|
||||||
defaultDiskMBpsReadWrite = 100
|
defaultDiskMBpsReadWrite = 100
|
||||||
|
|
||||||
|
diskEncryptionSetIDFormat = "/subscriptions/{subs-id}/resourceGroups/{rg-name}/providers/Microsoft.Compute/diskEncryptionSets/{diskEncryptionSet-name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
//ManagedDiskController : managed disk controller struct
|
//ManagedDiskController : managed disk controller struct
|
||||||
@ -132,6 +134,9 @@ func (c *ManagedDiskController) CreateManagedDisk(options *ManagedDiskOptions) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if options.DiskEncryptionSetID != "" {
|
if options.DiskEncryptionSetID != "" {
|
||||||
|
if strings.Index(strings.ToLower(options.DiskEncryptionSetID), "/subscriptions/") != 0 {
|
||||||
|
return "", fmt.Errorf("AzureDisk - format of DiskEncryptionSetID(%s) is incorrect, correct format: %s", options.DiskEncryptionSetID, diskEncryptionSetIDFormat)
|
||||||
|
}
|
||||||
diskProperties.Encryption = &compute.Encryption{
|
diskProperties.Encryption = &compute.Encryption{
|
||||||
DiskEncryptionSetID: &options.DiskEncryptionSetID,
|
DiskEncryptionSetID: &options.DiskEncryptionSetID,
|
||||||
Type: compute.EncryptionAtRestWithCustomerKey,
|
Type: compute.EncryptionAtRestWithCustomerKey,
|
||||||
|
@ -66,7 +66,7 @@ type VMSet interface {
|
|||||||
EnsureBackendPoolDeleted(service *v1.Service, backendPoolID, vmSetName string, backendAddressPools *[]network.BackendAddressPool) error
|
EnsureBackendPoolDeleted(service *v1.Service, backendPoolID, vmSetName string, backendAddressPools *[]network.BackendAddressPool) error
|
||||||
|
|
||||||
// AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI, and lun.
|
// AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI, and lun.
|
||||||
AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes) error
|
AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error
|
||||||
// DetachDisk detaches a vhd from host. The vhd can be identified by diskName or diskURI.
|
// DetachDisk detaches a vhd from host. The vhd can be identified by diskName or diskURI.
|
||||||
DetachDisk(diskName, diskURI string, nodeName types.NodeName) (*http.Response, error)
|
DetachDisk(diskName, diskURI string, nodeName types.NodeName) (*http.Response, error)
|
||||||
// GetDataDisks gets a list of data disks attached to the node.
|
// GetDataDisks gets a list of data disks attached to the node.
|
||||||
|
Loading…
Reference in New Issue
Block a user