@@ -58,7 +58,8 @@ func (n *networkContainerSyncState) Wait(ctx context.Context) {
5858 }
5959}
6060
61- // StartSyncHostNCVersionLoop loops until NCs are programmed and conflist is written The node subnet equivalent isStartNodeSubnet
61+ // StartSyncHostNCVersionLoop loops until checking htat NCS are programmed annd also notifis when at least one has been programmed
62+ // so we can write conflist and mark cns ready.
6263func (service * HTTPRestService ) StartSyncHostNCVersionLoop (ctx context.Context , cnsconfig configuration.CNSConfig ) error {
6364 if err := service .ncSyncState .Start (); err != nil {
6465 return err
@@ -70,18 +71,14 @@ func (service *HTTPRestService) StartSyncHostNCVersionLoop(ctx context.Context,
7071 ticker := time .NewTicker (time .Duration (cnsconfig .SyncHostNCVersionIntervalMs ) * time .Millisecond )
7172 timeout := time .Duration (cnsconfig .SyncHostNCVersionIntervalMs ) * time .Millisecond
7273 for {
73- timedCtx , cancel := context .WithTimeout (ctx , timeout )
74- if service .syncHostNCVersionWrapper (timedCtx , cnsconfig .ChannelMode ) {
74+ if service .syncHostNCVersionWrapper (ctx , cnsconfig .ChannelMode , timeout ) {
7575 one .Do (service .ncSyncState .NotifyReady )
7676 }
77- cancel ()
7877 select {
7978 case <- ticker .C :
80- timedCtx , cancel := context .WithTimeout (ctx , timeout )
81- if service .syncHostNCVersionWrapper (timedCtx , cnsconfig .ChannelMode ) {
79+ if service .syncHostNCVersionWrapper (ctx , cnsconfig .ChannelMode , timeout ) {
8280 one .Do (service .ncSyncState .NotifyReady )
8381 }
84- cancel ()
8582 case <- ctx .Done ():
8683 logger .Printf ("Stopping SyncHostNCVersion loop." )
8784 return
@@ -91,15 +88,15 @@ func (service *HTTPRestService) StartSyncHostNCVersionLoop(ctx context.Context,
9188 return nil
9289}
9390
94- // TODO: lowercase/unexport this function drive everything through StartSyncHostNCVersionLoop?
95- // SyncHostNCVersion will check NC version from NMAgent and save it as host NC version in container status.
96- // If NMAgent NC version got updated, CNS will refresh the pending programming IP status.
97- // returns true if soemthing was progammeed
98- func ( service * HTTPRestService ) syncHostNCVersionWrapper ( ctx context. Context , channelMode string ) bool {
91+ // syncHostNCVersionWrapper bascially calls syncHostNCVersion but wraps it with locks a timeout and logges erros (but doesn't fail).
92+ // Mostly exists so StartSyncHostNCVersionLoop doesn't have to repeat itself to be a do/while loop
93+ func ( service * HTTPRestService ) syncHostNCVersionWrapper ( ctx context. Context , channelMode string , timeout time. Duration ) bool {
94+ timedCtx , cancel := context . WithTimeout ( ctx , timeout )
95+ defer cancel ()
9996 service .Lock ()
10097 defer service .Unlock ()
10198 start := time .Now ()
102- programmedNCCount , err := service .syncHostNCVersion (ctx , channelMode )
99+ programmedNCCount , err := service .syncHostNCVersion (timedCtx , channelMode )
103100 if err != nil {
104101 logger .Errorf ("sync host error %v" , err )
105102 }
0 commit comments