Skip to content

Commit

Permalink
feat: add PerformancePlus option in disk creation
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx committed May 5, 2023
1 parent 69b57f4 commit b7c5014
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 6 additions & 4 deletions pkg/provider/azure_controller_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,15 @@ func vmUpdateRequired(future *azure.Future, err error) bool {
return configAccepted(future) && errCode == consts.OperationPreemptedErrorCode
}

func getValidCreationData(subscriptionID, resourceGroup, sourceResourceID, sourceType string) (compute.CreationData, error) {
if sourceResourceID == "" {
func getValidCreationData(subscriptionID, resourceGroup string, options *ManagedDiskOptions) (compute.CreationData, error) {
if options.SourceResourceID == "" {
return compute.CreationData{
CreateOption: compute.Empty,
}, nil
}

switch sourceType {
sourceResourceID := options.SourceResourceID
switch options.SourceType {
case sourceSnapshot:
if match := diskSnapshotPathRE.FindString(sourceResourceID); match == "" {
sourceResourceID = fmt.Sprintf(diskSnapshotPath, subscriptionID, resourceGroup, sourceResourceID)
Expand All @@ -749,14 +750,15 @@ func getValidCreationData(subscriptionID, resourceGroup, sourceResourceID, sourc

splits := strings.Split(sourceResourceID, "/")
if len(splits) > 9 {
if sourceType == sourceSnapshot {
if options.SourceType == sourceSnapshot {
return compute.CreationData{}, fmt.Errorf("sourceResourceID(%s) is invalid, correct format: %s", sourceResourceID, diskSnapshotPathRE)
}
return compute.CreationData{}, fmt.Errorf("sourceResourceID(%s) is invalid, correct format: %s", sourceResourceID, managedDiskPathRE)
}
return compute.CreationData{
CreateOption: compute.Copy,
SourceResourceID: &sourceResourceID,
PerformancePlus: options.PerformancePlus,
}, nil
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/provider/azure_controller_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,11 @@ func TestGetValidCreationData(t *testing.T) {
}

for _, test := range tests {
result, err := getValidCreationData(test.subscriptionID, test.resourceGroup, test.sourceResourceID, test.sourceType)
options := ManagedDiskOptions{
SourceResourceID: test.sourceResourceID,
SourceType: test.sourceType,
}
result, err := getValidCreationData(test.subscriptionID, test.resourceGroup, &options)
if !reflect.DeepEqual(result, test.expected1) || !reflect.DeepEqual(err, test.expected2) {
t.Errorf("input sourceResourceID: %v, sourceType: %v, getValidCreationData result: %v, expected1 : %v, err: %v, expected2: %v", test.sourceResourceID, test.sourceType, result, test.expected1, err, test.expected2)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/provider/azure_managedDiskController.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type ManagedDiskOptions struct {
SubscriptionID string
// Location - specify a different location
Location string
// PerformancePlus - Set this flag to true to get a boost on the performance target of the disk deployed
PerformancePlus *bool
}

// CreateManagedDisk: create managed disk
Expand Down Expand Up @@ -131,7 +133,7 @@ func (c *ManagedDiskController) CreateManagedDisk(ctx context.Context, options *
subsID = options.SubscriptionID
}

creationData, err := getValidCreationData(subsID, rg, options.SourceResourceID, options.SourceType)
creationData, err := getValidCreationData(subsID, rg, options)
if err != nil {
return "", err
}
Expand Down

0 comments on commit b7c5014

Please sign in to comment.