Skip to content

Commit b1b941e

Browse files
committed
removed npm lite check
1 parent b6e07fb commit b1b941e

File tree

3 files changed

+72
-60
lines changed

3 files changed

+72
-60
lines changed

npm/pkg/dataplane/dataplane.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ type DataPlane struct {
6565
nodeName string
6666
// endpointCache stores all endpoints of the network (including off-node)
6767
// Key is PodIP
68-
endpointCache *endpointCache
69-
ioShim *common.IOShim
70-
updatePodCache *updatePodCache
71-
endpointQuery *endpointQuery
72-
endpointQueryL1VH *endpointQuery // windows -> filter for state 2 (attached) endpoints in l1vh
73-
applyInfo *applyInfo
74-
netPolQueue *netPolQueue
68+
endpointCache *endpointCache
69+
ioShim *common.IOShim
70+
updatePodCache *updatePodCache
71+
endpointQuery *endpointQuery
72+
endpointQueryAttachedState *endpointQuery // windows -> filter for state 2 (attached) endpoints in l1vh
73+
applyInfo *applyInfo
74+
netPolQueue *netPolQueue
7575
// removePolicyInfo tracks when a policy was removed yet had ApplyIPSet failures.
7676
// This field is only relevant for Linux.
7777
removePolicyInfo removePolicyInfo
@@ -90,12 +90,12 @@ func NewDataPlane(nodeName string, ioShim *common.IOShim, cfg *Config, stopChann
9090
policyMgr: policies.NewPolicyManager(ioShim, cfg.PolicyManagerCfg),
9191
ipsetMgr: ipsets.NewIPSetManager(cfg.IPSetManagerCfg, ioShim),
9292
// networkID is set when initializing Windows dataplane
93-
networkID: "",
94-
endpointCache: newEndpointCache(),
95-
nodeName: nodeName,
96-
ioShim: ioShim,
97-
endpointQuery: new(endpointQuery),
98-
endpointQueryL1VH: new(endpointQuery),
93+
networkID: "",
94+
endpointCache: newEndpointCache(),
95+
nodeName: nodeName,
96+
ioShim: ioShim,
97+
endpointQuery: new(endpointQuery),
98+
endpointQueryAttachedState: new(endpointQuery),
9999
applyInfo: &applyInfo{
100100
inBootupPhase: true,
101101
},

npm/pkg/dataplane/dataplane_windows.go

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (dp *DataPlane) initializeDataPlane() error {
5151
Flags: hcn.HostComputeQueryFlagsNone,
5252
}
5353
// Initialize Endpoint query used to filter healthy endpoints (vNIC) of Windows pods on L1VH Node
54-
dp.endpointQueryL1VH.query = hcn.HostComputeQuery{
54+
dp.endpointQueryAttachedState.query = hcn.HostComputeQuery{
5555
SchemaVersion: hcn.SchemaVersion{
5656
Major: hcnSchemaMajorVersion,
5757
Minor: hcnSchemaMinorVersion,
@@ -69,15 +69,13 @@ func (dp *DataPlane) initializeDataPlane() error {
6969
klog.Infof("Attached Sharing State filter- %+v", string(filter))
7070

7171
// Filter out any endpoints that are not in "Attached" State. All running Windows L1VH pods with networking must be in this state.
72-
if dp.EnableNPMLite {
73-
filterMapL1VH := map[string]uint16{"State": hcnEndpointStateAttached}
74-
filterL1VH, err := json.Marshal(filterMapL1VH)
75-
if err != nil {
76-
return errors.Wrap(err, "failed to marshal endpoint filter map for attched state on L1VH Node")
77-
}
78-
dp.endpointQueryL1VH.query.Filter = string(filterL1VH)
79-
klog.Infof("AttachedState filter- %+v", string(filterL1VH))
72+
filterMapAttached := map[string]uint16{"State": hcnEndpointStateAttached}
73+
filterAttached, err := json.Marshal(filterMapAttached)
74+
if err != nil {
75+
return errors.Wrap(err, "failed to marshal endpoint filter map for attched state on L1VH Node")
8076
}
77+
dp.endpointQueryAttachedState.query.Filter = string(filterAttached)
78+
klog.Infof("AttachedState filter- %+v", string(filterAttached))
8179

8280
// reset endpoint cache so that netpol references are removed for all endpoints while refreshing pod endpoints
8381
// no need to lock endpointCache at boot up
@@ -351,67 +349,69 @@ func (dp *DataPlane) getEndpointsToApplyPolicies(netPols []*policies.NPMNetworkP
351349
func (dp *DataPlane) getLocalPodEndpoints() ([]*hcn.HostComputeEndpoint, error) {
352350
klog.Info("getting local endpoints")
353351
klog.Infof("npm lite is enabled: %+v", dp.EnableNPMLite) // Will remove after debugging
352+
353+
// Gets endpoints in state: Attached
354354
timer := metrics.StartNewTimer()
355+
endpointsAttached, err := dp.ioShim.Hns.ListEndpointsQuery(dp.endpointQueryAttachedState.query)
356+
klog.Infof("Attached: There are %+v endpoints with state: attached", len(endpointsAttached)) // Will remove after debugging
357+
for _, endpoint := range endpointsAttached {
358+
klog.Infof("ID: %s, Name: %+v", endpoint.Id, endpoint.Name)
359+
}
360+
metrics.RecordListEndpointsLatency(timer)
361+
if err != nil {
362+
metrics.IncListEndpointsFailures()
363+
return nil, errors.Wrap(err, "failed to get local pod endpoints in state:attached")
364+
}
365+
366+
// Gets endpoints in state: AttachedSharing
367+
timer = metrics.StartNewTimer()
355368
endpoints, err := dp.ioShim.Hns.ListEndpointsQuery(dp.endpointQuery.query)
356369
for _, endpoint1 := range endpoints {
357370
klog.Infof(" AttachedSharing: ID: %s, Name: %+v", endpoint1.Id, endpoint1.Name)
358-
} // Debugging
371+
}
359372
klog.Infof("There are %+v endpoints with state: attached sharing", len(endpoints)) // Will remove after debugging
360373
metrics.RecordListEndpointsLatency(timer)
361374
if err != nil {
362375
metrics.IncListEndpointsFailures()
363-
return nil, errors.Wrap(err, "failed to get local pod endpoints")
376+
return nil, errors.Wrap(err, "failed to get local pod endpoints in state: attachedSharing")
364377
}
365-
366-
if dp.EnableNPMLite {
367-
timer = metrics.StartNewTimer()
368-
endpointsAttached, err := dp.ioShim.Hns.ListEndpointsQuery(dp.endpointQueryL1VH.query)
369-
klog.Infof("Attached: There are %+v endpoints with state: attached", len(endpointsAttached)) // Will remove after debugging
370-
for _, endpoint := range endpointsAttached {
371-
klog.Infof("ID: %s, Name: %+v", endpoint.Id, endpoint.Name)
372-
} // Debugging
373-
metrics.RecordListEndpointsLatency(timer)
374-
if err != nil {
375-
metrics.IncListEndpointsFailures()
376-
return nil, errors.Wrap(err, "failed to get local pod endpoints in L1VH")
377-
}
378-
// TODO -> Check if endpoints and endpointsAttached have any same endpoint and if so filter those out
379-
endpoints = removeCommonEndpoints(endpoints, endpointsAttached)
380-
for _, endpoint := range endpoints {
381-
klog.Infof("combined enpoints ID: %s, Name: %+v", endpoint.Id, endpoint.Name)
382-
}
378+
// Filtering out any of the same endpoints between endpoints with state attached and attachedSharing
379+
endpoints = removeCommonEndpoints(&endpoints, &endpointsAttached)
380+
for _, endpoint := range endpoints {
381+
klog.Infof("combined enpoints ID: %s, Name: %+v", endpoint.Id, endpoint.Name)
383382
}
383+
384384
epPointers := make([]*hcn.HostComputeEndpoint, 0, len(endpoints))
385385
for k := range endpoints {
386386
epPointers = append(epPointers, &endpoints[k])
387387
}
388388
return epPointers, nil
389389
}
390390

391-
func removeCommonEndpoints(endpoints, endpointsAttached []hcn.HostComputeEndpoint) []hcn.HostComputeEndpoint {
392-
smaller, larger := endpoints, endpointsAttached
393-
if len(endpoints) > len(endpointsAttached) {
394-
smaller, larger = endpointsAttached, endpoints
391+
func removeCommonEndpoints(endpoints, endpointsAttached *[]hcn.HostComputeEndpoint) []hcn.HostComputeEndpoint {
392+
smallerEndpointsList, largerEndpointsList := endpoints, endpointsAttached
393+
if len(*endpoints) > len(*endpointsAttached) {
394+
smallerEndpointsList, largerEndpointsList = endpointsAttached, endpoints
395395
}
396396

397-
// Use a map to track the IDs in the smaller array
398-
idMap := make(map[string]struct{}, len(smaller))
399-
for _, ep := range smaller {
397+
// add endpoints from smaller array into a map
398+
idMap := make(map[string]struct{}, len(*smallerEndpointsList))
399+
for i := 0; i < len(*smallerEndpointsList); i++ {
400+
ep := &(*smallerEndpointsList)[i]
400401
idMap[ep.Id] = struct{}{}
401402
}
402403

403-
// Collect unique elements from both arrays
404+
// checking for common endpoints among two endpoint arrays
404405
var result []hcn.HostComputeEndpoint
405-
for _, ep := range larger {
406-
if _, found := idMap[ep.Id]; !found {
407-
result = append(result, ep) // Unique to larger array
408-
} else {
409-
delete(idMap, ep.Id) // Remove common element from map
410-
}
406+
for i := 0; i < len(*largerEndpointsList); i++ {
407+
ep := (*largerEndpointsList)[i]
408+
result = append(result, ep)
409+
delete(idMap, ep.Id)
411410
}
412411

413-
// Append remaining unique elements from the smaller array
414-
for _, ep := range smaller {
412+
// Appending remaining unique elements from the smaller endpoint array
413+
for i := 0; i < len(*smallerEndpointsList); i++ {
414+
ep := (*smallerEndpointsList)[i]
415415
if _, found := idMap[ep.Id]; found {
416416
result = append(result, ep)
417417
}

npm/pkg/dataplane/dataplane_windows_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,32 @@ func TestRemoveCommonEndpoints(t *testing.T) {
9999
name: "1 value same",
100100
endpoints: []hcn.HostComputeEndpoint{{Id: "456901"}, {Id: "123456"}, {Id: "560971"}},
101101
endpointsAttached: []hcn.HostComputeEndpoint{{Id: "567890"}, {Id: "123456"}, {Id: "789012"}},
102-
expected: []hcn.HostComputeEndpoint{{Id: "567890"}, {Id: "789012"}, {Id: "456901"}, {Id: "560971"}},
102+
expected: []hcn.HostComputeEndpoint{{Id: "567890"}, {Id: "123456"}, {Id: "789012"}, {Id: "456901"}, {Id: "560971"}},
103103
},
104104
{
105105
name: "no values same",
106106
endpoints: []hcn.HostComputeEndpoint{{Id: "456901"}, {Id: "560971"}},
107107
endpointsAttached: []hcn.HostComputeEndpoint{{Id: "567890"}, {Id: "789012"}},
108108
expected: []hcn.HostComputeEndpoint{{Id: "567890"}, {Id: "789012"}, {Id: "456901"}, {Id: "560971"}},
109109
},
110+
{
111+
name: "1 value same",
112+
endpoints: []hcn.HostComputeEndpoint{{Id: "456901"}, {Id: "123456"}, {Id: "560971"}},
113+
endpointsAttached: []hcn.HostComputeEndpoint{{Id: "567890"}, {Id: "123456"}, {Id: "789012"}},
114+
expected: []hcn.HostComputeEndpoint{{Id: "567890"}, {Id: "123456"}, {Id: "789012"}, {Id: "456901"}, {Id: "560971"}},
115+
},
116+
{
117+
name: "two values same",
118+
endpoints: []hcn.HostComputeEndpoint{{Id: "456901"}, {Id: "560971"}, {Id: "123456"}, {Id: "789012"}},
119+
endpointsAttached: []hcn.HostComputeEndpoint{{Id: "567890"}, {Id: "789012"}, {Id: "123456"}},
120+
expected: []hcn.HostComputeEndpoint{{Id: "456901"}, {Id: "560971"}, {Id: "123456"}, {Id: "789012"}, {Id: "567890"}},
121+
},
110122
}
111123
for _, tt := range tests {
112124
tt := tt
113125

114126
t.Run(tt.name, func(t *testing.T) {
115-
result := removeCommonEndpoints(tt.endpoints, tt.endpointsAttached)
127+
result := removeCommonEndpoints(&tt.endpoints, &tt.endpointsAttached)
116128
// Use reflect.DeepEqual as a backup if require.Equal doesn't work as expected
117129
if !reflect.DeepEqual(tt.expected, result) {
118130
t.Errorf("Test %s failed: expected %v, got %v", tt.name, tt.expected, result)

0 commit comments

Comments
 (0)