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

Prevent minikube from crashing if namespace or service doesn't exist #5844

Merged
merged 6 commits into from
Mar 21, 2020

Conversation

rajula96reddy
Copy link
Member

@rajula96reddy rajula96reddy commented Nov 6, 2019

Fixes issue #5836

Old behavior

$ minikube service newservice -n unknown --url

💣 Error opening service: Service newservice was not found in "unknown" namespace. You may select another namespace by using 'minikube service newservice -n : Temporary Error: Error getting service newservice: services "newservice" not found

😿 Sorry that minikube crashed. If this was unexpected, we would love to hear from you:
👉 https://github.com/kubernetes/minikube/issues/new/choose

New behaviour

$ minikube service newservice -n unknown --url

💣  Error opening service: Service newservice was not found in "unknown" namespace. You may select another namespace by using 'minikube service newservice -n <namespace>'. Or list out all the services using 'minikube service list': Temporary Error: Error getting service newservice: services "newservice" not found

PS: Hey! This is my first contribution to K8s 🎉. Pardon me if there are any blunders 😅

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

Welcome @rajula96reddy!

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 Nov 6, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @rajula96reddy. 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.

@minikube-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Nov 6, 2019
@codecov-io
Copy link

codecov-io commented Nov 6, 2019

Codecov Report

Merging #5844 into master will decrease coverage by 0.02%.
The diff coverage is 30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5844      +/-   ##
==========================================
- Coverage   37.01%   36.98%   -0.03%     
==========================================
  Files         144      144              
  Lines        9010     9019       +9     
==========================================
+ Hits         3335     3336       +1     
- Misses       5253     5260       +7     
- Partials      422      423       +1
Impacted Files Coverage Δ
cmd/minikube/cmd/service.go 8.86% <0%> (-0.48%) ⬇️
pkg/minikube/service/service.go 76.31% <50%> (-1.53%) ⬇️

@rajula96reddy
Copy link
Member Author

/assign @medyagh

@medyagh
Copy link
Member

medyagh commented Nov 6, 2019

@rajula96reddy welcome to contributing to minikube ! thank you for making such a quick PR !

the PR looks good just small request.

💣  Error opening service: Service newservice was not found in "unknown" namespace. You may select another namespace by using 'minikube service newservice -n <namespace>'. Or list out all the services using 'minikube service list': Temporary Error: Error getting service newservice: services "newservice" not found

how about making the format a bit nicer ? and get rid of the temporary error to the end user ? they don't need to see the temp error.

here is an example of using a template with exit

