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

[Policy Assistant] Add support for dynamic workload traffic via POLA cli #264

Merged
merged 3 commits into from
Nov 11, 2024

Conversation

gabrielggg
Copy link
Contributor

@gabrielggg gabrielggg commented Nov 5, 2024

Hey @huntergregory , as discussed, here is the pr for allowing dynamic traffic via cli. This is to finish #220 . And to allow #255 .

To test you cand do something like this:

image

Please check it out.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 5, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @gabrielggg. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 5, 2024
Copy link

netlify bot commented Nov 5, 2024

Deploy Preview for kubernetes-sigs-network-policy-api ready!

Name Link
🔨 Latest commit 21efeb4
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-network-policy-api/deploys/67322436d464980008f426e0
😎 Deploy Preview https://deploy-preview-264--kubernetes-sigs-network-policy-api.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@gabrielggg gabrielggg changed the title Add support for dynamic workload traffic Add support for dynamic workload traffic via POLA cli Nov 5, 2024
@gabrielggg gabrielggg changed the title Add support for dynamic workload traffic via POLA cli [Policy Assistant] Add support for dynamic workload traffic via POLA cli Nov 5, 2024
@huntergregory
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 5, 2024
Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

Thank you for the effort last minute @gabrielggg !

This looks great. If you could address the minor suggestions today that'd be amazing. Could you test each of the 5 workload types and when --port and --protocol are unspecified vs. specified?

Would be awesome if we could also support specifying a traffic.json with Pod labels etc. in case the user doesn't have a cluster and can't specify workload name. It also could be nice to support specifying workload in the traffic.json, but that is lower priority if we run out of time.

Let me know your thoughts! Thanks!

cmd/policy-assistant/pkg/cli/analyze.go Outdated Show resolved Hide resolved
cmd/policy-assistant/pkg/cli/analyze.go Outdated Show resolved Hide resolved
cmd/policy-assistant/pkg/cli/analyze.go Outdated Show resolved Hide resolved
@gabrielggg
Copy link
Contributor Author

gabrielggg commented Nov 5, 2024

hey @huntergregory, thanks for the review , i just committed some code to at least fix the conversations you opened, also tested the behavior when user doesn´t input port or protocol and tested different workload Types, the next commit will include support for the traffic.json file, but i think that will be ready for the night or maybe tomorrow.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 6, 2024
@gabrielggg
Copy link
Contributor Author

gabrielggg commented Nov 6, 2024

Hey @huntergregory , it's working now, and supporting cli arguments and also traffic.json file including native workloads on the file, I had to maneuver several scenarios to avoid null pointers, please check it out. Of course the code can be simplified but this was the fastest i could do for the first release!

This is the traffic, json file used for generating the image below.

https://github.com/gabrielggg/network-policy-api/blob/main/cmd/policy-assistant/examples/traffic.json

image

Some more testing with this last version:

image

@gabrielggg
Copy link
Contributor Author

/retest

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

Thanks @gabrielggg that result looks amazing! I appreciate you going above and beyond supporting the whole traffic.json in this PR. I had minor suggestions for validating input. I also feel like having all these if-else statements could be bug prone 😕. Luckily, it looks like all the branches have shared logic that can be refactored into a couple functions? I added comments with outlines for much smaller code.

I still would love to release this change for the upcoming KubeCon, but I feel like I unfortunately can't do a just review of the code if there are all the if-else branches

cmd/policy-assistant/pkg/cli/analyze.go Show resolved Hide resolved
cmd/policy-assistant/pkg/matcher/traffic.go Outdated Show resolved Hide resolved
cmd/policy-assistant/pkg/cli/analyze.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 7, 2024
@huntergregory
Copy link
Contributor

/retest

@gabrielggg
Copy link
Contributor Author

hey @huntergregory , thanks for the advice, i finished with the refactoring! Please check it out!

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

Thanks @gabrielggg, on the home stretch. I'd like to make one more change for the user experience. Good to merge after! We are planning to cut the release last minute on Monday after 12:00 PST if you could possibly update before then (the conference starts Tuesday). Would that work?

cmd/policy-assistant/pkg/cli/analyze.go Show resolved Hide resolved
cmd/policy-assistant/pkg/cli/analyze.go Outdated Show resolved Hide resolved
cmd/policy-assistant/pkg/cli/analyze.go Outdated Show resolved Hide resolved
cmd/policy-assistant/pkg/cli/analyze.go Show resolved Hide resolved
cmd/policy-assistant/pkg/matcher/traffic.go Show resolved Hide resolved
@gabrielggg gabrielggg closed this Nov 11, 2024
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 11, 2024
@gabrielggg gabrielggg reopened this Nov 11, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 11, 2024
@gabrielggg
Copy link
Contributor Author

Hey @huntergregory , thanks again for the review, i tackled all your suggestions and also squashed the commits. Please check it out!

@huntergregory
Copy link
Contributor

Looks good at a glance. Adding approval to hopefully kick off the GitHub action to make sure it passes

/approve

Will add a LGTM hopefully tomorrow morning

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 11, 2024
@huntergregory
Copy link
Contributor

/approve cancel

@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 11, 2024
@huntergregory
Copy link
Contributor

Trying the other way around. Lgtm first to kickoff GH action

/lgtm

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

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

Thanks @gabrielggg. Ready to approve but would prefer if we could fix the minor bug, and I'd recommend renaming the args, but neither is a blocker

cmd/policy-assistant/pkg/cli/analyze.go Show resolved Hide resolved
cmd/policy-assistant/pkg/cli/analyze.go Outdated Show resolved Hide resolved
cmd/policy-assistant/pkg/matcher/traffic.go Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 11, 2024
@gabrielggg
Copy link
Contributor Author

Hey @huntergregory , thanks again for the review, i made some changes based on your comments. Please check it out!

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

Thanks @gabrielggg ! This is a great feature

/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 Nov 11, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gabrielggg, huntergregory

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 11, 2024
@k8s-ci-robot k8s-ci-robot merged commit 6030eb9 into kubernetes-sigs:main Nov 11, 2024
8 checks passed
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants