@@ -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
351349func (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 }
0 commit comments