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

Support Network Policy for UDN namespaces #4690

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pperiyasamy
Copy link
Contributor

@pperiyasamy pperiyasamy commented Sep 2, 2024

What this PR does and why is it needed

This PR has required changes to support Network Policy on User Defined Network.

  • NetPol Support on L3 UDN network.
  • NetPol support on on L2 UDN network.

TODOs:

Which issue(s) this PR fixes

Fixes #

Special notes for reviewers

How to verify it

Details to documentation updates

Description for the changelog

Does this PR introduce a user-facing change?


@pperiyasamy pperiyasamy requested a review from a team as a code owner September 2, 2024 09:28
@pperiyasamy pperiyasamy marked this pull request as draft September 2, 2024 09:28
@github-actions github-actions bot added the area/unit-testing Issues related to adding/updating unit tests label Sep 2, 2024
@pperiyasamy pperiyasamy requested review from tssurya and npinaeva and removed request for trozet September 2, 2024 14:30
@npinaeva
Copy link
Member

npinaeva commented Sep 2, 2024

there are some netpol-related test failures. Also, could you please add a couple of e2es for the new netpol behaviour?

@pperiyasamy pperiyasamy force-pushed the netpol-udn branch 3 times, most recently from f55a827 to 259e967 Compare September 5, 2024 08:28
@pperiyasamy pperiyasamy changed the title Handle NetPol events on UDN namespaces Support Network Policy for UDN namespaces Sep 5, 2024
@pperiyasamy pperiyasamy marked this pull request as ready for review September 5, 2024 08:30
@pperiyasamy
Copy link
Contributor Author

@pperiyasamy pperiyasamy force-pushed the netpol-udn branch 2 times, most recently from 13bb7db to 95051a1 Compare September 6, 2024 07:25
Comment on lines +223 to +231
if bnc.NetInfo.IsSecondary() {
return nil
}

// add default hairpin allow acl
err = bnc.addHairpinAllowACL()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we need the hairpin allow ACLs for primary networks? Add comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added comment about why hairpin allow ACLs disabled now for UDN. will revisit once we have cluster port group exists per network. currently this is not impacting unit tests and e2e's.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have an issue to track?

Copy link
Contributor

Choose a reason for hiding this comment

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

