Skip to content

Commit 6e8bda0

Browse files
refactor: address comments
1 parent f94cb77 commit 6e8bda0

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

cns/restserver/helper_for_nodesubnet_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package restserver
33
import (
44
"context"
55
"net/netip"
6+
"testing"
67

78
"github.com/Azure/azure-container-networking/cns"
89
"github.com/Azure/azure-container-networking/cns/common"
@@ -13,7 +14,7 @@ import (
1314
"github.com/Azure/azure-container-networking/store"
1415
)
1516

16-
func GetRestServiceObjectForNodeSubnetTest(generator CNIConflistGenerator) *HTTPRestService {
17+
func GetRestServiceObjectForNodeSubnetTest(t *testing.T, generator CNIConflistGenerator) *HTTPRestService {
1718
config := &common.ServiceConfig{
1819
Name: "test",
1920
Version: "1.0",
@@ -56,6 +57,8 @@ func GetRestServiceObjectForNodeSubnetTest(generator CNIConflistGenerator) *HTTP
5657
return nil
5758
}
5859

60+
t.Cleanup(func() { svc.Uninitialize() })
61+
5962
return &HTTPRestService{
6063
Service: svc,
6164
cniConflistGenerator: generator,

cns/restserver/nodesubnet.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func (service *HTTPRestService) UpdateIPsForNodeSubnet(secondaryIPs []netip.Addr
2424

2525
code, msg := service.saveNetworkContainerGoalState(*networkContainerRequest)
2626
if code != types.Success {
27-
logger.Debugf("Error in processing IP change")
2827
return errors.Errorf("failed to save fetched ips. code: %d, message %s", code, msg)
2928
}
3029

cns/restserver/nodesubnet_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ func (m *MockPodInfoByIPProvider) PodInfoByIP() (res map[string]cns.PodInfo, err
1818

1919
// Mock implementation of CNIConflistGenerator
2020
type MockCNIConflistGenerator struct {
21-
GenerateCalled chan bool
21+
GenerateCalled chan struct{}
2222
}
2323

2424
func (m *MockCNIConflistGenerator) Generate() error {
25-
m.GenerateCalled <- true
25+
close(m.GenerateCalled)
2626
return nil
2727
}
2828

@@ -32,32 +32,30 @@ func (m *MockCNIConflistGenerator) Close() error {
3232
}
3333

3434
func TestNodeSubnet(t *testing.T) {
35-
mockPodInfoProvider := new(MockPodInfoByIPProvider)
35+
mockPodInfoProvider := &MockPodInfoByIPProvider{}
3636

3737
// Create a real HTTPRestService object
3838
mockCNIConflistGenerator := &MockCNIConflistGenerator{
39-
GenerateCalled: make(chan bool),
39+
GenerateCalled: make(chan struct{}),
4040
}
41-
service := restserver.GetRestServiceObjectForNodeSubnetTest(mockCNIConflistGenerator)
42-
defer service.Service.Uninitialize()
43-
41+
service := restserver.GetRestServiceObjectForNodeSubnetTest(t, mockCNIConflistGenerator)
4442
ctx, cancel := testContext(t)
4543
defer cancel()
4644

4745
err := service.InitializeNodeSubnet(ctx, mockPodInfoProvider)
4846
service.StartNodeSubnet(ctx)
4947

50-
if err != nil {
51-
t.Errorf("InitializeNodeSubnet returned an error: %v", err)
52-
}
53-
5448
if service.GetNodesubnetIPFetcher() == nil {
5549
t.Error("NodeSubnetIPFetcher is not initialized")
5650
}
5751

52+
if err != nil {
53+
t.Fatalf("InitializeNodeSubnet returned an error: %v", err)
54+
}
55+
5856
select {
5957
case <-ctx.Done():
60-
t.Error("Test context was canceled before conflist generation")
58+
t.Errorf("test context done - %s", ctx.Err())
6159
return
6260
case <-mockCNIConflistGenerator.GenerateCalled:
6361
break

cns/service/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,10 @@ func main() {
872872
}
873873
}
874874

875+
// AzureHost channelmode indeicates Nodesubnet. IPs are to be fetched from NMagent.
875876
if config.ChannelMode == cns.AzureHost {
876877
if !cnsconfig.ManageEndpointState {
877-
logger.Errorf("[Azure CNS] ManageEndpointState must be set to true for AzureHost mode")
878+
logger.Errorf("ManageEndpointState must be set to true for AzureHost mode")
878879
return
879880
}
880881

hack/aks/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ AKS Clusters
2424
byocni-up Alias to swift-byocni-up
2525
cilium-up Alias to swift-cilium-up
2626
up Alias to swift-up
27+
nodesubnet-byocni-nokubeproxy-up Bring up a Nodesubnet BYO CNI cluster. Does not include secondary IP configs.
2728
overlay-byocni-up Bring up a Overlay BYO CNI cluster
2829
overlay-byocni-nokubeproxy-up Bring up a Overlay BYO CNI cluster without kube-proxy
2930
overlay-cilium-up Bring up a Overlay Cilium cluster

0 commit comments

Comments
 (0)