Skip to content

Commit

Permalink
Add addressgroup peer for in-cluster stretched networkpolicy enforcem…
Browse files Browse the repository at this point in the history
…ent (antrea-io#4432)

Signed-off-by: Dyanngg <dingyang@vmware.com>
  • Loading branch information
Dyanngg committed Dec 18, 2022
1 parent 18011b8 commit 113fe92
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/controlplane/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ type HTTPProtocol struct {
}

// NetworkPolicyPeer describes a peer of NetworkPolicyRules.
// It could be a list of names of AddressGroups and/or a list of IPBlock.
// It could contain one of the subfields or a combination of them.
type NetworkPolicyPeer struct {
// A list of names of AddressGroups.
AddressGroups []string
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/networkpolicy/crd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,13 @@ func (n *NetworkPolicyController) toAntreaPeerForCRD(peers []v1alpha1.NetworkPol
} else if peer.NodeSelector != nil {
addressGroup := n.createAddressGroup("", nil, nil, nil, peer.NodeSelector)
addressGroups = append(addressGroups, addressGroup)
} else if peer.Scope == v1alpha1.ScopeClusterSet {
clusterSetScopeSelectors = append(clusterSetScopeSelectors, antreatypes.NewGroupSelector(np.GetNamespace(), peer.PodSelector, peer.NamespaceSelector, nil, nil))
} else {
addressGroup := n.createAddressGroup(np.GetNamespace(), peer.PodSelector, peer.NamespaceSelector, peer.ExternalEntitySelector, nil)
addressGroups = append(addressGroups, addressGroup)
}
if peer.Scope == v1alpha1.ScopeClusterSet {
clusterSetScopeSelectors = append(clusterSetScopeSelectors, antreatypes.NewGroupSelector(np.GetNamespace(), peer.PodSelector, peer.NamespaceSelector, nil, nil))
}
}
var labelIdentities []uint32
if n.multiclusterEnabled {
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/networkpolicy/crd_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ func TestToAntreaPeerForCRD(t *testing.T) {
},
outPeer: controlplane.NetworkPolicyPeer{
LabelIdentities: []uint32{1},
AddressGroups: []string{
getNormalizedUID(antreatypes.NewGroupSelector("", &selectorA, nil, nil, nil).NormalizedName),
},
},
direction: controlplane.DirectionIn,
clusterSetScope: true,
Expand Down

0 comments on commit 113fe92

Please sign in to comment.