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 port validation #12233

Merged
merged 3 commits into from
Sep 27, 2021
Merged

Added port validation #12233

merged 3 commits into from
Sep 27, 2021

Conversation

kadern0
Copy link
Contributor

@kadern0 kadern0 commented Aug 11, 2021

Fixes #10495

Tests:

minikube start --driver=docker --ports=asdf:80 --ports=443:443
πŸ˜„  minikube v1.22.0 on Ubuntu 20.04
✨  Using the docker driver based on existing profile

❌  Exiting due to MK_USAGE: Sorry, one of the ports provided with --ports flag is not valid [asdf:80 443:443]
minikube start --driver=docker --ports=8080:80 --ports=443:443
πŸ˜„  minikube v1.22.0 on Ubuntu 20.04
✨  Using the docker driver based on existing profile

❌  Exiting due to MK_USAGE: Sorry, you cannot use privileged ports on the host (below 1024) [8080:80 443:443]
minikube start --driver=docker --ports=8080:80 --ports=6443:443
πŸ˜„  minikube v1.22.0 on Ubuntu 20.04
✨  Using the docker driver based on existing profile
πŸ‘  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
πŸ”„  Restarting existing docker container for "minikube" ...
🐳  Preparing Kubernetes v1.21.3 on Docker 20.10.7 ...
πŸ”Ž  Verifying Kubernetes components...
    β–ͺ Using image k8s.gcr.io/ingress-nginx/controller:v0.44.0
    β–ͺ Using image docker.io/jettech/kube-webhook-certgen:v1.5.1
    β–ͺ Using image docker.io/jettech/kube-webhook-certgen:v1.5.1
    β–ͺ Using image gcr.io/k8s-minikube/storage-provisioner:v5
πŸ”Ž  Verifying ingress addon...
🌟  Enabled addons: storage-provisioner, default-storageclass, ingress

πŸ„  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 11, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @kadern0. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 11, 2021
@minikube-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@kadern0 kadern0 force-pushed the issue-10495 branch 2 times, most recently from 0777f14 to e19c734 Compare August 11, 2021 22:28
@spowelljr
Copy link
Member

Thanks for the validation @kadern0, it looks good! If I could ask you to do one more thing, if you wouldn't mind writing a test for this validation in start_test.go.

If you call

func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k8sVersion string, drvName string) (config.ClusterConfig, config.Node, error) {
in the test it will run flag validation, there are other tests in start_test.go that do this exact same thing if you're looking for an example.

Thanks!

@kadern0
Copy link
Contributor Author

kadern0 commented Aug 12, 2021

@spowelljr thanks for the feedback!
Adding tests for this function might not be as straightforward (for me, at least) as it seems. Unlike the other tests on the file, this function doesn't return anything (same as the other validation functions) and unlike the other two tests that call 'generateClusterConfig', we can't test the function from there since this function is called from 'runStart'. So unless I'm missing anything, options are: no test (as with most of validating functions), refactor and add a return statement and test the function directly (although this isn't being done for the other validation functions), making a call to the function during the configuration generation so we can test it from there.
What do you think?

cmd/minikube/cmd/start.go Outdated Show resolved Hide resolved
@medyagh
Copy link
Member

medyagh commented Aug 13, 2021

@spowelljr thanks for the feedback!
Adding tests for this function might not be as straightforward (for me, at least) as it seems. Unlike the other tests on the file, this function doesn't return anything (same as the other validation functions) and unlike the other two tests that call 'generateClusterConfig', we can't test the function from there since this function is called from 'runStart'. So unless I'm missing anything, options are: no test (as with most of validating functions), refactor and add a return statement and test the function directly (although this isn't being done for the other validation functions), making a call to the function during the configuration generation so we can test it from there.
What do you think?

how about adding a unit test in start_test.go
just for this func

validatePorts(ports []string)

@kadern0
Copy link
Contributor Author

kadern0 commented Aug 13, 2021

@medyagh so the plan is: refactoring the function so it returns error and then create a unit test for it, right?

@medyagh
Copy link
Member

medyagh commented Aug 13, 2021

@medyagh so the plan is: refactoring the function so it returns error and then create a unit test for it, right?

Yes please . Thank you for your helpful prs

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 14, 2021
@kadern0
Copy link
Contributor Author

kadern0 commented Aug 14, 2021

@medyagh I've made the changes as suggested but now it seems the cyclomatic complexity of the function validateFlags is > 30. It seems it might require additional changes.

@kadern0 kadern0 requested a review from medyagh August 14, 2021 05:51
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 30, 2021
@kadern0 kadern0 requested a review from spowelljr August 31, 2021 00:06
@kadern0
Copy link
Contributor Author

kadern0 commented Sep 19, 2021

@medyagh , @spowelljr I think this PR is ready for another review :)

@spowelljr
Copy link
Member

@kadern0 The code looks good! One last thing, could you run make generate-docs and push the changes up and then we'll be good to go, thanks for your patience.

cmd/minikube/cmd/start.go Outdated Show resolved Hide resolved
cmd/minikube/cmd/start.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kadern0, 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 Sep 27, 2021
@spowelljr spowelljr merged commit f85e7db into kubernetes:master Sep 27, 2021
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.

validate ports provided by user to --ports flag on docker driver
5 participants