Skip to content

Commit f8f724d

Browse files
fix: address comments
1 parent 2a6881f commit f8f724d

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

cns/restserver/helper_for_nodesubnet_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/Azure/azure-container-networking/store"
1515
)
1616

17+
// GetRestServiceObjectForNodeSubnetTest creates a new HTTPRestService object for use in nodesubnet unit tests.
1718
func GetRestServiceObjectForNodeSubnetTest(t *testing.T, generator CNIConflistGenerator) *HTTPRestService {
1819
config := &common.ServiceConfig{
1920
Name: "test",

cns/restserver/nodesubnet.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (service *HTTPRestService) InitializeNodeSubnet(ctx context.Context, podInf
5656
return nil
5757
}
5858

59+
// StartNodeSubnet starts the IP fetcher for NodeSubnet. This will cause secondary IPs to be fetched periodically.
60+
// After the first successful fetch, conflist will be generated to indicate CNS is ready.
5961
func (service *HTTPRestService) StartNodeSubnet(ctx context.Context) {
6062
service.nodesubnetIPFetcher.Start(ctx)
6163
}

cns/restserver/nodesubnet_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/Azure/azure-container-networking/store"
1313
)
1414

15+
// getMockStore creates a mock KeyValueStore with some endpoint state
1516
func getMockStore() store.KeyValueStore {
1617
mockStore := store.NewMockStore("")
1718
endpointState := map[string]*restserver.EndpointInfo{
@@ -67,13 +68,15 @@ func (m *MockCNIConflistGenerator) Close() error {
6768
return nil
6869
}
6970

71+
// TestNodeSubnet tests initialization of NodeSubnet with endpoint info, and verfies that
72+
// the conflist is generated after fetching secondary IPs
7073
func TestNodeSubnet(t *testing.T) {
7174
podInfoByIPProvider, err := cnireconciler.NewCNSPodInfoProvider(getMockStore())
7275
if err != nil {
7376
t.Fatalf("NewCNSPodInfoProvider returned an error: %v", err)
7477
}
7578

76-
// Create a real HTTPRestService object
79+
// create a real HTTPRestService object
7780
mockCNIConflistGenerator := &MockCNIConflistGenerator{
7881
GenerateCalled: make(chan struct{}),
7982
}
@@ -111,6 +114,7 @@ func TestNodeSubnet(t *testing.T) {
111114
checkIPassignment(t, service, expectedIPs)
112115
}
113116

117+
// checkIPassignment checks whether the IP assignment state in the HTTPRestService object matches expectation
114118
func checkIPassignment(t *testing.T, service *restserver.HTTPRestService, expectedIPs map[string]types.IPState) {
115119
if len(service.PodIPConfigState) != len(expectedIPs) {
116120
t.Fatalf("expected 2 entries in PodIPConfigState, got %d", len(service.PodIPConfigState))

0 commit comments

Comments
 (0)