Skip to content

Commit c9ba36b

Browse files
committed
simpler name
1 parent 2f8eabf commit c9ba36b

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

cns/restserver/nodesubnet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (service *HTTPRestService) UpdateIPsForNodeSubnet(secondaryIPs []netip.Addr
2929

3030
logger.Debugf("IP change processed successfully")
3131

32-
service.ncSyncState.NotifyReady()
32+
service.ncWait.Done()
3333
return nil
3434
}
3535

@@ -58,7 +58,7 @@ func (service *HTTPRestService) InitializeNodeSubnet(ctx context.Context, podInf
5858
// StartNodeSubnet starts the IP fetcher for NodeSubnet. This will cause secondary IPs to be fetched periodically.
5959
// After the first successful fetch, conflist will be generated to indicate CNS is ready.
6060
func (service *HTTPRestService) StartNodeSubnet(ctx context.Context) error {
61-
if err := service.ncSyncState.Start(); err != nil {
61+
if err := service.ncWait.Start(); err != nil {
6262
return err
6363
}
6464
service.nodesubnetIPFetcher.Start(ctx)

cns/restserver/restserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type HTTPRestService struct {
101101
PnpIDByMacAddress map[string]string
102102
imdsClient imdsClient
103103
nodesubnetIPFetcher *nodesubnet.IPFetcher
104-
ncSyncState networkContainerSyncState
104+
ncWait ncWait
105105
}
106106

107107
type CNIConflistGenerator interface {
@@ -388,7 +388,7 @@ func (service *HTTPRestService) AttachIPConfigsHandlerMiddleware(middleware cns.
388388

389389
// Wait waits for nc sync state then writes out the conflist.
390390
func (service *HTTPRestService) Wait(ctx context.Context) {
391-
service.ncSyncState.Wait(ctx)
391+
service.ncWait.Wait(ctx)
392392
if ctx.Err() != nil {
393393
logger.Printf("Context done before writing out conflist: %v", ctx.Err())
394394
return

cns/restserver/synchostnc.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@ import (
1919

2020
// TODO: make this file a sub pacakge?
2121

22-
// NetworkContainerSyncState manages waiting on conflist to ge
22+
// ncWait manages making sure ncstate or nodesubnet state is ready before conflist writing
2323
// Basically a wait group that can only be added once and waits with a context
2424
// meant to be used uninitialized and then started once the sync loop begins.
25-
type networkContainerSyncState struct {
25+
type ncWait struct {
2626
wg sync.WaitGroup
2727
started atomic.Bool
2828
}
2929

30-
// Start is like add except it only allows being called once.
31-
func (n *networkContainerSyncState) Start() error {
30+
// Start is like Add except it only allows being called once.
31+
func (n *ncWait) Start() error {
3232
if !n.started.CompareAndSwap(false, true) {
3333
return errors.New("sync loop already started")
3434
}
3535
n.wg.Add(1)
3636
return nil
3737
}
3838

39-
// NotifyReady is like Done but will ignore if Start was never called.
40-
func (n *networkContainerSyncState) NotifyReady() {
39+
// Done is like waitgroup Done but will ignore if Start was never called.
40+
func (n *ncWait) Done() {
4141
if !n.started.Load() {
4242
return //nobody ever set this up just move on.
4343
}
4444
n.wg.Done()
4545
}
4646

4747
// Wait waits for the CNI conflist to be ready or for the context to be done.
48-
func (n *networkContainerSyncState) Wait(ctx context.Context) {
48+
func (n *ncWait) Wait(ctx context.Context) {
4949
done := make(chan struct{})
5050
go func() {
5151
n.wg.Wait() //still fine to wait even if never started will just return immediately
@@ -61,7 +61,7 @@ func (n *networkContainerSyncState) Wait(ctx context.Context) {
6161
// StartSyncHostNCVersionLoop loops until checking htat NCS are programmed annd also notifis when at least one has been programmed
6262
// so we can write conflist and mark cns ready.
6363
func (service *HTTPRestService) StartSyncHostNCVersionLoop(ctx context.Context, cnsconfig configuration.CNSConfig) error {
64-
if err := service.ncSyncState.Start(); err != nil {
64+
if err := service.ncWait.Start(); err != nil {
6565
return err
6666
}
6767
go func() {
@@ -72,12 +72,12 @@ func (service *HTTPRestService) StartSyncHostNCVersionLoop(ctx context.Context,
7272
timeout := time.Duration(cnsconfig.SyncHostNCVersionIntervalMs) * time.Millisecond
7373
for {
7474
if service.syncHostNCVersionWrapper(ctx, cnsconfig.ChannelMode, timeout) {
75-
one.Do(service.ncSyncState.NotifyReady)
75+
one.Do(service.ncWait.Done)
7676
}
7777
select {
7878
case <-ticker.C:
7979
if service.syncHostNCVersionWrapper(ctx, cnsconfig.ChannelMode, timeout) {
80-
one.Do(service.ncSyncState.NotifyReady)
80+
one.Do(service.ncWait.Done)
8181
}
8282
case <-ctx.Done():
8383
logger.Printf("Stopping SyncHostNCVersion loop.")

0 commit comments

Comments
 (0)