exit.WithCodeT(exit.IO, `minikube is unable to connect to the VM: {{.error}}

@rajula96reddy
Copy link
Member Author

Hey! Thank you for your feedback. I will try to improve the format as suggested.

@medyagh
Copy link
Member

medyagh commented Nov 6, 2019

FYI I created a new issue, #5846
this would be the next thing to do on Service refactor (not for this PR but next one)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rajula96reddy
To complete the pull request process, please assign medyagh
You can assign the PR to them by writing /assign @medyagh in a comment when ready.

The full list of commands accepted by this bot can be found 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

@rajula96reddy
Copy link
Member Author

Hey @medyagh! I formatted the error. Let me know what you think about it?

Also, I was trying to test my change and wanted to test the below case

serviceURL, err := GetServiceURLsForService(api, namespace, service, urlTemplate)
if err != nil {
return urlList, errors.Wrap(err, "Check that minikube is running and that you have specified the correct namespace")
}

But I wasn't able to reach this statement, as it was either getting caught in the earlier check or it is not throwing any error at all. Any idea, how to reach this statement?

I have also noticed that if minikube is not running, minikube service example-service command is not throwing out anything like


💣  command runner: getting ssh client for bootstrapper: Error dialing tcp via ssh client: dial tcp 127.0.0.1:54552: connect: connection refused

😿  Sorry that minikube crashed. If this was unexpected, we would love to hear from you:
👉  https://github.com/kubernetes/minikube/issues/new/choose

Is this behavior expected?

@RA489
Copy link

RA489 commented Nov 12, 2019

/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 12, 2019
@minikube-bot
Copy link
Collaborator

Error: building minikube at head: updating minikube master branch: running [git pull origin master] in /home/performance-monitor/minikube:
From https://github.com/kubernetes/minikube

  • branch master -> FETCH_HEAD
    error: Your local changes to the following files would be overwritten by merge:
    go.mod
    Please commit your changes or stash them before you merge.
    Aborting
    Updating 1d0ca6c..e611b38
    : exit status 1

@medyagh
Copy link
Member

medyagh commented Dec 11, 2019

@rajula96reddy I just wanted to see if you still have any questions on how to handle this PR ?

@minikube-bot
Copy link
Collaborator

All Times Minikube (PR 5844): [ 123.180857 122.815112 118.334852]
All Times minikube: [ 120.558695 116.922259 109.509355]

Average minikube: 115.663436
Average Minikube (PR 5844): 121.443607

Averages Time Per Log

+----------------------+-----------+--------------------+
|         LOG          | MINIKUBE  | MINIKUBE (PR 5844) |
+----------------------+-----------+--------------------+
| minikube v           |  0.321316 |           0.241735 |
| Creating kvm2        | 45.740124 |          45.792395 |
| Preparing Kubernetes | 44.908187 |          50.137522 |
| Pulling images       |  2.758694 |           3.090232 |
| Launching Kubernetes | 18.974369 |          19.247018 |
| Waiting for cluster  |  2.913272 |           2.890865 |
+----------------------+-----------+--------------------+

@rajula96reddy
Copy link
Member Author

Hey @medyagh. Can you review my latest commit?

Also, I wanted to ask if I should make changes for #5846 also in this PR only?

@medyagh
Copy link
Member

medyagh commented Dec 21, 2019

@rajula96reddy yes you could include this in this pr

@medyagh
Copy link
Member

medyagh commented Dec 21, 2019

Here is an example of using error types https://blog.golang.org/error-handling-and-go

@medyagh
Copy link
Member

medyagh commented Jan 13, 2020

@rajula96reddy are you still working on this ?

Copy link
Member

@medyagh medyagh left a comment

Choose a reason for hiding this comment

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

see comments

@@ -77,6 +77,10 @@ var serviceCmd = &cobra.Command{

urls, err := service.WaitForService(api, namespace, svc, serviceURLTemplate, serviceURLMode, https, wait, interval)
if err != nil {
if err.Error() == "Service not found in namespace" {
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this error a type ? Instead of string

And than have a functional called

IsErrorrSVCNotFound(err)
?

@@ -77,6 +77,10 @@ var serviceCmd = &cobra.Command{

urls, err := service.WaitForService(api, namespace, svc, serviceURLTemplate, serviceURLMode, https, wait, interval)
Copy link
Member

Choose a reason for hiding this comment

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

because getting list of ALL services is a very quick call,
First, get a list of services and then check if the service is in that list , if there isnt return quick,
then Seconly if the service exist, then wait for the service to be up !

@k8s-ci-robot k8s-ci-robot removed the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jan 14, 2020
@medyagh
Copy link
Member

medyagh commented Jan 22, 2020

@rajula96reddy are you still working on this ?

@medyagh medyagh reopened this Jan 22, 2020
@rajula96reddy
Copy link
Member Author

@medyagh Yes! I have made changes to my commit couple of days back (5ac578b) & I am awaiting your review on the same.

@minikube-pr-bot
Copy link

All Times minikube: [ 100.438152 95.368815 92.722641]
All Times Minikube (PR 5844): [ 124.317613 126.464113 115.632643]

Average minikube: 96.176536
Average Minikube (PR 5844): 122.138123

Averages Time Per Log

+----------------------+-----------+--------------------+
|         LOG          | MINIKUBE  | MINIKUBE (PR 5844) |
+----------------------+-----------+--------------------+
| minikube v           |  0.297793 |           0.324520 |
| Creating kvm2        | 19.779730 |          47.206725 |
| Preparing Kubernetes | 49.817024 |          47.181363 |
| Pulling images       |  3.624858 |           2.949342 |
| Launching Kubernetes | 18.988780 |          19.495113 |
| Waiting for cluster  |  2.395348 |           2.894473 |
+----------------------+-----------+--------------------+

@rajula96reddy rajula96reddy requested a review from medyagh January 27, 2020 06:50
@medyagh
Copy link
Member

medyagh commented Jan 28, 2020

@rajula96reddy
Copy link
Member Author

@medyagh Sorry for that. Let me check the test failures. Thanks!

@rajula96reddy
Copy link
Member Author

@medyagh I have corrected the issue. Sorry, it was because I was trying to #5846 by calling the wrong function. It's resolved now. Can you please take a look & give your feedback? Thank you!

@minikube-pr-bot
Copy link

All Times Minikube (PR 5844): [ 97.375983 95.940267 96.675498]
All Times minikube: [ 96.914335 100.220012 98.540137]

Average minikube: 98.558162
Average Minikube (PR 5844): 96.663916

Averages Time Per Log

+----------------------+-----------+--------------------+
|         LOG          | MINIKUBE  | MINIKUBE (PR 5844) |
+----------------------+-----------+--------------------+
| minikube v           |  0.311744 |           0.296857 |
| Creating kvm2        | 20.190853 |          19.897212 |
| Preparing Kubernetes | 50.718608 |          50.011045 |
| Pulling images       |  4.072735 |           4.002056 |
| Launching Kubernetes | 20.526796 |          19.766602 |
| Waiting for cluster  |  1.078027 |           1.081082 |
+----------------------+-----------+--------------------+

Copy link
Contributor

@tstromberg tstromberg left a comment

Choose a reason for hiding this comment

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

Looks ready to merge other than one nit.

cmd/minikube/cmd/service.go Outdated Show resolved Hide resolved
@minikube-pr-bot
Copy link

All Times minikube: [ 96.702800 94.278517 90.986860]
All Times Minikube (PR 5844): [ 91.670269 95.138358 91.838445]

Average minikube: 93.989392
Average Minikube (PR 5844): 92.882357

Averages Time Per Log

+----------------------+-----------+--------------------+
|         LOG          | MINIKUBE  | MINIKUBE (PR 5844) |
+----------------------+-----------+--------------------+
| minikube v           |  0.191398 |           0.212668 |
| Creating kvm2        | 21.193625 |          19.914098 |
| Preparing Kubernetes | 49.221663 |          50.848176 |
| Pulling images       |           |                    |
| Launching Kubernetes | 21.345468 |          19.985958 |
| Waiting for cluster  |  0.417006 |           0.048281 |
+----------------------+-----------+--------------------+

@medyagh medyagh closed this Mar 7, 2020
@medyagh medyagh reopened this Mar 7, 2020
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 7, 2020
@medyagh
Copy link
Member

medyagh commented Mar 7, 2020

@rajula96reddy we could merge this if u could please rebase

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 7, 2020
@rajula96reddy
Copy link
Member Author

@medyagh Thanks for the feedback. I rebased as requested. Can you please confirm the same & proceed accordingly? Thanks!

@tstromberg
Copy link
Contributor

Thank you!

@tstromberg tstromberg merged commit 6954549 into kubernetes:master Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants