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

Fix and Enhance E2E ACNP Baseline Isolation Test #6218

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

qiyueyao
Copy link
Contributor

@qiyueyao qiyueyao commented Apr 13, 2024

In current baseline isolation e2e test, the nsSelector expression is misplaced as nodeSelector expression, yet the test case does not detect the error based on current test factors.

This PR fixes the nsSelector expression issue, and also adds test factors in the baseline isolation test case to increase coverage.

Comment on lines 1659 to 1661
builder1.AddIngress(ProtocolTCP, &p80, nil, nil, nil, nil, nil, nil, nil, nil, nil,
nil, []metav1.LabelSelectorRequirement{podExpOtherThanC}, nil, nil,
nil, nil, crdv1beta1.RuleActionDrop, "", "", nil)
Copy link
Member

Choose a reason for hiding this comment

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

A util function with so many arguments is difficult to use and error prone, especially when adjacent parameters are of the same type.
We should consider refactoring it in a more clear and flexible way some day.

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 agree😶

test/e2e/antreapolicy_test.go Outdated Show resolved Hide resolved
test/e2e/antreapolicy_test.go Outdated Show resolved Hide resolved
testStep := []*TestStep{
{
Name: "Port 80",
Name: "Two baseline ACNPs",
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if the rewriting is necessary. It looks to me the real problem is the ACNP's effect regarding x->x has the same effect as the K8s policy's x->x, so the issue was not detected. Should we just remove the x->x part in K8s policy?

Copy link
Contributor Author

@qiyueyao qiyueyao Apr 16, 2024

Choose a reason for hiding this comment

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

This PR actually started from #6111 when adding e2e tests for NetworkPolicyEvaluation, otherwise it won't be detected. The purpose was to test that

  1. baseline ACNP works
  2. KNP enforced before baseline ACNP
  3. KNP default isolation also enforced before baseline ACNP
  4. baseline ACNP remains effective if not selected by KNP

So I will test each of these aspects returns correct rule result in NetworkPolicyEvaluation tests.

Copy link
Member

Choose a reason for hiding this comment

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

Are 1 and 4 essentially the same? The only difference is 1 has no K8s policy while 4 has irrelevant K8s policy.
Regardless of whether 1 and 4 are duplicate, I think just changing the original test a little can still cover it:

  1. Keep the ACNP acnp-baseline-isolate-ns-x unchanged
  2. Make the K8s policy applied to x/a, allow y/a

Then:
only y/a can access x/a, proving 2 and 3 works
only x can access x/b and x/c, proving 1 and 4 works

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 that sounds good!

@qiyueyao qiyueyao changed the title Fix E2E ACNP Baseline Isolation Test Fix and Enhance E2E ACNP Baseline Isolation Test Apr 16, 2024
@qiyueyao qiyueyao requested a review from Dyanngg April 16, 2024 23:42
test/e2e/antreapolicy_test.go Outdated Show resolved Hide resolved
Comment on lines 1667 to 1669
// create a K8s NetworkPolicy for the x/a Pod to allow ingress traffic from Pods in the same namespace,
// as well as from the y/a Pod. It should open up ingress from y/a and deny ingress from y/b y/c based on
// Kubernetes NetworkPolicy default isolation model, since it's evaluated before the baseline tier.
Copy link
Member

Choose a reason for hiding this comment

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

I think this won't validate the 3rd point: KNP default isolation also enforced before baseline ACNP.
Even if the implementation is the opposite, the test can still pass.
My suggestion was to remove ns-x from the rule, so only y/a is expected to access x/a, proving it's enforced before baseline ACNP.

Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM,

test/e2e/antreapolicy_test.go Outdated Show resolved Hide resolved
test/e2e/antreapolicy_test.go Outdated Show resolved Hide resolved
In current baseline isolation e2e test, the nsSelector expression is
missplaced as nodeSelector expression, yet the test case does not
detect the error based on current test factors.

This PR fixes the nsSelector expression issue, and also adds test
factors in the baseline isolation test case to increase coverage.

Signed-off-by: Qiyue Yao <[email protected]>
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

@tnqn
Copy link
Member

tnqn commented Apr 23, 2024

/skip-all

@tnqn tnqn merged commit 50f2626 into antrea-io:main Apr 23, 2024
49 of 52 checks passed
@qiyueyao qiyueyao deleted the fix-e2e-baseline branch April 23, 2024 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants