Skip to content

Commit 177506d

Browse files
authored
Merge pull request kubernetes#87945 from andyzhangx/azure-writeaccelerator
add azure disk WriteAccelerator support
2 parents f0c14f2 + 657dedc commit 177506d

File tree

7 files changed

+37
-16
lines changed

7 files changed

+37
-16
lines changed

pkg/volume/azure_dd/azure_provision.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
130130
availabilityZone string
131131
availabilityZones sets.String
132132
selectedAvailabilityZone string
133+
writeAcceleratorEnabled string
133134

134135
diskIopsReadWrite string
135136
diskMbpsReadWrite string
@@ -178,6 +179,8 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
178179
diskMbpsReadWrite = v
179180
case "diskencryptionsetid":
180181
diskEncryptionSetID = v
182+
case azure.WriteAcceleratorEnabled:
183+
writeAcceleratorEnabled = v
181184
default:
182185
return nil, fmt.Errorf("AzureDisk - invalid option %s in storage class", k)
183186
}
@@ -245,6 +248,9 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
245248
if p.options.CloudTags != nil {
246249
tags = *(p.options.CloudTags)
247250
}
251+
if strings.EqualFold(writeAcceleratorEnabled, "true") {
252+
tags[azure.WriteAcceleratorEnabled] = "true"
253+
}
248254

249255
volumeOptions := &azure.ManagedDiskOptions{
250256
DiskName: name,

staging/src/k8s.io/legacy-cloud-providers/azure/azure_controller_common.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ const (
5151
sourceSnapshot = "snapshot"
5252
sourceVolume = "volume"
5353

54+
// WriteAcceleratorEnabled support for Azure Write Accelerator on Azure Disks
55+
// https://docs.microsoft.com/azure/virtual-machines/windows/how-to-enable-write-accelerator
56+
WriteAcceleratorEnabled = "writeacceleratorenabled"
57+
5458
// see https://docs.microsoft.com/en-us/rest/api/compute/disks/createorupdate#create-a-managed-disk-by-copying-a-snapshot.
5559
diskSnapshotPath = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/snapshots/%s"
5660

@@ -113,6 +117,8 @@ func (c *controllerCommon) getNodeVMSet(nodeName types.NodeName, crt cacheReadTy
113117
// return (lun, error)
114118
func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error) {
115119
diskEncryptionSetID := ""
120+
writeAcceleratorEnabled := false
121+
116122
if isManagedDisk {
117123
diskName := path.Base(diskURI)
118124
resourceGroup, err := getResourceGroupFromDiskURI(diskURI)
@@ -142,6 +148,11 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
142148
disk.DiskProperties.Encryption.DiskEncryptionSetID != nil {
143149
diskEncryptionSetID = *disk.DiskProperties.Encryption.DiskEncryptionSetID
144150
}
151+
if v, ok := disk.Tags[WriteAcceleratorEnabled]; ok {
152+
if v != nil && strings.EqualFold(*v, "true") {
153+
writeAcceleratorEnabled = true
154+
}
155+
}
145156
}
146157

147158
vmset, err := c.getNodeVMSet(nodeName, cacheReadTypeUnsafe)
@@ -167,7 +178,7 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
167178
klog.V(2).Infof("Trying to attach volume %q lun %d to node %q.", diskURI, lun, nodeName)
168179
c.diskAttachDetachMap.Store(strings.ToLower(diskURI), "attaching")
169180
defer c.diskAttachDetachMap.Delete(strings.ToLower(diskURI))
170-
return lun, vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode, diskEncryptionSetID)
181+
return lun, vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode, diskEncryptionSetID, writeAcceleratorEnabled)
171182
}
172183

173184
// DetachDisk detaches a disk from host. The vhd can be identified by diskName or diskURI.

staging/src/k8s.io/legacy-cloud-providers/azure/azure_controller_standard.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ import (
2222
"strings"
2323

2424
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
25+
"github.com/Azure/go-autorest/autorest/to"
2526

2627
"k8s.io/apimachinery/pkg/types"
2728
"k8s.io/klog"
2829
)
2930

