88
99 "github.com/Azure/azure-container-networking/cns"
1010 "github.com/Azure/azure-container-networking/cns/logger"
11- "github.com/Azure/azure-container-networking/cns/requestcontroller "
11+ "github.com/Azure/azure-container-networking/cns/singletenantcontroller "
1212 nnc "github.com/Azure/azure-container-networking/nodenetworkconfig/api/v1alpha"
1313)
1414
@@ -17,21 +17,18 @@ const (
1717)
1818
1919type CNSIPAMPoolMonitor struct {
20- pendingRelease bool
21-
20+ MaximumFreeIps int64
21+ MinimumFreeIps int64
2222 cachedNNC nnc.NodeNetworkConfig
23- updatingIpsNotInUseCount int
23+ httpService cns.HTTPService
24+ mu sync.RWMutex
25+ pendingRelease bool
26+ rc singletenantcontroller.RequestController
2427 scalarUnits nnc.Scaler
25-
26- httpService cns.HTTPService
27- rc requestcontroller.RequestController
28- MinimumFreeIps int64
29- MaximumFreeIps int64
30-
31- mu sync.RWMutex
28+ updatingIpsNotInUseCount int
3229}
3330
34- func NewCNSIPAMPoolMonitor (httpService cns.HTTPService , rc requestcontroller .RequestController ) * CNSIPAMPoolMonitor {
31+ func NewCNSIPAMPoolMonitor (httpService cns.HTTPService , rc singletenantcontroller .RequestController ) * CNSIPAMPoolMonitor {
3532 logger .Printf ("NewCNSIPAMPoolMonitor: Create IPAM Pool Monitor" )
3633 return & CNSIPAMPoolMonitor {
3734 pendingRelease : false ,
@@ -40,16 +37,6 @@ func NewCNSIPAMPoolMonitor(httpService cns.HTTPService, rc requestcontroller.Req
4037 }
4138}
4239
43- func stopReconcile (ch <- chan struct {}) bool {
44- select {
45- case <- ch :
46- return true
47- default :
48- }
49-
50- return false
51- }
52-
5340func (pm * CNSIPAMPoolMonitor ) Start (ctx context.Context , poolMonitorRefreshMilliseconds int ) error {
5441 logger .Printf ("[ipam-pool-monitor] Starting CNS IPAM Pool Monitor" )
5542
@@ -60,15 +47,15 @@ func (pm *CNSIPAMPoolMonitor) Start(ctx context.Context, poolMonitorRefreshMilli
6047 case <- ctx .Done ():
6148 return fmt .Errorf ("[ipam-pool-monitor] CNS IPAM Pool Monitor received cancellation signal" )
6249 case <- ticker .C :
63- err := pm .Reconcile ()
50+ err := pm .Reconcile (ctx )
6451 if err != nil {
6552 logger .Printf ("[ipam-pool-monitor] Reconcile failed with err %v" , err )
6653 }
6754 }
6855 }
6956}
7057
71- func (pm * CNSIPAMPoolMonitor ) Reconcile () error {
58+ func (pm * CNSIPAMPoolMonitor ) Reconcile (ctx context. Context ) error {
7259 cnsPodIPConfigCount := len (pm .httpService .GetPodIPConfigState ())
7360 pendingProgramCount := len (pm .httpService .GetPendingProgramIPConfigs ()) // TODO: add pending program count to real cns
7461 allocatedPodIPCount := len (pm .httpService .GetAllocatedIPConfigs ())
@@ -90,18 +77,18 @@ func (pm *CNSIPAMPoolMonitor) Reconcile() error {
9077 }
9178
9279 logger .Printf ("[ipam-pool-monitor] Increasing pool size...%s " , msg )
93- return pm .increasePoolSize ()
80+ return pm .increasePoolSize (ctx )
9481
9582 // pod count is decreasing
9683 case freeIPConfigCount > pm .MaximumFreeIps :
9784 logger .Printf ("[ipam-pool-monitor] Decreasing pool size...%s " , msg )
98- return pm .decreasePoolSize (pendingReleaseIPCount )
85+ return pm .decreasePoolSize (ctx , pendingReleaseIPCount )
9986
10087 // CRD has reconciled CNS state, and target spec is now the same size as the state
10188 // free to remove the IP's from the CRD
10289 case pm .pendingRelease && int (pm .cachedNNC .Spec .RequestedIPCount ) == cnsPodIPConfigCount :
10390 logger .Printf ("[ipam-pool-monitor] Removing Pending Release IP's from CRD...%s " , msg )
104- return pm .cleanPendingRelease ()
91+ return pm .cleanPendingRelease (ctx )
10592
10693 // no pods scheduled
10794 case allocatedPodIPCount == 0 :
@@ -112,7 +99,7 @@ func (pm *CNSIPAMPoolMonitor) Reconcile() error {
11299 return nil
113100}
114101
115- func (pm * CNSIPAMPoolMonitor ) increasePoolSize () error {
102+ func (pm * CNSIPAMPoolMonitor ) increasePoolSize (ctx context. Context ) error {
116103 defer pm .mu .Unlock ()
117104 pm .mu .Lock ()
118105
@@ -143,7 +130,7 @@ func (pm *CNSIPAMPoolMonitor) increasePoolSize() error {
143130
144131 logger .Printf ("[ipam-pool-monitor] Increasing pool size, Current Pool Size: %v, Updated Requested IP Count: %v, Pods with IP's:%v, ToBeDeleted Count: %v" , len (pm .httpService .GetPodIPConfigState ()), tempNNCSpec .RequestedIPCount , len (pm .httpService .GetAllocatedIPConfigs ()), len (tempNNCSpec .IPsNotInUse ))
145132
146- err = pm .rc .UpdateCRDSpec (context . Background () , tempNNCSpec )
133+ err = pm .rc .UpdateCRDSpec (ctx , tempNNCSpec )
147134 if err != nil {
148135 // caller will retry to update the CRD again
149136 return err
@@ -155,7 +142,7 @@ func (pm *CNSIPAMPoolMonitor) increasePoolSize() error {
155142 return nil
156143}
157144
158- func (pm * CNSIPAMPoolMonitor ) decreasePoolSize (existingPendingReleaseIPCount int ) error {
145+ func (pm * CNSIPAMPoolMonitor ) decreasePoolSize (ctx context. Context , existingPendingReleaseIPCount int ) error {
159146 defer pm .mu .Unlock ()
160147 pm .mu .Lock ()
161148
@@ -215,7 +202,7 @@ func (pm *CNSIPAMPoolMonitor) decreasePoolSize(existingPendingReleaseIPCount int
215202 tempNNCSpec .RequestedIPCount -= int64 (len (pendingIpAddresses ))
216203 logger .Printf ("[ipam-pool-monitor] Decreasing pool size, Current Pool Size: %v, Requested IP Count: %v, Pods with IP's: %v, ToBeDeleted Count: %v" , len (pm .httpService .GetPodIPConfigState ()), tempNNCSpec .RequestedIPCount , len (pm .httpService .GetAllocatedIPConfigs ()), len (tempNNCSpec .IPsNotInUse ))
217204
218- err = pm .rc .UpdateCRDSpec (context . Background () , tempNNCSpec )
205+ err = pm .rc .UpdateCRDSpec (ctx , tempNNCSpec )
219206 if err != nil {
220207 // caller will retry to update the CRD again
221208 return err
@@ -236,7 +223,7 @@ func (pm *CNSIPAMPoolMonitor) decreasePoolSize(existingPendingReleaseIPCount int
236223
237224// if cns pending ip release map is empty, request controller has already reconciled the CNS state,
238225// so we can remove it from our cache and remove the IP's from the CRD
239- func (pm * CNSIPAMPoolMonitor ) cleanPendingRelease () error {
226+ func (pm * CNSIPAMPoolMonitor ) cleanPendingRelease (ctx context. Context ) error {
240227 defer pm .mu .Unlock ()
241228 pm .mu .Lock ()
242229
@@ -247,7 +234,7 @@ func (pm *CNSIPAMPoolMonitor) cleanPendingRelease() error {
247234 return err
248235 }
249236
250- err = pm .rc .UpdateCRDSpec (context . Background () , tempNNCSpec )
237+ err = pm .rc .UpdateCRDSpec (ctx , tempNNCSpec )
251238 if err != nil {
252239 // caller will retry to update the CRD again
253240 return err
0 commit comments