Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add addressgroup peer for in-cluster stretched NetworkPolicy enforcement #4432

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Comment on lines -192 to -193
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean it will create AddressGroup anyway no matter it's ClusterSet scope or not?
I am wondering how we can verify that the stretchedNetworkPolicy being spitted into two parts of NP correctly? Shall we mention this on the document?

Copy link
Contributor Author

@Dyanngg Dyanngg Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean it will create AddressGroup anyway no matter it's ClusterSet scope or not?

If there are any pod/nsSelectors, yes it will create AddressGroups because an AddressGroup will need to be created no matter the scope of these selectors.

I am wondering how we can verify that the stretchedNetworkPolicy being spitted into two parts of NP correctly?

E2E testcases should verify this.

} 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