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

Added --subnet validation #15530

Merged
merged 5 commits into from Jan 4, 2023
Merged

Conversation

shubhbapna
Copy link
Contributor

fixes #15517

Added validateSubnet that makes sure the given subnet has a valid private IP address and if it is cidr then the mask shouldn't be greater than 30

To reduce code duplication, I refactored inspect to use ParseAddr

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 17, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @shubhbapna!

It looks like this is your first PR to kubernetes/minikube 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/minikube has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 17, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @shubhbapna. Thanks for your PR.

I'm waiting for a kubernetes 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 17, 2022
@minikube-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@shubhbapna
Copy link
Contributor Author

@spowelljr I have marked it as draft since make lint-ci was failing for me with the following error

cmd/minikube/cmd/start.go:1177:1: cyclomatic complexity 32 of func `validateFlags` is high (> 30) (gocyclo)
func validateFlags(cmd *cobra.Command, drvName string) {
^

But I don't see any way around reducing cyclomatic complexity since I did need to add validateSubnet to this function which adds another path to it. Any suggestions?

@spowelljr
Copy link
Member

I think the easiest way to resolve this is to move if driver.BareMetal(drvName) into it's own function and then call it in that func.

func validateBareMetal(cmd *cobra.Command, drvName string) {
        if !driver.BareMetal(drvName) {
                return
        }
        // bare metal validation
}

@shubhbapna shubhbapna marked this pull request as ready for review December 22, 2022 21:11
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 22, 2022
cmd/minikube/cmd/start.go Outdated Show resolved Hide resolved
func validateSubnet(subnet string) error {
ip, cidr, err := netutil.ParseAddr(subnet)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

Should wrap this will some helpful text like the others

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 you might have forgot to wrap this error

cmd/minikube/cmd/start.go Outdated Show resolved Hide resolved
@shubhbapna shubhbapna requested review from spowelljr and removed request for medyagh December 23, 2022 13:45
func validateSubnet(subnet string) error {
ip, cidr, err := netutil.ParseAddr(subnet)
if err != nil {
return err
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 you might have forgot to wrap this error

@medyagh
Copy link
Member

medyagh commented Jan 3, 2023

shubhbapna are you still working on this ?

@shubhbapna
Copy link
Contributor Author

Yep just came back from the holidays! Will start working on it again today

Copy link
Member

@spowelljr spowelljr left a comment

Choose a reason for hiding this comment

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

Looks good, thank you for the PR

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: shubhbapna, spowelljr

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 Jan 4, 2023
@spowelljr spowelljr merged commit 80dbe4c into kubernetes:master Jan 4, 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. needs-ok-to-test Indicates a PR that requires an org member to verify it 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.

Add --subnet validation
5 participants