@@ -60,6 +60,7 @@ type scaleSet struct {
60
60
// (e.g. master nodes) may not belong to any scale sets.
61
61
availabilitySet VMSet
62
62
63
+ vmssCache * timedCache
63
64
vmssVMCache * timedCache
64
65
availabilitySetNodesCache * timedCache
65
66
}
@@ -77,6 +78,11 @@ func newScaleSet(az *Cloud) (VMSet, error) {
77
78
return nil , err
78
79
}
79
80
81
+ ss .vmssCache , err = ss .newVMSSCache ()
82
+ if err != nil {
83
+ return nil , err
84
+ }
85
+
80
86
ss .vmssVMCache , err = ss .newVMSSVirtualMachinesCache ()
81
87
if err != nil {
82
88
return nil , err
@@ -85,6 +91,43 @@ func newScaleSet(az *Cloud) (VMSet, error) {
85
91
return ss , nil
86
92
}
87
93
94
+ func (ss * scaleSet ) getVMSS (vmssName string , crt cacheReadType ) (* compute.VirtualMachineScaleSet , error ) {
95
+ getter := func (vmssName string ) (* compute.VirtualMachineScaleSet , error ) {
96
+ cached , err := ss .vmssCache .Get (vmssKey , crt )
97
+ if err != nil {
98
+ return nil , err
99
+ }
100
+
101
+ vmsses := cached .(* sync.Map )
102
+ if vmss , ok := vmsses .Load (vmssName ); ok {
103
+ result := vmss .(* vmssEntry )
104
+ return result .vmss , nil
105
+ }
106
+
107
+ return nil , nil
108
+ }
109
+
110
+ vmss , err := getter (vmssName )
111
+ if err != nil {
112
+ return nil , err
113
+ }
114
+ if vmss != nil {
115
+ return vmss , nil
116
+ }
117
+
118
+ klog .V (3 ).Infof ("Couldn't find VMSS with name %s, refreshing the cache" , vmssName )
119
+ ss .vmssCache .Delete (vmssKey )
120
+ vmss , err = getter (vmssName )
121
+ if err != nil {
122
+ return nil , err
123
+ }
124
+
125
+ if vmss == nil {
126
+ return nil , cloudprovider .InstanceNotFound
127
+ }
128
+ return vmss , nil
129
+ }
130
+
88
131
// getVmssVM gets virtualMachineScaleSetVM by nodeName from cache.
89
132
// It returns cloudprovider.InstanceNotFound if node does not belong to any scale sets.
90
133
func (ss * scaleSet ) getVmssVM (nodeName string , crt cacheReadType ) (string , string , * compute.VirtualMachineScaleSetVM , error ) {
@@ -903,7 +946,7 @@ func (ss *scaleSet) ensureVMSSInPool(service *v1.Service, nodes []*v1.Node, back
903
946
}
904
947
905
948
for vmssName := range vmssNamesMap {
906
- vmss , err := ss .GetScaleSetWithRetry ( service , ss . ResourceGroup , vmssName )
949
+ vmss , err := ss .getVMSS ( vmssName , cacheReadTypeDefault )
907
950
if err != nil {
908
951
return err
909
952
}
@@ -1208,7 +1251,7 @@ func (ss *scaleSet) ensureBackendPoolDeletedFromVMSS(service *v1.Service, backen
1208
1251
}
1209
1252
1210
1253
for vmssName := range vmssNamesMap {
1211
- vmss , err := ss .GetScaleSetWithRetry ( service , ss . ResourceGroup , vmssName )
1254
+ vmss , err := ss .getVMSS ( vmssName , cacheReadTypeDefault )
1212
1255
1213
1256
// When vmss is being deleted, CreateOrUpdate API would report "the vmss is being deleted" error.
1214
1257
// Since it is being deleted, we shouldn't send more CreateOrUpdate requests for it.
0 commit comments