Skip to content

Conversation

@zeeke
Copy link
Contributor

@zeeke zeeke commented Sep 28, 2022

The test case uses Cluster Network Operator field useMultiNetworkPolicy field and a basic deny-all policy to ensure the feature is correctly setup.
Fixture involves a macvlan net-attach-def and network policy. Connectivity tests are implemented using agnhost http server and cURL.

Signed-off-by: Andrea Panattoni apanatto@redhat.com

@zeeke
Copy link
Contributor Author

zeeke commented Sep 29, 2022

/retest-required

err = oc.AsAdmin().Run("create").Args("-f", nad_yaml).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("launching pod with an annotation to use the net-attach-def")
Copy link
Contributor

Choose a reason for hiding this comment

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

Would our tests be simpler if we added some NAD-related helper functions?

err = exutil.CreateNetworkAttachmentDefinition("macvlan-nad.yml")

exutil.SetNADAnnotation(pod, "macvlan1-nad", map[string]interface{
        "ips": []string{"2.2.2.1/24"},
})

etc? Or something? (I don't remember exactly what the overlap is with the other NAD-related tests, but I know there are a lot of NAD-related tests at this point...)

(If you were going to do this, it would be best to have one commit first that adds the helpers and ports the existing tests to use them, and then a second commit adding the new MultiNetworkPolicy test, using the helpers.)

Copy link
Contributor

Choose a reason for hiding this comment

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

um, wait, there's already a createNetworkAttachmentDefinition method in test/extending/networking/utils.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, saw it .But it uses dynamic client instead of Yaml files. Is it ok to turn every NAD creation (I found 4 in the code base) in a call to createNetworkAttachmentDefinition()? and then removing yaml files?

]`

frameworkpod.CreateExecPodOrFail(f.ClientSet, ns, podName, func(pod *v1.Pod) {
pod.Spec.Containers[0].Args = []string{"net", "--serve", "2.2.2.1:8889"}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to use an IP in a reserved range, rather than an IP that actually does belong to someone in the real world. I think for the ovn-kube egress IP tests we use IPs from the "reserved for documentation examples" range?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, I didn't know that: https://www.rfc-editor.org/rfc/rfc5737 .


o.Eventually(func() error {
return oc.AsAdmin().Run("get").Args("multi-networkpolicies.k8s.cni.cncf.io").Execute()
}, "30s", "2s").Should(o.Succeed())
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't reliably indicate that MNP enforcement is in effect... that depends on deploying a DaemonSet as well, right?

The timeouts help, but it would be better if there was a good way of ensuring that the DaemonSet is fully deployed, so the test doesn't end up flaking under heavy load. (But also, we don't want to make too many assumptions about exactly what CNO is doing when you enable the feature, especially since we might change to a different MNP implementation in the future... I'm not sure what the best approach here is...)

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 agree with your considerations, it's not easy to decide what's the best approach. From the user's perspective, turning on the feature means that MNP resource becomes available.

If the Daemonset (or any other component) is not working or it is not started, then some other assertion will fail.

As a further example, in the future we can also decide to keep the Daemonset up and running but not creating iptables if the flag is set to false.

That said, I would keep it as simple as possible.

err = oc.AsAdmin().Run("create").Args("-f", multinetpolicy_yaml).Execute()
o.Expect(err).To(o.Succeed())

g.By("checking podB can NOT connnect to podA")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to test more than this. As written, this test would pass even if the actual behavior was "activating MNP completely breaks all secondary networks" 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! To achieve it, I need to:

  • add a third pod (podC)
  • change the policy from a deny-all style to something like:
...
  podSelector:
    matchLabels:
      pod: a
  policyTypes:
    - Ingress
  ingress:
    - from:
        - podSelector:
            matchLabels:
              pod: c
  • check pod-C can connect to pod-A

But it will make the test a little more complicated. Do you have any suggestions for this?

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 refactored the test a little, now there is a deny-all-ingress rule applied only to pod-A, and I added another server pod-C. This way I can test pod-B can't connect to A but can still reach C. WDYT?

}, "30s", "2s").Should(o.Succeed())
}

func disablMultiNetworkPolicy(oc *exutil.CLI) {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo "disabl"

Comment on lines 60 to 62
g.By("enabling MultiNetworkPolicies on cluster")
enableMultiNetworkPolicy(oc)
defer disablMultiNetworkPolicy(oc)
Copy link
Contributor

Choose a reason for hiding this comment

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

You're assuming that the feature is disabled by default in all clusters where the e2e suite runs, but that doesn't seem safe. I'd check to see if it's already enabled, and only do the "enable and defer disable" if it's 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.

Sure, I added logic to store initial useMultinetworkPolicy state and restore it afterward

@danwinship danwinship mentioned this pull request Sep 29, 2022
@zeeke zeeke force-pushed the multinetwork-policy branch from 99e897d to fb04f7a Compare September 29, 2022 16:48
@zeeke zeeke requested review from danwinship and removed request for soltysh October 5, 2022 14:32
@zeeke zeeke force-pushed the multinetwork-policy branch from fb04f7a to c7d0849 Compare October 11, 2022 14:26
@zeeke
Copy link
Contributor Author

zeeke commented Oct 18, 2022

/retest-required

@zeeke
Copy link
Contributor Author

zeeke commented Oct 20, 2022

@danwinship can you please take another look at this?

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 22, 2022
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 30, 2022
@zeeke
Copy link
Contributor Author

zeeke commented Nov 7, 2022

/retest-required

@zeeke zeeke force-pushed the multinetwork-policy branch from c7d0849 to cfcede3 Compare November 9, 2022 11:31
Test case use Cluster Network Operator field `useMultiNetworkPolicy`
field and a basic `deny-all-ingress` policy to ensure the feature is correctly
setup.
Fixture involves a macvlan net-attach-def and network policy.
Connectivity tests are implemented using agnhost http server
and cURL.

Signed-off-by: Andrea Panattoni <apanatto@redhat.com>
@zeeke zeeke force-pushed the multinetwork-policy branch from cfcede3 to 64404c5 Compare November 18, 2022 15:56
@cgoncalves
Copy link

/retest-required

2 similar comments
@zeeke
Copy link
Contributor Author

zeeke commented Dec 14, 2022

/retest-required

@cgoncalves
Copy link

/retest-required

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 15, 2022

@zeeke: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-builds c7d0849 link true /test e2e-gcp-builds
ci/prow/e2e-gcp-ovn-image-ecosystem c7d0849 link true /test e2e-gcp-ovn-image-ecosystem
ci/prow/e2e-aws-ovn-upgrade 64404c5 link false /test e2e-aws-ovn-upgrade
ci/prow/e2e-aws-ovn-cgroupsv2 64404c5 link false /test e2e-aws-ovn-cgroupsv2
ci/prow/e2e-gcp-ovn-rt-upgrade 64404c5 link false /test e2e-gcp-ovn-rt-upgrade
ci/prow/e2e-aws-ovn-single-node-upgrade 64404c5 link false /test e2e-aws-ovn-single-node-upgrade
ci/prow/e2e-openstack-ovn 64404c5 link false /test e2e-openstack-ovn
ci/prow/e2e-aws-csi 64404c5 link false /test e2e-aws-csi
ci/prow/e2e-aws-ovn-single-node 64404c5 link false /test e2e-aws-ovn-single-node
ci/prow/e2e-aws-ovn-single-node-serial 64404c5 link false /test e2e-aws-ovn-single-node-serial
ci/prow/e2e-gcp-ovn 64404c5 link true /test e2e-gcp-ovn
ci/prow/verify 64404c5 link true /test verify

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@zeeke
Copy link
Contributor Author

zeeke commented Dec 16, 2022

@cgoncalves
@danwinship

All the required tests are passing. openshift-ci comments refer to old tests that are no longer required.

e.g. e2e-gcp-builds -> e2e-gcp-ovn-builds

@cgoncalves
Copy link

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 9, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 9, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cgoncalves, zeeke
Once this PR has been reviewed and has the lgtm label, please assign deads2k for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@zeeke
Copy link
Contributor Author

zeeke commented Mar 6, 2023

@s1061123 @dougbtv @danwinship
can you help me get this in?

Copy link

@s1061123 s1061123 left a comment

Choose a reason for hiding this comment

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

Almost stuff seems to be good. Thanks!


import (
"fmt"

Choose a reason for hiding this comment

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

should be removed due to CI failure

annotations:
k8s.v1.cni.cncf.io/policy-for: macvlan1-nad
spec:
podSelector:

Choose a reason for hiding this comment

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

should we add policyType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure!

@zeeke
Copy link
Contributor Author

zeeke commented Mar 14, 2023

@s1061123 thanks for reviewing. Since this issue staled for a while, I opened an IPv6 / IPv4 version in:

I addressed your comment there. Please, have a look

@zeeke
Copy link
Contributor Author

zeeke commented Mar 21, 2023

@zeeke zeeke closed this Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants