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

Add ability to change prefix in the Namer #74

Merged
merged 1 commit into from
Dec 5, 2017
Merged

Conversation

bowei
Copy link
Member

@bowei 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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 7, 2017
sslCertPrefix = "k8s-ssl"
targetHTTPProxyPrefix = "tp"
targetHTTPSProxyPrefix = "tps"
sslCertPrefix = "ssl"
// TODO: this should really be "fr" and "frs".
Copy link
Contributor

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"?

@nikhiljindal
Copy link
Contributor

This is great! thx, lgtm

@bowei
Copy link
Member Author

bowei commented Nov 7, 2017

fixing the test failure related to instance groups

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 9, 2017
@bowei
Copy link
Member Author

bowei commented Nov 9, 2017

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Love this change!

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

XXX is intentional? :)

Copy link
Contributor

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?

Copy link
Member Author

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")
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor

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")
Copy link
Contributor

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?

Copy link
Contributor

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

@@ -18,6 +18,8 @@ package loadbalancers

import (
"fmt"
"github.com/golang/glog"
"testing"
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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",
Copy link
Contributor

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?

Copy link
Member Author

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.

@bowei
Copy link
Member Author

bowei commented Nov 28, 2017

@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.
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

See comment above.

Copy link
Contributor

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")
Copy link
Contributor

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")
Copy link
Contributor

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?

@@ -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
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member Author

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.

Copy link
Contributor

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?

@nikhiljindal
Copy link
Contributor

cc @G-Harmon @csbell

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment mismatches with code

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

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
Copy link
Contributor

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?

Copy link
Member Author

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...

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@bowei bowei force-pushed the namer branch 2 times, most recently from d1dcc42 to fc59532 Compare December 5, 2017 21:41
@nikhiljindal
Copy link
Contributor

Thanks for all the fixes!
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 5, 2017
@nikhiljindal
Copy link
Contributor

unit test failures are legit:

pkg/loadbalancers/loadbalancers_test.go:415:24: f.Calls undefined (type *FakeLoadBalancers has no field or method Calls, but does have calls)
pkg/loadbalancers/loadbalancers_test.go:470:3: f.Name undefined (type *FakeLoadBalancers has no field or method Name, but does have name)

@bowei
Copy link
Member Author

bowei commented Dec 5, 2017

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.
@bowei
Copy link
Member Author

bowei commented Dec 5, 2017

should be fixed now

@bowei bowei merged commit 2c86681 into kubernetes:master Dec 5, 2017
@bowei bowei deleted the namer branch December 5, 2017 22:23
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants