Skip to content

Commit ae849be

Browse files
committed
Added logic to make 2 hns calls for 2 different endpoint states
1 parent 2836a9d commit ae849be

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

npm/pkg/dataplane/dataplane.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ type DataPlane struct {
6464
nodeName string
6565
// endpointCache stores all endpoints of the network (including off-node)
6666
// Key is PodIP
67-
endpointCache *endpointCache
68-
ioShim *common.IOShim
69-
updatePodCache *updatePodCache
70-
endpointQuery *endpointQuery
71-
applyInfo *applyInfo
72-
netPolQueue *netPolQueue
67+
endpointCache *endpointCache
68+
ioShim *common.IOShim
69+
updatePodCache *updatePodCache
70+
endpointQuery *endpointQuery
71+
endpointQueryL1VH *endpointQuery //windows -> filter for state 2 (attached) endpoints in l1vh
72+
applyInfo *applyInfo
73+
netPolQueue *netPolQueue
7374
// removePolicyInfo tracks when a policy was removed yet had ApplyIPSet failures.
7475
// This field is only relevant for Linux.
7576
removePolicyInfo removePolicyInfo
@@ -88,11 +89,12 @@ func NewDataPlane(nodeName string, ioShim *common.IOShim, cfg *Config, stopChann
8889
policyMgr: policies.NewPolicyManager(ioShim, cfg.PolicyManagerCfg),
8990
ipsetMgr: ipsets.NewIPSetManager(cfg.IPSetManagerCfg, ioShim),
9091
// networkID is set when initializing Windows dataplane
91-
networkID: "",
92-
endpointCache: newEndpointCache(),
93-
nodeName: nodeName,
94-
ioShim: ioShim,
95-
endpointQuery: new(endpointQuery),
92+
networkID: "",
93+
endpointCache: newEndpointCache(),
94+
nodeName: nodeName,
95+
ioShim: ioShim,
96+
endpointQuery: new(endpointQuery),
97+
endpointQueryL1VH: new(endpointQuery),
9698
applyInfo: &applyInfo{
9799
inBootupPhase: true,
98100
},

npm/pkg/dataplane/dataplane_windows.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,25 @@ func (dp *DataPlane) initializeDataPlane() error {
5050
},
5151
Flags: hcn.HostComputeQueryFlagsNone,
5252
}
53+
// Initialize Endpoint query used to filter healthy endpoints (vNIC) of Windows pods on L1VH Node
54+
dp.endpointQueryL1VH.query = hcn.HostComputeQuery{
55+
SchemaVersion: hcn.SchemaVersion{
56+
Major: hcnSchemaMajorVersion,
57+
Minor: hcnSchemaMinorVersion,
58+
},
59+
Flags: hcn.HostComputeQueryFlagsNone,
60+
}
61+
5362
// Filter out any endpoints that are not in "AttachedShared" State. All running Windows pods with networking must be in this state.
5463
filterMap := map[string]uint16{"State": hcnEndpointStateAttachedSharing}
55-
filter, err := json.Marshal(filterMap)
56-
if err != nil {
57-
return npmerrors.SimpleErrorWrapper("failed to marshal endpoint filter map", err)
58-
}
64+
filterMapL1VH := map[string]uint16{"State": hcnEndpointStateAttached}
65+
66+
filter, err := marshalFilterMap(filterMap)
67+
68+
filterL1VH, err := marshalFilterMap(filterMapL1VH)
69+
5970
dp.endpointQuery.query.Filter = string(filter)
71+
dp.endpointQueryL1VH.query.Filter = string(filterL1VH)
6072

6173
// reset endpoint cache so that netpol references are removed for all endpoints while refreshing pod endpoints
6274
// no need to lock endpointCache at boot up
@@ -65,6 +77,14 @@ func (dp *DataPlane) initializeDataPlane() error {
6577
return nil
6678
}
6779

80+
func marshalFilterMap(filtermap map[string]uint16) ([]byte, error) {
81+
filter, err := json.Marshal(filtermap)
82+
if err != nil {
83+
return nil, npmerrors.SimpleErrorWrapper("failed to marshal endpoint filter map", err)
84+
}
85+
return filter, nil
86+
}
87+
6888
func (dp *DataPlane) getNetworkInfo() error {
6989
retryNumber := 0
7090
ticker := time.NewTicker(time.Second * time.Duration(maxNoNetSleepTime))
@@ -330,13 +350,15 @@ func (dp *DataPlane) getEndpointsToApplyPolicies(netPols []*policies.NPMNetworkP
330350
func (dp *DataPlane) getLocalPodEndpoints() ([]*hcn.HostComputeEndpoint, error) {
331351
klog.Info("getting local endpoints")
332352
timer := metrics.StartNewTimer()
333-
endpoints, err := dp.ioShim.Hns.ListEndpointsQuery(dp.endpointQuery.query)
353+
endpointsAttachedSharing, err := dp.ioShim.Hns.ListEndpointsQuery(dp.endpointQuery.query)
354+
endpointsAttached, err := dp.ioShim.Hns.ListEndpointsQuery(dp.endpointQueryL1VH.query)
334355
metrics.RecordListEndpointsLatency(timer)
335356
if err != nil {
336357
metrics.IncListEndpointsFailures()
337358
return nil, npmerrors.SimpleErrorWrapper("failed to get local pod endpoints", err)
338359
}
339-
360+
endpoints := append(endpointsAttachedSharing, endpointsAttached...)
361+
klog.Infof("there are %+v endpoints in endpointsAttachedSharing and %+v endpoints in Attached", len(endpointsAttachedSharing), len(endpointsAttached))
340362
epPointers := make([]*hcn.HostComputeEndpoint, 0, len(endpoints))
341363
for k := range endpoints {
342364
epPointers = append(epPointers, &endpoints[k])

0 commit comments

Comments
 (0)