@pperiyasamy pperiyasamy force-pushed the netpol-udn branch 2 times, most recently from 954ed21 to 3c24090 Compare September 13, 2024 08:59
@pperiyasamy pperiyasamy changed the title Support Network Policy for UDN namespaces Support Network Policy for L3 UDN namespaces Sep 13, 2024
@pperiyasamy pperiyasamy force-pushed the netpol-udn branch 2 times, most recently from cc1b738 to dd13b11 Compare September 16, 2024 09:24
Comment on lines 927 to 955
func (bnc *BaseNetworkController) UpdateResourceCommon(objType reflect.Type, oldObj, newObj interface{}) error {
switch objType {
case factory.PolicyType:
oldNp, ok := oldObj.(*knet.NetworkPolicy)
if !ok {
return fmt.Errorf("could not cast obj of type %T to *knet.NetworkPolicy", oldObj)
}
if err := bnc.deleteNetworkPolicy(oldNp); err != nil {
klog.Infof("NetworkPolicy delete failed for %s/%s, will try again later: %v",
oldNp.Namespace, oldNp.Name, err)
return err
}
newNp, ok := newObj.(*knet.NetworkPolicy)
if !ok {
return fmt.Errorf("could not cast obj of type %T to *knet.NetworkPolicy", newObj)
}
if err := bnc.addNetworkPolicy(newNp); err != nil {
klog.Infof("NetworkPolicy add failed for %s/%s, will try again later: %v",
newNp.Namespace, newNp.Name, err)
return err
}
default:
return fmt.Errorf("object type %s not supported", objType)
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, removed the method as it's no longer needed.

go-controller/pkg/ovn/base_network_controller.go Outdated Show resolved Hide resolved
@pperiyasamy pperiyasamy force-pushed the netpol-udn branch 2 times, most recently from 40b8e95 to aa7e68f Compare September 17, 2024 09:11
@jcaamano
Copy link
Contributor

Potential flake
[FAIL] Network Segmentation: services on a user defined primary network should be reachable through their cluster IP and node port [It] L3 dualstack primary UDN, cluster-networked pods, NodePort service
https://github.com/ovn-org/ovn-kubernetes/actions/runs/10900030212/job/30253567040?pr=4690

@jcaamano
Copy link
Contributor

Potential flake [FAIL] Network Segmentation: services on a user defined primary network should be reachable through their cluster IP and node port [It] L3 dualstack primary UDN, cluster-networked pods, NodePort service https://github.com/ovn-org/ovn-kubernetes/actions/runs/10900030212/job/30253567040?pr=4690

@pperiyasamy does not look like a flake

trozet
trozet previously approved these changes Sep 17, 2024
Copy link
Contributor

@trozet trozet left a comment

Choose a reason for hiding this comment

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

minor comment nits, lgtm


},
ginkgo.Entry(
"in L2 dualstack primary UDN",
Copy link
Contributor

Choose a reason for hiding this comment

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

the title of this PR says netpol for L3, but here are L2 test cases and changes to layer 2 controller. So is L2 also supported and the title just needs to be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes @trozet , updated title and description accordingly now.

@pperiyasamy pperiyasamy force-pushed the netpol-udn branch 2 times, most recently from c844a21 to e29cb3e Compare September 19, 2024 07:58
@pperiyasamy pperiyasamy changed the title Support Network Policy for L3 UDN namespaces Support Network Policy for UDN namespaces Sep 19, 2024
if ns != namespace {
continue
}
return []string{nadName}, nil
Copy link
Contributor

@jcaamano jcaamano Sep 19, 2024

Choose a reason for hiding this comment

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

This is based on two assumptions:

  • There is a single NAD per namespace for primary networks. However, there is nothing currently that prevents this from happening.
  • We are aware of the primary network of a pod. However this might be racey.

The first issue should be handled in some way by the NAD controller. It might do that through GetActiveNetworkForNamespace. For the second issue, GetActiveNetworkForNamespace offers a bit more of protection since it will check against the UDN CRDs as well.

I don't want to hold this because of that. But I am entertaining the idea that we could just implement GetActiveNetworkForNamespace in NetInfo that would just end up calling the nad controller GetActiveNetworkForNamespace which is feasible since the nad controller is the one building those NetInfo after all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the idea of having GetActiveNetworkForNamespace inside netInfo.

Comment on lines 199 to 205
defer func() {
gomega.Expect(cs.CoreV1().Namespaces().Delete(
context.Background(),
namespace,
metav1.DeleteOptions{},
)).To(gomega.Succeed())
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use defer to clean up please, it hinders troubleshooting. Use f.AddNamespacesToDelete; or manually in AfterEach depending on how the framework is configured and if the test case failed or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes @jcaamano , modified the test to use f.AddNamespacesToDelete.

@pperiyasamy pperiyasamy force-pushed the netpol-udn branch 2 times, most recently from b43b948 to 87ce669 Compare September 19, 2024 14:00
@npinaeva
Copy link
Member

Is it intended to configure netpol for both default and primary UDN at the same time?

@pperiyasamy
Copy link
Contributor Author

Is it intended to configure netpol for both default and primary UDN at the same time?

yes @npinaeva , The netpol for default and primary UDN networks would coexist with this PR as well. The existing shard-conformance CI lane tests netpol over default network and we had few e2e's to test NetPol over UDN network.
We also ran upstream NetPol tests over UDN L3 network on this PR and it worked fine. We're waiting for #4653 to run upstream tests over L2 network. Does it suffice ? or do you want to cover something more ?

@npinaeva
Copy link
Member

yes @npinaeva , The netpol for default and primary UDN networks would coexist with this PR as well. The existing shard-conformance CI lane tests netpol over default network and we had few e2e's to test NetPol over UDN network. We also ran upstream NetPol tests over UDN L3 network on this PR and it worked fine. We're waiting for #4653 to run upstream tests over L2 network. Does it suffice ? or do you want to cover something more ?

So when primary UDN exists, we will configure network policy both for UDN and for default network, which means 2 times more port groups, acls, address sets, which will not be used (as default network traffic has its own ACLs that deny almost everything already). So UDN netpol will work, but not sure if it is the most optimal solution.

@jcaamano
Copy link
Contributor

So when primary UDN exists, we will configure network policy both for UDN and for default network, which means 2 times more port groups, acls, address sets, which will not be used (as default network traffic has its own ACLs that deny almost everything already). So UDN netpol will work, but not sure if it is the most optimal solution.

@npinaeva has a point.

So when handling a policy we would have to GetActiveNetworkForNamespace(netpolNamespace) and check that it matches our network. Seems straight forward enough.

This commit provides Network Policy support for user defined l3
or l2 networks when it is configured as the primary network for
namespace. It's done by subscribing to NetPol events from secondary
network controllers and handling it appropriately in base network
and policy controllers.

Signed-off-by: Periyasamy Palanisamy <[email protected]>
When primary UDN exists for the namespace, the current implementation configured
network policy for both UDN and default network. The default network traffic
has its own ACLs that deny almost everything already so handling network policy
for default is unnecessary and not an optimal solution as it programs another
set of port groups, acls and address sets which are never going to be used.
Hence this commit skips handling network policy events on the default network
controller when namespace contains an active user defined network.

Signed-off-by: Periyasamy Palanisamy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/e2e-testing area/unit-testing Issues related to adding/updating unit tests feature/admin-network-policy feature/egress-gateway All issues related to ICNI/APBR feature/egress-ip Issues related to EgressIP feature feature/egress-qos
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

5 participants