-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
gateway: fix the dns discovery method #7454
Conversation
d272f4a
to
8b16946
Compare
@@ -77,6 +78,23 @@ func newGatewayStartCommand() *cobra.Command { | |||
return &cmd | |||
} | |||
|
|||
func stripSchema(eps []string) []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.
Can you add unit tests for this function? I would like to increase the etcd coverage.
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 discovery stuff should eventually be covered by e2e tests; I don't think a unit test is necessary here
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.
@bdudelsack heyitsanthony is right about not having the unit test. The test path should be covered in e2e test where the correct behavior gateway should be verified. Sorry for the wrong suggestion.
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.
looks OK in general
etcdmain/gateway.go
Outdated
|
||
for _, ep := range eps { | ||
|
||
if strings.HasPrefix(ep, "https://") { |
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.
use the url library instead?
if u, err := url.Parse(ep); err != nil {
ep = u.Host
}
endpoints = append(endpoints, ep)
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.
I wanted it to be general and parse the endpoints passed by "--endpoints" param too. I think it could be a common mistake to add "http://" or "https://" to that parameter.
I could use the url library, but then parse only the endpoints which come from the dns discovery, or use this method for both. I don't think url method would work with correct hostnames like "etcd-node:2379" without further checks.
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.
Oh, sorry. I meant:
if u, err := url.Parse(ep); err == nil {
ep = u.Host
}
endpoints = append(endpoints, ep)
It'll strip the schema off a valid url and leave anything else (e.g., etcd-node:2379) alone.
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.
url.Parse
seems to treat it like a relative path, so my tests are failing:
func stripSchema(eps []string) []string {
var endpoints []string
for _, ep := range eps {
if u, err := url.Parse(ep); err == nil {
ep = u.Host
}
endpoints = append(endpoints, ep)
}
return endpoints
}
--- FAIL: TestStripSchema (0.00s)
gateway_test.go:24: Expected stripSchema to return 'etcd-node:2379' from 'etcd-node:2379' but got ''
gateway_test.go:24: Expected stripSchema to return 'etcd-node' from 'etcd-node' but got ''
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.
OK, so if u, err := url.Parse(ep); err == nil && u.Host != ""
?
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.
That would work 👌
etcdmain/gateway.go
Outdated
@@ -24,6 +24,7 @@ import ( | |||
"github.com/coreos/etcd/pkg/transport" | |||
"github.com/coreos/etcd/proxy/tcpproxy" | |||
"github.com/spf13/cobra" | |||
"strings" |
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.
standard library packages (e.g., net, os, strings) should be group together at the beginning of the import
8b16946
to
ce968ee
Compare
etcdmain/gateway_test.go
Outdated
@@ -0,0 +1,27 @@ | |||
package etcdmain |
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.
I don't think this test is necessary...
ce968ee
to
e317664
Compare
d05dca3
to
4ec1a42
Compare
Build failed couse of
|
strip the scheme from the endpoints to have a clean hostname for TCP proxy Fixes etcd-io#7452
4ec1a42
to
0d48fc5
Compare
lgtm Thanks! |
strip the scheme from the endpoints to have a clean hostname for TCP proxy
Fixes #7452