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 network policy enforcement latency measurement #2234

Merged

Conversation

dlapcevic
Copy link
Contributor

Description

A new measurement that utilizes network policy enforcement latency test clients.
https://github.com/kubernetes/perf-tests/tree/master/network/tools/network-policy-enforcement-latency

This measurement is intended to be used in the ClusterLoader2 load test.
https://github.com/kubernetes/perf-tests/tree/master/clusterloader2/testing/load

Network policy enforcement latency is the required time for any change to pods or network policies to be reflected in the system. It's measured by simulating a real scenario with workloads that are connecting to each other, and measuring the time it takes for the network policies to be honored for new pods or network policy changes. The relevant scalability and performance dimensions are pod and policy churn rate (create, update, delete).

Usage

The measurement tests network policy enforcement latency for two cases:

  1. Created network policies
    Deploy the test clients (setup and run) with "testType" flag set to "policy-creation" after creating the target pods.

  2. Created pods that are affected by network policies
    Deploy the test clients (setup and run) with "testType" flag set to "pod-creation”, before creating the target pods. Target pods are all pods that have the specified label: { targetLabelKey: targetLabelValue }.

The test is set up by creating the required resources, including the network policy enforcement latency test client pods that measure the latencies and generate metrics for them.

/kind feature

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 15, 2023
@dlapcevic
Copy link
Contributor Author

/assign @marseel

@aojea
Copy link
Member

aojea commented Feb 15, 2023

/cc

@marseel
Copy link
Member

marseel commented Apr 25, 2023

/lgtm

As it's a non-trivial measurement I would like someone else to take a look too.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 25, 2023
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 25, 2023
@marseel
Copy link
Member

marseel commented Apr 25, 2023

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 25, 2023
@dlapcevic
Copy link
Contributor Author

Hi @marseel and @aojea, could you please recommend another reviewer?

Copy link
Member

@tosi3k tosi3k left a comment

Choose a reason for hiding this comment

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

Nitpicks, apart from that LGTM.

limiter := rate.NewLimiter(rate.Limit(policyLoadQPS), policyLoadQPS)

for nsIdx, ns := range nps.targetNamespaces {
baseCidr := fmt.Sprintf("10.0.%d.0/24", nsIdx)
Copy link
Member

Choose a reason for hiding this comment

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

The measurement is not suitable for more than 256 test namespaces.

Could we at least have some way of indicating this is not allowed by explicitly failing in Execute when the user attempts to do so?

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 octet := nsIdx % 256 to make it work for more than 256 namespaces, because the CIDR is not very important here, it's just testing the network policy load.

matchLabels:
kubernetes.io/metadata.name: {{.TargetNamespace}}
{{else}}
namespaceSelector: {}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: is this actually needed?

Copy link
Contributor Author

@dlapcevic dlapcevic Jun 1, 2023

Choose a reason for hiding this comment

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

Yes, because we are allowing ingress traffic from all test namespaces and not just from the one that the pods are in and policies applied.
More info: https://github.com/ahmetb/kubernetes-network-policy-recipes/blob/master/05-allow-traffic-from-all-namespaces.md

Selects all pods in all namespaces (namespaceSelector: {}).
By default, if you omit specifying a namespaceSelector it does not select any namespaces, which means it will allow traffic only from the namespace the NetworkPolicy is deployed to.

verbs: ["get", "list", "watch"]
- apiGroups: ["networking.k8s.io"]
resources: ["networkpolicies"]
verbs: ["get", "list", "watch"]
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: "watch" for networkpolicies isn't required, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently neither "list" is being used. I'm removing both "list" and "watch" for network policies.
They are being used by the test client app https://github.com/kubernetes/perf-tests/tree/master/network/tools/network-policy-enforcement-latency

}

func (nps *networkPolicyEnforcementMeasurement) run(config *measurement.Config) error {
// Should this be mandatory? Fail if not provided.
Copy link
Member

Choose a reason for hiding this comment

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

Should this get a TODO or is it an unfinished leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

return nil
}

func (nps *networkPolicyEnforcementMeasurement) run(config *measurement.Config) error {
Copy link
Member

Choose a reason for hiding this comment

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

Could we add some check to run that setup was run beforehand?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Used nps.framework == nil to check if setup was run before.

@dlapcevic dlapcevic force-pushed the netpol-enforcement-latency-test branch from c9000be to 1ca5029 Compare June 6, 2023 12:15
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 6, 2023
@dlapcevic
Copy link
Contributor Author

@tosi3k @marseel can we please merge now?

@dlapcevic dlapcevic force-pushed the netpol-enforcement-latency-test branch from 1ca5029 to 02a316d Compare June 6, 2023 12:37
@marseel
Copy link
Member

marseel commented Jun 6, 2023

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 6, 2023
@dlapcevic dlapcevic force-pushed the netpol-enforcement-latency-test branch from 02a316d to c4cb115 Compare June 7, 2023 09:26
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 7, 2023
@tosi3k
Copy link
Member

tosi3k commented Jun 7, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 7, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dlapcevic, marseel, tosi3k

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

The pull request process is described here

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

@dlapcevic
Copy link
Contributor Author

@marseel can we please merge now?

@tosi3k
Copy link
Member

tosi3k commented Jun 9, 2023

I think you just need to cancel the hold :).

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 9, 2023
@dlapcevic
Copy link
Contributor Author

Thanks @tosi3k. I didn't know that I had a permission to do it.

@k8s-ci-robot k8s-ci-robot merged commit 9025300 into kubernetes:master Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants