From 25cf5039cc47b255d746a33f706ff0218f08bb00 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Thu, 1 Dec 2022 11:44:21 +0000 Subject: [PATCH] fix: add disk lun check in VMSSFlex AttachDisk to avoid race condition --- go.mod | 2 +- go.sum | 4 ++-- vendor/modules.txt | 4 ++-- .../pkg/provider/azure_controller_vmssflex.go | 13 +++++++++---- .../pkg/provider/azure_utils.go | 5 ++++- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 7b971d76cd..43c93e8d3a 100644 --- a/go.mod +++ b/go.mod @@ -144,5 +144,5 @@ replace ( k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.24.0-alpha.4 k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.24.0-alpha.4 k8s.io/sample-controller => k8s.io/sample-controller v0.24.0-alpha.4 - sigs.k8s.io/cloud-provider-azure => sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221127220127-3a7fec959fb3 + sigs.k8s.io/cloud-provider-azure => sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221201101027-11407986e99d ) diff --git a/go.sum b/go.sum index ebe272390c..e2041cf5f7 100644 --- a/go.sum +++ b/go.sum @@ -1207,8 +1207,8 @@ rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30/go.mod h1:fEO7lRTdivWO2qYVCVG7dEADOMo/MLDCVr8So2g88Uw= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.33 h1:LYqFq+6Cj2D0gFfrJvL7iElD4ET6ir3VDdhDdTK7rgc= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.33/go.mod h1:soWkSNf2tZC7aMibXEqVhCd73GOY5fJikn8qbdzemB0= -sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221127220127-3a7fec959fb3 h1:6VDdLir8+NVwtfYiCmt9DOrjSOz1Zyc2E/Y/R7yY6Yo= -sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221127220127-3a7fec959fb3/go.mod h1:My3CvQ0U/1jzQ9r0Z/yyREkW+xckcdXQY09m3NK9exo= +sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221201101027-11407986e99d h1:p/mMH2tVFZdx0EGJBLweBl8iLbzfeDnVA6nvIHB0+xY= +sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221201101027-11407986e99d/go.mod h1:My3CvQ0U/1jzQ9r0Z/yyREkW+xckcdXQY09m3NK9exo= sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2/go.mod h1:B+TnT182UBxE84DiCz4CVE26eOSDAeYCpfDnC2kdKMY= sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k= sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= diff --git a/vendor/modules.txt b/vendor/modules.txt index 20f0a188f6..0e10828fca 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1059,7 +1059,7 @@ k8s.io/utils/trace ## explicit; go 1.17 sigs.k8s.io/apiserver-network-proxy/konnectivity-client/pkg/client sigs.k8s.io/apiserver-network-proxy/konnectivity-client/proto/client -# sigs.k8s.io/cloud-provider-azure v0.7.4 => sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221127220127-3a7fec959fb3 +# sigs.k8s.io/cloud-provider-azure v0.7.4 => sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221201101027-11407986e99d ## explicit; go 1.18 sigs.k8s.io/cloud-provider-azure/pkg/auth sigs.k8s.io/cloud-provider-azure/pkg/azureclients @@ -1155,4 +1155,4 @@ sigs.k8s.io/yaml # k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.24.0-alpha.4 # k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.24.0-alpha.4 # k8s.io/sample-controller => k8s.io/sample-controller v0.24.0-alpha.4 -# sigs.k8s.io/cloud-provider-azure => sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221127220127-3a7fec959fb3 +# sigs.k8s.io/cloud-provider-azure => sigs.k8s.io/cloud-provider-azure v0.7.4-0.20221201101027-11407986e99d diff --git a/vendor/sigs.k8s.io/cloud-provider-azure/pkg/provider/azure_controller_vmssflex.go b/vendor/sigs.k8s.io/cloud-provider-azure/pkg/provider/azure_controller_vmssflex.go index 753ee22fad..42964e2cde 100644 --- a/vendor/sigs.k8s.io/cloud-provider-azure/pkg/provider/azure_controller_vmssflex.go +++ b/vendor/sigs.k8s.io/cloud-provider-azure/pkg/provider/azure_controller_vmssflex.go @@ -18,6 +18,7 @@ package provider import ( "context" + "fmt" "net/http" "strings" @@ -51,13 +52,17 @@ func (fs *FlexScaleSet) AttachDisk(ctx context.Context, nodeName types.NodeName, opt := v attached := false for _, disk := range *vm.StorageProfile.DataDisks { - if disk.ManagedDisk != nil && strings.EqualFold(*disk.ManagedDisk.ID, diskURI) { - attached = true - break + if disk.ManagedDisk != nil && strings.EqualFold(*disk.ManagedDisk.ID, diskURI) && disk.Lun != nil { + if *disk.Lun == opt.lun { + attached = true + break + } else { + return nil, fmt.Errorf("disk(%s) already attached to node(%s) on LUN(%d), but target LUN is %d", diskURI, nodeName, *disk.Lun, opt.lun) + } } } if attached { - klog.V(2).Infof("azureDisk - disk(%s) already attached to node(%s)", diskURI, nodeName) + klog.V(2).Infof("azureDisk - disk(%s) already attached to node(%s) on LUN(%d)", diskURI, nodeName, opt.lun) continue } diff --git a/vendor/sigs.k8s.io/cloud-provider-azure/pkg/provider/azure_utils.go b/vendor/sigs.k8s.io/cloud-provider-azure/pkg/provider/azure_utils.go index fe353f7084..e3542f35c9 100644 --- a/vendor/sigs.k8s.io/cloud-provider-azure/pkg/provider/azure_utils.go +++ b/vendor/sigs.k8s.io/cloud-provider-azure/pkg/provider/azure_utils.go @@ -316,7 +316,9 @@ func isNodeInVMSSVMCache(nodeName string, vmssVMCache *azcache.TimedCache) bool for _, entry := range vmssVMCache.Store.List() { if entry != nil { - data := entry.(*azcache.AzureCacheEntry).Data + e := entry.(*azcache.AzureCacheEntry) + e.Lock.Lock() + data := e.Data if data != nil { data.(*sync.Map).Range(func(vmName, _ interface{}) bool { if vmName != nil && vmName.(string) == nodeName { @@ -326,6 +328,7 @@ func isNodeInVMSSVMCache(nodeName string, vmssVMCache *azcache.TimedCache) bool return true }) } + e.Lock.Unlock() } if isInCache {