Skip to content

Commit f889213

Browse files
committed
feat: support Azure shared disk
1 parent a19942c commit f889213

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

pkg/volume/azure_dd/azure_provision.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
133133
diskIopsReadWrite string
134134
diskMbpsReadWrite string
135135
diskEncryptionSetID string
136+
137+
maxShares int
136138
)
137139
// maxLength = 79 - (4 for ".vhd") = 75
138140
name := util.GenerateVolumeName(p.options.ClusterName, p.options.PVName, 75)
@@ -179,6 +181,14 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
179181
diskEncryptionSetID = v
180182
case azure.WriteAcceleratorEnabled:
181183
writeAcceleratorEnabled = v
184+
case "maxshares":
185+
maxShares, err = strconv.Atoi(v)
186+
if err != nil {
187+
return nil, fmt.Errorf("parse %s failed with error: %v", v, err)
188+
}
189+
if maxShares < 1 {
190+
return nil, fmt.Errorf("parse %s returned with invalid value: %d", v, maxShares)
191+
}
182192
default:
183193
return nil, fmt.Errorf("AzureDisk - invalid option %s in storage class", k)
184194
}
@@ -261,6 +271,7 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
261271
DiskIOPSReadWrite: diskIopsReadWrite,
262272
DiskMBpsReadWrite: diskMbpsReadWrite,
263273
DiskEncryptionSetID: diskEncryptionSetID,
274+
MaxShares: int32(maxShares),
264275
}
265276
diskURI, err = diskController.CreateManagedDisk(volumeOptions)
266277
if err != nil {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
136136
return -1, rerr.Error()
137137
}
138138

139-
if disk.ManagedBy != nil {
139+
if disk.ManagedBy != nil && (disk.MaxShares == nil || *disk.MaxShares <= 1) {
140140
attachErr := fmt.Sprintf(
141141
"disk(%s) already attached to node(%s), could not be attached to node(%s)",
142142
diskURI, *disk.ManagedBy, nodeName)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type ManagedDiskOptions struct {
7575
SourceType string
7676
// ResourceId of the disk encryption set to use for enabling encryption at rest.
7777
DiskEncryptionSetID string
78+
// The maximum number of VMs that can attach to the disk at the same time. Value greater than one indicates a disk that can be mounted on multiple VMs at the same time.
79+
MaxShares int32
7880
}
7981

8082
//CreateManagedDisk : create managed disk
@@ -152,6 +154,10 @@ func (c *ManagedDiskController) CreateManagedDisk(options *ManagedDiskOptions) (
152154
}
153155
}
154156

157+
if options.MaxShares > 1 {
158+
diskProperties.MaxShares = &options.MaxShares
159+
}
160+
155161
model := compute.Disk{
156162
Location: &c.common.location,
157163
Tags: newTags,

0 commit comments

Comments
 (0)