Skip to content

Commit a5e2b34

Browse files
committed
fix tests
1 parent b8e906b commit a5e2b34

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

cns/restserver/internalapi_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func TestSyncHostNCVersionErrorMissingNC(t *testing.T) {
446446
}
447447

448448
// Check that the error message contains the expected text
449-
expectedErrorText := "unable to update some NCs"
449+
expectedErrorText := "Have outdated NCs"
450450
if !strings.Contains(err.Error(), expectedErrorText) {
451451
t.Errorf("Expected error to contain '%s', but got: %v", expectedErrorText, err)
452452
}
@@ -607,7 +607,7 @@ func TestSyncHostNCVersionIMDSAPIVersionNotSupported(t *testing.T) {
607607
}
608608

609609
// Verify the error is about being unable to update NCs
610-
expectedErrorText := "unable to update some NCs"
610+
expectedErrorText := "Have outdated NCs"
611611
if !strings.Contains(err.Error(), expectedErrorText) {
612612
t.Errorf("Expected error to contain '%s', but got: %v", expectedErrorText, err)
613613
}

cns/restserver/nodesubnet.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func (service *HTTPRestService) UpdateIPsForNodeSubnet(secondaryIPs []netip.Addr
3131

3232
// saved NC successfully. UpdateIPsForNodeSubnet is called only when IPs are fetched from NMAgent.
3333
// We now have IPs to serve IPAM requests. Generate conflist to indicate CNS is ready
34-
service.MustGenerateCNIConflistOnce()
34+
service.ncSynced = make(chan struct{}) // in case this is called multiple times
35+
service.mustGenerateCNIConflistOnce()
3536
return nil
3637
}
3738

cns/restserver/synchostnc.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (service *HTTPRestService) SyncHostNCVersion(ctx context.Context, channelMo
5050
if programmedNCCount > 0 {
5151
// This will only be done once per lifetime of the CNS process. This function is threadsafe and will panic
5252
// if it fails, so it is safe to call in a non-preemptable goroutine.
53-
go service.MustGenerateCNIConflistOnce()
53+
go service.mustGenerateCNIConflistOnce()
5454
} else {
5555
logger.Printf("No NCs programmed on this host yet, skipping CNI conflist generation")
5656
}
@@ -185,9 +185,11 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
185185

186186
// MustGenerateCNIConflistOnce will generate the CNI conflist once if the service was initialized with
187187
// a conflist generator. If not, this is a no-op.
188-
func (service *HTTPRestService) MustGenerateCNIConflistOnce() {
188+
func (service *HTTPRestService) mustGenerateCNIConflistOnce() {
189189
service.generateCNIConflistOnce.Do(func() {
190-
close(service.ncSynced)
190+
if service.ncSynced != nil {
191+
close(service.ncSynced)
192+
}
191193
if err := service.cniConflistGenerator.Generate(); err != nil {
192194
panic("unable to generate cni conflist with error: " + err.Error())
193195
}

0 commit comments

Comments
 (0)