-
Notifications
You must be signed in to change notification settings - Fork 303
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
Add ability to change prefix in the Namer #74
Conversation
bowei
commented
Nov 7, 2017
- This allows the multicluster code to share use of the Namer.
- Add more unit testing
- Coverage is now ~90% of namer code.
sslCertPrefix = "k8s-ssl" | ||
targetHTTPProxyPrefix = "tp" | ||
targetHTTPSProxyPrefix = "tps" | ||
sslCertPrefix = "ssl" | ||
// TODO: this should really be "fr" and "frs". |
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.
Doesnt firewall rule use "fr"?
This is great! thx, lgtm |
fixing the test failure related to instance groups |
The second patch is a little large but it's basically making all of the unit tests and fakes use the Namer consistently. |
@@ -36,16 +36,6 @@ const ( | |||
defaultPort = 80 | |||
defaultHealthCheckPath = "/" | |||
|
|||
// A backend is created per nodePort, tagged with the nodeport. |
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.
Love this change!
pkg/controller/controller_test.go
Outdated
@@ -50,7 +50,7 @@ var ( | |||
|
|||
// TODO: Use utils.Namer instead of this function. | |||
func defaultBackendName(clusterName string) string { | |||
return fmt.Sprintf("%v-%v", backendPrefix, clusterName) | |||
return fmt.Sprintf("%v-%v", "k8s-be", clusterName) // backendPrefix, clusterName) XXX |
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.
XXX is intentional? :)
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.
Also dont like "k8s-be" being hardcoded here.
Remove this method altogether to use Namer?
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.
yes, this needs to be fixed
@@ -54,7 +54,7 @@ func TestHealthCheckAdd(t *testing.T) { | |||
} | |||
|
|||
func TestHealthCheckAddExisting(t *testing.T) { | |||
namer := &utils.Namer{} | |||
namer := utils.NewNamer("uid1", "fw1") |
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.
Maybe define a utils.NewTestNamer() rather than duplicating "uid1", "fw1" it in all these tests?
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.
You can define it one of the fakes.go?
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.
ping, what do you think of instantiating once and reusing in all?
@@ -202,7 +202,7 @@ func TestHealthCheckDeleteLegacy(t *testing.T) { | |||
} | |||
|
|||
func TestAlphaHealthCheck(t *testing.T) { | |||
namer := &utils.Namer{} | |||
namer := utils.NewNamer("uid1", "fw1") |
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.
Do these really need a separate instance?
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 see instances_test.go uses a single instance in all test cases. This uses separate. Lets be consistent.
Instantiate once and reuse it in all tests
pkg/loadbalancers/fakes.go
Outdated
@@ -18,6 +18,8 @@ package loadbalancers | |||
|
|||
import ( | |||
"fmt" | |||
"github.com/golang/glog" | |||
"testing" |
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.
No!!!!
This is reverting #69. Please fix
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 we move the method to the test or a different package?
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.
Moving the method to test is fine by me. As long as non test code does not depend on testing.
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.
Quite funny I think I exactly reverted the change.
lbInfo := &L7RuntimeInfo{ | ||
Name: "test", |
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.
Do things break without this change?
Seems like you have fixed all the instances. We can keep things simple where a namer generated name is not required?
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.
Things do break and the inconsistent use of names is quite problematic.
@nikhiljindal -- took care of most of the comments. Some of the test clean I'm going to put in a follow on, the change is getting somewhat large. |
@@ -48,9 +48,8 @@ var ( | |||
testIPManager = testIP{} | |||
) | |||
|
|||
// TODO: Use utils.Namer instead of this function. |
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.
Why remove the TODO? It still seems relevant.
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.
It isn't actually a Namer resource (it is not a GCP resource). The comment is incorrect.
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 got it, thx!
func defaultBackendName(clusterName string) string { | ||
return fmt.Sprintf("%v-%v", backendPrefix, clusterName) | ||
return fmt.Sprintf("%v-%v", "k8s-be", clusterName) |
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.
(repeat of previous comment). Do not hardcode this here and reuse namer method?
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.
See comment above.
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, resolved.
@@ -202,7 +202,7 @@ func TestHealthCheckDeleteLegacy(t *testing.T) { | |||
} | |||
|
|||
func TestAlphaHealthCheck(t *testing.T) { | |||
namer := &utils.Namer{} | |||
namer := utils.NewNamer("uid1", "fw1") |
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 see instances_test.go uses a single instance in all test cases. This uses separate. Lets be consistent.
Instantiate once and reuse it in all tests
@@ -54,7 +54,7 @@ func TestHealthCheckAdd(t *testing.T) { | |||
} | |||
|
|||
func TestHealthCheckAddExisting(t *testing.T) { | |||
namer := &utils.Namer{} | |||
namer := utils.NewNamer("uid1", "fw1") |
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.
ping, what do you think of instantiating once and reusing in all?
pkg/loadbalancers/fake/fakes.go
Outdated
@@ -14,14 +14,18 @@ See the License for the specific language governing permissions and | |||
limitations under the License. | |||
*/ | |||
|
|||
package loadbalancers | |||
// Package fake contains fakes for loadbalancer. | |||
package fake |
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.
Keep package name and file name consistent. Call them both fakes?
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.
done
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and | |||
limitations under the License. | |||
*/ | |||
|
|||
package loadbalancers | |||
package loadbalancers_test |
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.
Sorry not sure why is this a separate package? Unit tests are supposed to be in the same package.
If you are really moving to a separate package, then also move this to a different directory with the package name.
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 there is actually a hard and fast rule about keeping the tests in the same package. (test via the front door). I hesitate to create a package just for the test.
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.
Actually, let me see why I did that originally. Maybe it was a leftover from a different attempt to clean up
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, the problem is this:
- fakes imports loadbalancers
- the test depends on fakes.
import cycle.
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.
Agreed that there is not a hard and fast rule, but it is preferred so that you dont have to expose private members outside the package, just for unit tests.
The problem here is that fakes imports testing, which is not usual.
All of this seems like a hack just to be able to pass t to CheckURLMap and I am not convinced why do you want to do that. Why not let CheckURLMap return an error and handle it appropriately in tests (as it does now). You wont need separate fake and loadbalancer_tests packages then (we can still keep the fake package if we want, but it wont necessarily be required). Reverting that change will make this PR a lot simpler and focused only on the namer change.
What do you think?
pkg/loadbalancers/fakes.go
Outdated
@@ -38,46 +40,46 @@ func (t *testIP) ip() string { | |||
|
|||
// Loadbalancer fakes | |||
|
|||
// FakeLoadBalancers is a type that fakes out the loadbalancer interface. | |||
// LoadBalancers is a type that fakes out the loadbalancer interface. |
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 mismatches with code
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.
fixed
pkg/loadbalancers/fakes.go
Outdated
type FakeLoadBalancers struct { | ||
Fw []*compute.ForwardingRule | ||
Um []*compute.UrlMap | ||
Tp []*compute.TargetHttpProxy | ||
Tps []*compute.TargetHttpsProxy | ||
IP []*compute.Address | ||
Certs []*compute.SslCertificate | ||
name string | ||
calls []string // list of calls that were made | ||
Name 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.
All these changes in this file seem like leftover from when the tests were not in same package and hence you had to export them. You dont need to export them anymore?
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'll change it back, but there shouldn't really be any issue with exporting stuff out of the fake...
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.
fixed
d1dcc42
to
fc59532
Compare
Thanks for all the fixes! |
unit test failures are legit:
|
hmm -- strange, thought I fixed all of the call sites, fixing |
- This allows the multicluster code to share use of the Namer. - Add more unit testing - Increases coverage of the namer code.
should be fixed now |