-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Refactor to remove opening browser and just return url(s) #5718
Refactor to remove opening browser and just return url(s) #5718
Conversation
Hi @nanikjava. 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 Once the patch is verified, the new status will be reflected by the 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. |
Can one of the admins verify this patch? |
Codecov Report
@@ Coverage Diff @@
## master #5718 +/- ##
==========================================
- Coverage 37.83% 37.78% -0.05%
==========================================
Files 106 106
Lines 7773 7780 +7
==========================================
- Hits 2941 2940 -1
- Misses 4452 4461 +9
+ Partials 380 379 -1
|
pkg/minikube/service/service.go
Outdated
@@ -267,7 +267,7 @@ func PrintServiceList(writer io.Writer, data [][]string) { | |||
|
|||
// WaitAndMaybeOpenService waits for a service, and opens it when running | |||
func WaitAndMaybeOpenService(api libmachine.API, namespace string, service string, urlTemplate *template.Template, urlMode bool, https bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WaitAndMaybeOpenService already has too many arguments, let's not add another.
How about removing the browser.OpenURL
call altogether, and leaving that up to cmd/service.go
to handle. Then this function could be renamed to a more definite WaitForService
, and be more testable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with tstromberg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Will make the changes
f4e2c7b
to
2a2ee37
Compare
2a2ee37
to
8e36c45
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactor looks great. Just a few minor suggestions for clarity. Thank you for doing this.
pkg/minikube/service/service.go
Outdated
// WaitAndMaybeOpenService waits for a service, and opens it when running | ||
func WaitAndMaybeOpenService(api libmachine.API, namespace string, service string, urlTemplate *template.Template, urlMode bool, https bool, | ||
wait int, interval int) error { | ||
// WaitForService waits for a service, and opens it when running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make comment accurate again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method no longer opens a URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment has been updated to reflect returning url instead of opening in browser. PR title has been modified too.
serviceURLTemplate, serviceURLMode, https, wait, interval) | ||
if err != nil { | ||
exit.WithError("Error opening service", err) | ||
} | ||
|
||
if len(urlString) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WaitAndMaybeOpenService
had the following logic for opening a URL:
if urlMode || !isHTTPSchemedURL {
Make sure your PR preserves the same behavior as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code that you are referring to is inside pkg/minikube/service/service.go and the only changes made was to send back the array of urls
pkg/minikube/service/service.go
Outdated
func WaitForService(api libmachine.API, namespace string, service string, urlTemplate *template.Template, urlMode bool, https bool, | ||
wait int, interval int) (string, error) { | ||
|
||
var urlString string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just url
is fine as a variable name. It generally isn't useful to repeat the type of an object in the object name.
See also https://github.com/golang/go/wiki/CodeReviewComments#variable-names
pkg/minikube/service/service_test.go
Outdated
@@ -903,12 +903,12 @@ func TestWaitAndMaybeOpenService(t *testing.T) { | |||
servicesMap: serviceNamespaces, | |||
endpointsMap: endpointNamespaces, | |||
} | |||
err := WaitAndMaybeOpenService(test.api, test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0) | |||
_, err := WaitForService(test.api, test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns a URL now - please test the returned value of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tstromberg Want to bounce some thoughts. In master branch the current implementation is
for _, bareURLString := range serviceURL.URLs {
urlString, isHTTPSchemedURL := OptionallyHTTPSFormattedURLString(bareURLString, https)
if urlMode || !isHTTPSchemedURL {
out.T(out.Empty, urlString)
} else {
out.T(out.Celebrate, "Opening kubernetes service {{.namespace_name}}/{{.service_name}} in default browser...", out.V{"namespace_name": namespace, "service_name": service})
if err := browser.OpenURL(urlString); err != nil {
out.ErrT(out.Empty, "browser failed to open url: {{.error}}", out.V{"error": err})
}
}
}
which means that there is possibility that there are more than 1 url, so is it correct to also
implement string array as the returned value ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After going through the code and the functionality the function will have to return array of url. So have made changes to both the code and test cases.
pkg/util/utils.go
Outdated
@@ -200,3 +202,9 @@ func ConcatStrings(src []string, prefix string, postfix string) []string { | |||
} | |||
return ret | |||
} | |||
|
|||
func OpenBrowser(urlString string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't add ta lot of value, so just remove it and inline the code instead. The only thing really duplicated is the error message.
Also, we're trying to get rid of unscoped packages like the util
package.
cmd/minikube/cmd/service.go
Outdated
|
||
if len(urlString) != 0 { | ||
out.T(out.Celebrate, "Opening kubernetes service {{.namespace_name}}/{{.service_name}} in default browser...", out.V{"namespace_name": namespace, "service_name": svc}) | ||
util.OpenBrowser(urlString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If opening the browser fails, call exit.WithError
/ok-to-test |
8e36c45
to
8a88e86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix PR title and description to reflect the most recent changes. Looks mergeable otherwise.
pkg/minikube/service/service.go
Outdated
// WaitAndMaybeOpenService waits for a service, and opens it when running | ||
func WaitAndMaybeOpenService(api libmachine.API, namespace string, service string, urlTemplate *template.Template, urlMode bool, https bool, | ||
wait int, interval int) error { | ||
// WaitForService waits for a service, and opens it when running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method no longer opens a URL.
The WaitAndMaybeOpenService(..) method allow user to open the service url in a browser when found, this create issue during testing as it's opening browser and consuming resources. The fix is to introduce a boolean flag allowing the caller to specify whether to just print out the url or open a browser window
8a88e86
to
994d093
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: nanikjava 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 |
Thank you for sticking through with the review process! |
No worries. Thanks for being patience in reviewing my PRs, still learning :) |
The WaitAndMaybeOpenService(..) method allow user to open the service
url in a browser when found, this create issue during testing as it's
opening browser and consuming resources.
The fix is to introduce a boolean flag allowing the caller to specify
whether to just print out the url or open a browser window