3031
// AttachDisk attaches a vhd to vm
3132
// the vhd must exist, can be identified by diskName, diskURI, and lun.
32-
func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error {
33+
func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string, writeAcceleratorEnabled bool) error {
3334
vm, err := as.getVirtualMachine(nodeName, cacheReadTypeDefault)
3435
if err != nil {
3536
return err
@@ -59,11 +60,12 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
5960
}
6061
disks = append(disks,
6162
compute.DataDisk{
62-
Name: &diskName,
63-
Lun: &lun,
64-
Caching: cachingMode,
65-
CreateOption: "attach",
66-
ManagedDisk: managedDisk,
63+
Name: &diskName,
64+
Lun: &lun,
65+
Caching: cachingMode,
66+
CreateOption: "attach",
67+
ManagedDisk: managedDisk,
68+
WriteAcceleratorEnabled: to.BoolPtr(writeAcceleratorEnabled),
6769
})
6870
} else {
6971
disks = append(disks,

staging/src/k8s.io/legacy-cloud-providers/azure/azure_controller_standard_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestStandardAttachDisk(t *testing.T) {
5353
setTestVirtualMachines(testCloud, map[string]string{"vm1": "PowerState/Running"}, false)
5454

5555
err := vmSet.AttachDisk(true, "",
56-
"uri", test.nodeName, 0, compute.CachingTypesReadOnly, "")
56+
"uri", test.nodeName, 0, compute.CachingTypesReadOnly, "", false)
5757
assert.Equal(t, test.expectedErr, err != nil, "TestCase[%d]: %s, err: %v", i, test.desc, err)
5858
}
5959
}

staging/src/k8s.io/legacy-cloud-providers/azure/azure_controller_vmss.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ import (
2222
"strings"
2323

2424
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
25+
"github.com/Azure/go-autorest/autorest/to"
2526

2627
"k8s.io/apimachinery/pkg/types"
2728
"k8s.io/klog"
2829
)
2930

3031
// AttachDisk attaches a vhd to vm
3132
// the vhd must exist, can be identified by diskName, diskURI, and lun.
32-
func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error {
33+
func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string, writeAcceleratorEnabled bool) error {
3334
vmName := mapNodeNameToVMName(nodeName)
3435
ssName, instanceID, vm, err := ss.getVmssVM(vmName, cacheReadTypeDefault)
3536
if err != nil {
@@ -61,11 +62,12 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
6162
}
6263
disks = append(disks,
6364
compute.DataDisk{
64-
Name: &diskName,
65-
Lun: &lun,
66-
Caching: compute.CachingTypes(cachingMode),
67-
CreateOption: "attach",
68-
ManagedDisk: managedDisk,
65+
Name: &diskName,
66+
Lun: &lun,
67+
Caching: compute.CachingTypes(cachingMode),
68+
CreateOption: "attach",
69+
ManagedDisk: managedDisk,
70+
WriteAcceleratorEnabled: to.BoolPtr(writeAcceleratorEnabled),
6971
})
7072
} else {
7173
disks = append(disks,

staging/src/k8s.io/legacy-cloud-providers/azure/azure_fakes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ func (f *fakeVMSet) EnsureBackendPoolDeleted(service *v1.Service, backendPoolID,
963963
return fmt.Errorf("unimplemented")
964964
}
965965

966-
func (f *fakeVMSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error {
966+
func (f *fakeVMSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string, writeAcceleratorEnabled bool) error {
967967
return fmt.Errorf("unimplemented")
968968
}
969969

staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmsets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type VMSet interface {
6464
EnsureBackendPoolDeleted(service *v1.Service, backendPoolID, vmSetName string, backendAddressPools *[]network.BackendAddressPool) error
6565

6666
// AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI, and lun.
67-
AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error
67+
AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string, writeAcceleratorEnabled bool) error
6868
// DetachDisk detaches a vhd from host. The vhd can be identified by diskName or diskURI.
6969
DetachDisk(diskName, diskURI string, nodeName types.NodeName) error
7070
// GetDataDisks gets a list of data disks attached to the node.

0 commit comments

Comments
 (0)