Skip to content

Commit dcb45f8

Browse files
committed
node subnet needs to handle this too
1 parent 6c3c9f5 commit dcb45f8

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

cns/restserver/helper_for_nodesubnet_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ func GetRestServiceObjectForNodeSubnetTest(t *testing.T, generator CNIConflistGe
7979
return interfaces, nil
8080
},
8181
},
82-
wscli: &fakes.WireserverClientFake{},
82+
wscli: &fakes.WireserverClientFake{},
83+
ncSynced: make(chan struct{}),
8384
}
8485
}
8586

cns/restserver/nodesubnet.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func (service *HTTPRestService) InitializeNodeSubnet(ctx context.Context, podInf
5858

5959
// StartNodeSubnet starts the IP fetcher for NodeSubnet. This will cause secondary IPs to be fetched periodically.
6060
// After the first successful fetch, conflist will be generated to indicate CNS is ready.
61-
func (service *HTTPRestService) StartNodeSubnet(ctx context.Context) {
61+
func (service *HTTPRestService) StartNodeSubnet(ctx context.Context) error {
62+
if !service.ncSyncLoop.CompareAndSwap(false, true) {
63+
return errors.New("SyncHostNCVersion loop already started")
64+
}
6265
service.nodesubnetIPFetcher.Start(ctx)
66+
return nil
6367
}

cns/restserver/nodesubnet_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ func TestNodeSubnet(t *testing.T) {
9696

9797
checkIPassignment(t, service, expectedIPs)
9898

99-
service.StartNodeSubnet(ctx)
99+
if err := service.StartNodeSubnet(ctx); err != nil {
100+
t.Fatalf("StartNodeSubnet returned an error: %v", err)
101+
}
100102

101103
if service.GetNodesubnetIPFetcher() == nil {
102104
t.Fatal("NodeSubnetIPFetcher is not initialized")

cns/service/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,10 @@ func main() {
11151115
// at this point, rest service is running. We can now start serving new requests. So call StartNodeSubnet, which
11161116
// will fetch secondary IPs and generate conflist. Do not move this all before rest service start - this will cause
11171117
// CNI to start sending requests, and if the service doesn't start successfully, the requests will fail.
1118-
httpRemoteRestService.StartNodeSubnet(rootCtx)
1118+
if err := httpRemoteRestService.StartNodeSubnet(rootCtx); err != nil {
1119+
logger.Errorf("Failed to start NodeSubnet: %v", err)
1120+
return
1121+
}
11191122
}
11201123

11211124
// Wait for NC sync to complete before marking service as ready.

0 commit comments

Comments
 (0)