Skip to content

Commit b26467b

Browse files
committed
feat: add SSE+CMK support for azure disk
add logging fix comment
1 parent f10d44b commit b26467b

File tree

7 files changed

+29
-14
lines changed

7 files changed

+29
-14
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (c *controllerCommon) getNodeVMSet(nodeName types.NodeName, crt cacheReadTy
9898
// AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI.
9999
// return (lun, error)
100100
func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error) {
101+
diskEncryptionSetID := ""
101102
if isManagedDisk {
102103
diskName := path.Base(diskURI)
103104
resourceGroup, err := getResourceGroupFromDiskURI(diskURI)
@@ -122,6 +123,11 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
122123
danglingErr := volerr.NewDanglingError(attachErr, types.NodeName(attachedNode), "")
123124
return -1, danglingErr
124125
}
126+
127+
if disk.DiskProperties != nil && disk.DiskProperties.Encryption != nil &&
128+
disk.DiskProperties.Encryption.DiskEncryptionSetID != nil {
129+
diskEncryptionSetID = *disk.DiskProperties.Encryption.DiskEncryptionSetID
130+
}
125131
}
126132

127133
vmset, err := c.getNodeVMSet(nodeName, cacheReadTypeUnsafe)
@@ -145,7 +151,7 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
145151
}
146152

147153
klog.V(2).Infof("Trying to attach volume %q lun %d to node %q.", diskURI, lun, nodeName)
148-
return lun, vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode)
154+
return lun, vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode, diskEncryptionSetID)
149155
}
150156

151157
// 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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
// AttachDisk attaches a vhd to vm
3232
// the vhd must exist, can be identified by diskName, diskURI, and lun.
33-
func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes) error {
33+
func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error {
3434
vm, err := as.getVirtualMachine(nodeName, cacheReadTypeDefault)
3535
if err != nil {
3636
return err
@@ -46,15 +46,17 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
4646
copy(disks, *vm.StorageProfile.DataDisks)
4747

4848
if isManagedDisk {
49+
managedDisk := &compute.ManagedDiskParameters{ID: &diskURI}
50+
if diskEncryptionSetID != "" {
51+
managedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: &diskEncryptionSetID}
52+
}
4953
disks = append(disks,
5054
compute.DataDisk{
5155
Name: &diskName,
5256
Lun: &lun,
5357
Caching: cachingMode,
5458
CreateOption: "attach",
55-
ManagedDisk: &compute.ManagedDiskParameters{
56-
ID: &diskURI,
57-
},
59+
ManagedDisk: managedDisk,
5860
})
5961
} else {
6062
disks = append(disks,
@@ -77,7 +79,7 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
7779
},
7880
},
7981
}
80-
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s, %s)", nodeResourceGroup, vmName, diskName, diskURI)
82+
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s, %s) with DiskEncryptionSetID(%s)", nodeResourceGroup, vmName, diskName, diskURI, diskEncryptionSetID)
8183
ctx, cancel := getContextWithCancel()
8284
defer cancel()
8385

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, "")
5757
assert.Equal(t, test.expectedErr, err != nil, "TestCase[%d]: %s", i, test.desc)
5858
}
5959
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
// AttachDisk attaches a vhd to vm
3232
// the vhd must exist, can be identified by diskName, diskURI, and lun.
33-
func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes) error {
33+
func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error {
3434
vmName := mapNodeNameToVMName(nodeName)
3535
ssName, instanceID, vm, err := ss.getVmssVM(vmName, cacheReadTypeDefault)
3636
if err != nil {
@@ -48,15 +48,17 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
4848
copy(disks, *vm.StorageProfile.DataDisks)
4949
}
5050
if isManagedDisk {
51+
managedDisk := &compute.ManagedDiskParameters{ID: &diskURI}
52+
if diskEncryptionSetID != "" {
53+
managedDisk.DiskEncryptionSet = &compute.DiskEncryptionSetParameters{ID: &diskEncryptionSetID}
54+
}
5155
disks = append(disks,
5256
compute.DataDisk{
5357
Name: &diskName,
5458
Lun: &lun,
5559
Caching: compute.CachingTypes(cachingMode),
5660
CreateOption: "attach",
57-
ManagedDisk: &compute.ManagedDiskParameters{
58-
ID: &diskURI,
59-
},
61+
ManagedDisk: managedDisk,
6062
})
6163
} else {
6264
disks = append(disks,
@@ -90,7 +92,7 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
9092
return err
9193
}
9294

93-
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s, %s)", nodeResourceGroup, nodeName, diskName, diskURI)
95+
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s, %s) with DiskEncryptionSetID(%s)", nodeResourceGroup, nodeName, diskName, diskURI, diskEncryptionSetID)
9496
_, err = ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, newVM, "attach_disk")
9597
if err != nil {
9698
detail := err.Error()

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
@@ -942,7 +942,7 @@ func (f *fakeVMSet) EnsureBackendPoolDeleted(service *v1.Service, backendPoolID,
942942
return fmt.Errorf("unimplemented")
943943
}
944944

945-
func (f *fakeVMSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes) error {
945+
func (f *fakeVMSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, lun int32, cachingMode compute.CachingTypes, diskEncryptionSetID string) error {
946946
return fmt.Errorf("unimplemented")
947947
}
948948

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const (
4040
// default IOPS Caps & Throughput Cap (MBps) per https://docs.microsoft.com/en-us/azure/virtual-machines/linux/disks-ultra-ssd
4141
defaultDiskIOPSReadWrite = 500
4242
defaultDiskMBpsReadWrite = 100
43+
44+
diskEncryptionSetIDFormat = "/subscriptions/{subs-id}/resourceGroups/{rg-name}/providers/Microsoft.Compute/diskEncryptionSets/{diskEncryptionSet-name}"
4345
)
4446

4547
//ManagedDiskController : managed disk controller struct
@@ -132,6 +134,9 @@ func (c *ManagedDiskController) CreateManagedDisk(options *ManagedDiskOptions) (
132134
}
133135

134136
if options.DiskEncryptionSetID != "" {
137+
if strings.Index(strings.ToLower(options.DiskEncryptionSetID), "/subscriptions/") != 0 {
138+
return "", fmt.Errorf("AzureDisk - format of DiskEncryptionSetID(%s) is incorrect, correct format: %s", options.DiskEncryptionSetID, diskEncryptionSetIDFormat)
139+
}
135140
diskProperties.Encryption = &compute.Encryption{
136141
DiskEncryptionSetID: &options.DiskEncryptionSetID,
137142
Type: compute.EncryptionAtRestWithCustomerKey,

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
@@ -66,7 +66,7 @@ type VMSet interface {
6666
EnsureBackendPoolDeleted(service *v1.Service, backendPoolID, vmSetName string, backendAddressPools *[]network.BackendAddressPool) error
6767

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

0 commit comments

Comments
 (0)