Skip to content

Commit

Permalink
Merge pull request #2154 from MartinForReal/shafan/bumpcloudprovider
Browse files Browse the repository at this point in the history
Refactor:bump cloudprovider and adopt new function changes
  • Loading branch information
k8s-ci-robot authored Jan 16, 2024
2 parents c2fc3b9 + 274da7b commit d0242a2
Show file tree
Hide file tree
Showing 31 changed files with 345 additions and 1,243 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/kubernetes-csi/csi-lib-utils v0.17.0
github.com/kubernetes-csi/csi-proxy/client v1.1.3
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
github.com/pelletier/go-toml v1.9.5
github.com/stretchr/testify v1.8.4
Expand All @@ -40,9 +40,9 @@ require (
k8s.io/mount-utils v0.29.0
k8s.io/pod-security-admission v0.0.0
k8s.io/utils v0.0.0-20231127182322-b307cd553661
sigs.k8s.io/cloud-provider-azure v1.27.1-0.20240109125110-b65c47cc857e
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.0-20240109125110-b65c47cc857e
sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader v0.0.0-20240109125110-b65c47cc857e
sigs.k8s.io/cloud-provider-azure v1.27.1-0.20240114181025-ca41d9562e6c
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.0-20240114181025-ca41d9562e6c
sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader v0.0.0-20240114181025-ca41d9562e6c
sigs.k8s.io/yaml v1.4.0
)

Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3Ro
github.com/onsi/ginkgo/v2 v2.9.7/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0=
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
github.com/onsi/ginkgo/v2 v2.14.0 h1:vSmGj2Z5YPb9JwCWT6z6ihcUvDhuXLc3sJiqd3jMKAY=
github.com/onsi/ginkgo/v2 v2.14.0/go.mod h1:JkUdW7JkN0V6rFvsHcJ478egV3XH9NxpD27Hal/PhZw=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
Expand Down Expand Up @@ -2037,12 +2037,12 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 h1:TgtAeesdhpm2SGwkQasmbeqDo8th5wOBA5h/AjTKA4I=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0/go.mod h1:VHVDI/KrK4fjnV61bE2g3sA7tiETLn8sooImelsCx3Y=
sigs.k8s.io/cloud-provider-azure v1.27.1-0.20240109125110-b65c47cc857e h1:zZfSBMGRNr0b+WCWu1LavF5qlRGWFdipVUATODY9CsA=
sigs.k8s.io/cloud-provider-azure v1.27.1-0.20240109125110-b65c47cc857e/go.mod h1:0WCrYlWxqk3/AptztkqPk1r9Gr3IULSHat7LipAA1sI=
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.0-20240109125110-b65c47cc857e h1:PXmAxCp4Ljqs6NXaczNmC81wff9OjPSisdjtfNmi3lY=
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.0-20240109125110-b65c47cc857e/go.mod h1:E5FvnrVeWyRBfBTdmfb2Kztwi9KEloBwylMcyDpND2k=
sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader v0.0.0-20240109125110-b65c47cc857e h1:Jz0AXWFq330aeautfIjDrN1k4t8MAmDiQ/IoRUwGh/Q=
sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader v0.0.0-20240109125110-b65c47cc857e/go.mod h1:2kNmNMR+IWYltE68RhOePyt1PKefDq0Y3/3aHsmatSc=
sigs.k8s.io/cloud-provider-azure v1.27.1-0.20240114181025-ca41d9562e6c h1:5Q300VvljRNIT2LaKZ+xo9Z1NvAOKV1v007YxItji1Y=
sigs.k8s.io/cloud-provider-azure v1.27.1-0.20240114181025-ca41d9562e6c/go.mod h1:0WCrYlWxqk3/AptztkqPk1r9Gr3IULSHat7LipAA1sI=
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.0-20240114181025-ca41d9562e6c h1:6RWYYBDabcs2L3bs+t5IPSDietkKTqDUqJ+drIhx6xk=
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.0.0-20240114181025-ca41d9562e6c/go.mod h1:dhkW9GQLM9XJMvXcXziwy7QqDOLwaXU11FsGJyIpy+s=
sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader v0.0.0-20240114181025-ca41d9562e6c h1:/UCu9sYXGn3zhT0/B74nxc3EE5lRNuDVJC8gCYqk+K8=
sigs.k8s.io/cloud-provider-azure/pkg/azclient/configloader v0.0.0-20240114181025-ca41d9562e6c/go.mod h1:slvzU7aF5CMzat64pn/LdpgU4mLYBDQGqm1fjXMAp1Q=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
Expand Down
1 change: 0 additions & 1 deletion pkg/azuredisk/azure_controller_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ func TestCommonAttachDisk(t *testing.T) {
tt := test
t.Run(tt.desc, func(t *testing.T) {
testCloud := provider.GetTestCloud(ctrl)
testCloud.DisableDiskLunCheck = true
diskURI := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/disks/%s",
testCloud.SubscriptionID, testCloud.ResourceGroup, test.diskName)
if tt.isBadDiskURI {
Expand Down
17 changes: 14 additions & 3 deletions pkg/azuredisk/azure_managedDiskController_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,13 @@ func TestGetDisk(t *testing.T) {

for i, test := range testCases {
testCloud := provider.GetTestCloud(ctrl)
managedDiskController := testCloud.ManagedDiskController

managedDiskController := &ManagedDiskController{
controllerCommon: &controllerCommon{
cloud: testCloud,
lockMap: newLockMap(),
DisableDiskLunCheck: true,
},
}
mockDisksClient := testCloud.DisksClient.(*mockdiskclient.MockInterface)
if test.diskName == fakeGetDiskFailed {
mockDisksClient.EXPECT().Get(gomock.Any(), "", testCloud.ResourceGroup, test.diskName).Return(test.existedDisk, &retry.Error{RawError: fmt.Errorf("Get Disk failed")}).AnyTimes()
Expand Down Expand Up @@ -562,7 +567,13 @@ func TestResizeDisk(t *testing.T) {

for i, test := range testCases {
testCloud := provider.GetTestCloud(ctrl)
managedDiskController := testCloud.ManagedDiskController
managedDiskController := &ManagedDiskController{
controllerCommon: &controllerCommon{
cloud: testCloud,
lockMap: newLockMap(),
DisableDiskLunCheck: true,
},
}
diskURI := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/disks/%s",
testCloud.SubscriptionID, testCloud.ResourceGroup, *test.existedDisk.Name)

Expand Down
9 changes: 3 additions & 6 deletions pkg/azuredisk/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ func newDriverV1(options *DriverOptions) *Driver {

if driver.cloud != nil {
driver.diskController = NewManagedDiskController(driver.cloud)
driver.diskController.DisableUpdateCache = driver.disableUpdateCache
driver.diskController.AttachDetachInitialDelayInMs = int(driver.attachDetachInitialDelayInMs)
if driver.vmType != "" {
klog.V(2).Infof("override VMType(%s) in cloud config as %s", driver.cloud.VMType, driver.vmType)
driver.cloud.VMType = driver.vmType
Expand Down Expand Up @@ -209,11 +211,6 @@ func newDriverV1(options *DriverOptions) *Driver {
driver.cloud.VMCacheTTLInSeconds = int(driver.vmssCacheTTLInSeconds)
driver.cloud.VmssCacheTTLInSeconds = int(driver.vmssCacheTTLInSeconds)
}

if driver.cloud.ManagedDiskController != nil {
driver.cloud.DisableUpdateCache = driver.disableUpdateCache
driver.cloud.AttachDetachInitialDelayInMs = int(driver.attachDetachInitialDelayInMs)
}
}

driver.deviceHelper = optimization.NewSafeDeviceHelper()
Expand Down Expand Up @@ -538,7 +535,7 @@ func (d *DriverCore) getUsedLunsFromVolumeAttachments(ctx context.Context, nodeN

// getUsedLunsFromNode returns a list of sorted used luns from Node
func (d *DriverCore) getUsedLunsFromNode(nodeName types.NodeName) ([]int, error) {
disks, _, err := d.cloud.GetNodeDataDisks(nodeName, azcache.CacheReadTypeDefault)
disks, _, err := d.diskController.GetNodeDataDisks(nodeName, azcache.CacheReadTypeDefault)
if err != nil {
klog.Errorf("error of getting data disks for node %s: %v", nodeName, err)
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/azuredisk/azuredisk_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ func newDriverV2(options *DriverOptions) *DriverV2 {

if driver.cloud != nil {
driver.diskController = NewManagedDiskController(driver.cloud)
driver.diskController.DisableUpdateCache = driver.disableUpdateCache
driver.diskController.AttachDetachInitialDelayInMs = int(driver.attachDetachInitialDelayInMs)
if driver.vmType != "" {
klog.V(2).Infof("override VMType(%s) in cloud config as %s", driver.cloud.VMType, driver.vmType)
driver.cloud.VMType = driver.vmType
Expand Down
23 changes: 17 additions & 6 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,24 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}

localCloud := d.cloud
localDiskController := d.diskController

if diskParams.UserAgent != "" {
localCloud, err = azureutils.GetCloudProviderFromClient(ctx, d.kubeClient, d.cloudConfigSecretName, d.cloudConfigSecretNamespace, diskParams.UserAgent,
d.allowEmptyCloudConfig, d.enableTrafficManager, d.trafficManagerPort)
if err != nil {
return nil, status.Errorf(codes.Internal, "create cloud with UserAgent(%s) failed with: (%s)", diskParams.UserAgent, err)
}
localDiskController = &ManagedDiskController{
controllerCommon: &controllerCommon{
cloud: localCloud,
lockMap: newLockMap(),
DisableDiskLunCheck: true,
},
}
localDiskController.DisableUpdateCache = d.disableUpdateCache
localDiskController.AttachDetachInitialDelayInMs = int(d.attachDetachInitialDelayInMs)

}
if azureutils.IsAzureStackCloud(localCloud.Config.Cloud, localCloud.Config.DisableAzureStackCloud) {
if diskParams.MaxShares > 1 {
Expand Down Expand Up @@ -254,7 +265,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}

diskParams.VolumeContext[consts.RequestedSizeGib] = strconv.Itoa(requestGiB)
volumeOptions := &azure.ManagedDiskOptions{
volumeOptions := &ManagedDiskOptions{
AvailabilityZone: diskZone,
BurstingEnabled: diskParams.EnableBursting,
DiskEncryptionSetID: diskParams.DiskEncryptionSetID,
Expand Down Expand Up @@ -292,7 +303,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
mc.ObserveOperationWithResult(isOperationSucceeded, consts.VolumeID, diskURI)
}()

diskURI, err = localCloud.CreateManagedDisk(ctx, volumeOptions)
diskURI, err = localDiskController.CreateManagedDisk(ctx, volumeOptions)
if err != nil {
if strings.Contains(err.Error(), consts.NotFound) {
return nil, status.Error(codes.NotFound, err.Error())
Expand Down Expand Up @@ -343,7 +354,7 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
}()

klog.V(2).Infof("deleting azure disk(%s)", diskURI)
err := d.cloud.DeleteManagedDisk(ctx, diskURI)
err := d.diskController.DeleteManagedDisk(ctx, diskURI)
klog.V(2).Infof("delete azure disk(%s) returned with %v", diskURI, err)
isOperationSucceeded = (err == nil)
return &csi.DeleteVolumeResponse{}, err
Expand Down Expand Up @@ -403,7 +414,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
mc.ObserveOperationWithResult(isOperationSucceeded, consts.VolumeID, diskURI, consts.Node, string(nodeName))
}()

lun, vmState, err := d.cloud.GetDiskLun(diskName, diskURI, nodeName)
lun, vmState, err := d.diskController.GetDiskLun(diskName, diskURI, nodeName)
if err == cloudprovider.InstanceNotFound {
return nil, status.Error(codes.NotFound, fmt.Sprintf("failed to get azure instance id for node %q (%v)", nodeName, err))
}
Expand All @@ -423,7 +434,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
if err == nil {
if vmState != nil && strings.ToLower(*vmState) == "failed" {
klog.Warningf("VM(%s) is in failed state, update VM first", nodeName)
if err := d.cloud.UpdateVM(ctx, nodeName); err != nil {
if err := d.diskController.UpdateVM(ctx, nodeName); err != nil {
return nil, status.Errorf(codes.Internal, "update instance %q failed with %v", nodeName, err)
}
}
Expand All @@ -445,7 +456,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
attachDiskInitialDelay := azureutils.GetAttachDiskInitialDelay(volumeContext)
if attachDiskInitialDelay > 0 {
klog.V(2).Infof("attachDiskInitialDelayInMs is set to %d", attachDiskInitialDelay)
d.cloud.AttachDetachInitialDelayInMs = attachDiskInitialDelay
d.diskController.AttachDetachInitialDelayInMs = attachDiskInitialDelay
}
lun, err = d.diskController.AttachDisk(ctx, diskName, diskURI, nodeName, cachingMode, disk, occupiedLuns)
if err == nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/azuredisk/controllerserver_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (d *DriverV2) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeReques
}()

klog.V(2).Infof("deleting azure disk(%s)", diskURI)
err := d.cloud.DeleteManagedDisk(ctx, diskURI)
err := d.diskController.DeleteManagedDisk(ctx, diskURI)
klog.V(2).Infof("delete azure disk(%s) returned with %v", diskURI, err)
isOperationSucceeded = (err == nil)
return &csi.DeleteVolumeResponse{}, err
Expand Down Expand Up @@ -346,7 +346,7 @@ func (d *DriverV2) ControllerPublishVolume(ctx context.Context, req *csi.Control
mc.ObserveOperationWithResult(isOperationSucceeded, consts.VolumeID, diskURI, consts.Node, string(nodeName))
}()

lun, vmState, err := d.cloud.GetDiskLun(diskName, diskURI, nodeName)
lun, vmState, err := d.diskController.GetDiskLun(diskName, diskURI, nodeName)
if err == cloudprovider.InstanceNotFound {
return nil, status.Error(codes.NotFound, fmt.Sprintf("failed to get azure instance id for node %q (%v)", nodeName, err))
}
Expand All @@ -361,7 +361,7 @@ func (d *DriverV2) ControllerPublishVolume(ctx context.Context, req *csi.Control
if err == nil {
if vmState != nil && strings.ToLower(*vmState) == "failed" {
klog.Warningf("VM(%s) is in failed state, update VM first", nodeName)
if err := d.cloud.UpdateVM(ctx, nodeName); err != nil {
if err := d.diskController.UpdateVM(ctx, nodeName); err != nil {
return nil, status.Errorf(codes.Internal, "update instance %q failed with %v", nodeName, err)
}
}
Expand Down
25 changes: 25 additions & 0 deletions vendor/github.com/onsi/ginkgo/v2/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d0242a2

Please sign in to comment.