Skip to content

Commit

Permalink
Merge pull request #5292 from MartinForReal/shafan/bumpdisktrack2
Browse files Browse the repository at this point in the history
Refactor: migrate getdatadisk to track2 api
  • Loading branch information
k8s-ci-robot authored Jan 17, 2024
2 parents 8a51c7d + 57b1e05 commit 2bb675d
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 512 deletions.
9 changes: 7 additions & 2 deletions pkg/provider/azure_controller_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/go-autorest/autorest/azure"

Expand Down Expand Up @@ -269,7 +270,7 @@ func (as *availabilitySet) updateCache(nodeName string, vm *compute.VirtualMachi
}

// GetDataDisks gets a list of data disks attached to the node.
func (as *availabilitySet) GetDataDisks(nodeName types.NodeName, crt azcache.AzureCacheReadType) ([]compute.DataDisk, *string, error) {
func (as *availabilitySet) GetDataDisks(nodeName types.NodeName, crt azcache.AzureCacheReadType) ([]*armcompute.DataDisk, *string, error) {
vm, err := as.getVirtualMachine(nodeName, crt)
if err != nil {
return nil, nil, err
Expand All @@ -279,5 +280,9 @@ func (as *availabilitySet) GetDataDisks(nodeName types.NodeName, crt azcache.Azu
return nil, nil, nil
}

return *vm.StorageProfile.DataDisks, vm.ProvisioningState, nil
result, err := ToArmcomputeDisk(*vm.StorageProfile.DataDisks)
if err != nil {
return nil, nil, err
}
return result, vm.ProvisioningState, nil
}
7 changes: 4 additions & 3 deletions pkg/provider/azure_controller_standard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/go-autorest/autorest/azure"
autorestmocks "github.com/Azure/go-autorest/autorest/mocks"
Expand Down Expand Up @@ -292,7 +293,7 @@ func TestGetDataDisks(t *testing.T) {
crt azcache.AzureCacheReadType
isDataDiskNull bool
expectedError bool
expectedDataDisks []compute.DataDisk
expectedDataDisks []*armcompute.DataDisk
}{
{
desc: "an error shall be returned if there's no corresponding vm",
Expand All @@ -304,7 +305,7 @@ func TestGetDataDisks(t *testing.T) {
{
desc: "correct list of data disks shall be returned if everything is good",
nodeName: "vm1",
expectedDataDisks: []compute.DataDisk{
expectedDataDisks: []*armcompute.DataDisk{
{
Lun: pointer.Int32(0),
Name: pointer.String("disk1"),
Expand All @@ -324,7 +325,7 @@ func TestGetDataDisks(t *testing.T) {
{
desc: "correct list of data disks shall be returned if everything is good",
nodeName: "vm1",
expectedDataDisks: []compute.DataDisk{
expectedDataDisks: []*armcompute.DataDisk{
{
Lun: pointer.Int32(0),
Name: pointer.String("disk1"),
Expand Down
10 changes: 7 additions & 3 deletions pkg/provider/azure_controller_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/go-autorest/autorest/azure"

Expand Down Expand Up @@ -286,7 +287,7 @@ func (ss *ScaleSet) UpdateVMAsync(ctx context.Context, nodeName types.NodeName)
}

// GetDataDisks gets a list of data disks attached to the node.
func (ss *ScaleSet) GetDataDisks(nodeName types.NodeName, crt azcache.AzureCacheReadType) ([]compute.DataDisk, *string, error) {
func (ss *ScaleSet) GetDataDisks(nodeName types.NodeName, crt azcache.AzureCacheReadType) ([]*armcompute.DataDisk, *string, error) {
vm, err := ss.getVmssVM(string(nodeName), crt)
if err != nil {
return nil, nil, err
Expand All @@ -298,8 +299,11 @@ func (ss *ScaleSet) GetDataDisks(nodeName types.NodeName, crt azcache.AzureCache
if storageProfile == nil || storageProfile.DataDisks == nil {
return nil, nil, nil
}

return *storageProfile.DataDisks, vm.AsVirtualMachineScaleSetVM().ProvisioningState, nil
result, err := ToArmcomputeDisk(*storageProfile.DataDisks)
if err != nil {
return nil, nil, err
}
return result, vm.AsVirtualMachineScaleSetVM().ProvisioningState, nil
}

return nil, nil, nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/provider/azure_controller_vmss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/go-autorest/autorest/azure"
autorestmocks "github.com/Azure/go-autorest/autorest/mocks"
Expand Down Expand Up @@ -426,7 +427,7 @@ func TestGetDataDisksWithVMSS(t *testing.T) {
desc string
crt azcache.AzureCacheReadType
nodeName types.NodeName
expectedDataDisks []compute.DataDisk
expectedDataDisks []*armcompute.DataDisk
isDataDiskNull bool
expectedErr bool
expectedErrMsg error
Expand All @@ -442,7 +443,7 @@ func TestGetDataDisksWithVMSS(t *testing.T) {
{
desc: "correct list of data disks shall be returned if everything is good",
nodeName: "vmss00-vm-000000",
expectedDataDisks: []compute.DataDisk{
expectedDataDisks: []*armcompute.DataDisk{
{
Lun: pointer.Int32(0),
Name: pointer.String("disk1"),
Expand All @@ -454,7 +455,7 @@ func TestGetDataDisksWithVMSS(t *testing.T) {
{
desc: "correct list of data disks shall be returned if everything is good",
nodeName: "vmss00-vm-000000",
expectedDataDisks: []compute.DataDisk{
expectedDataDisks: []*armcompute.DataDisk{
{
Lun: pointer.Int32(0),
Name: pointer.String("disk1"),
Expand Down
10 changes: 7 additions & 3 deletions pkg/provider/azure_controller_vmssflex.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"
"sync"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/go-autorest/autorest/azure"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -297,7 +298,7 @@ func (fs *FlexScaleSet) updateCache(nodeName string, vm *compute.VirtualMachine)
}

// GetDataDisks gets a list of data disks attached to the node.
func (fs *FlexScaleSet) GetDataDisks(nodeName types.NodeName, crt azcache.AzureCacheReadType) ([]compute.DataDisk, *string, error) {
func (fs *FlexScaleSet) GetDataDisks(nodeName types.NodeName, crt azcache.AzureCacheReadType) ([]*armcompute.DataDisk, *string, error) {
vm, err := fs.getVmssFlexVM(string(nodeName), crt)
if err != nil {
return nil, nil, err
Expand All @@ -306,6 +307,9 @@ func (fs *FlexScaleSet) GetDataDisks(nodeName types.NodeName, crt azcache.AzureC
if vm.StorageProfile.DataDisks == nil {
return nil, nil, nil
}

return *vm.StorageProfile.DataDisks, vm.ProvisioningState, nil
result, err := ToArmcomputeDisk(*vm.StorageProfile.DataDisks)
if err != nil {
return nil, nil, err
}
return result, vm.ProvisioningState, nil
}
7 changes: 4 additions & 3 deletions pkg/provider/azure_controller_vmssflex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/go-autorest/autorest/azure"
autorestmocks "github.com/Azure/go-autorest/autorest/mocks"
Expand Down Expand Up @@ -296,7 +297,7 @@ func TestGetDataDisksWithVmssFlex(t *testing.T) {
testVMListWithoutInstanceView []compute.VirtualMachine
testVMListWithOnlyInstanceView []compute.VirtualMachine
vmListErr error
expectedDataDisks []compute.DataDisk
expectedDataDisks []*armcompute.DataDisk
expectedErr error
}{
{
Expand All @@ -305,11 +306,11 @@ func TestGetDataDisksWithVmssFlex(t *testing.T) {
testVMListWithoutInstanceView: testVMListWithoutInstanceView,
testVMListWithOnlyInstanceView: testVMListWithOnlyInstanceView,
vmListErr: nil,
expectedDataDisks: []compute.DataDisk{
expectedDataDisks: []*armcompute.DataDisk{
{
Lun: pointer.Int32(1),
Name: pointer.String("dataDisktestvm1"),
ManagedDisk: &compute.ManagedDiskParameters{ID: pointer.String("uri")},
ManagedDisk: &armcompute.ManagedDiskParameters{ID: pointer.String("uri")},
},
},
expectedErr: nil,
Expand Down
Loading

0 comments on commit 2bb675d

Please sign in to comment.