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

TranslateIngress changes #275

Merged
merged 1 commit into from
May 18, 2018
Merged

Conversation

nicksardo
Copy link
Contributor

Changes

  • Stop gracefully falling back on system default backend if specified backend is not found - no longer need EventRecorder in translater
  • Return list of errors from TranslateIngress
  • ensureIngress will error if TranslateIngress hits any errors. ToSvcPorts iterates all ingresses (for now) and will continue to collect all known service ports
  • Deleted a lot of tests in controller_test.go. Some of them should be re-created in different packages (tests that check GCE resource config), and new tests should be made for the controller that assert controller logic such as garbage collection, k8s object lifecycle edge cases.
  • Re-wrote tests for controller and created tests for TranslateIngress.

@nicksardo nicksardo requested review from MrHohn and rramkumar1 May 18, 2018 18:13
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 18, 2018
@nicksardo nicksardo force-pushed the controller branch 4 times, most recently from 3577266 to 19fed83 Compare May 18, 2018 18:30
@@ -150,6 +152,19 @@ func trimFieldsEvenly(max int, fields ...string) []string {
return ret
}

// PrettyJson marshals an object in a human-friendly format.
func PrettyJson(data interface{}) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something, but this doesn't seem to be used anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, but is a useful func to exist when we need to add more tests.

return &GCEURLMap{HostRules: make(map[string][]PathRule)}
}

func EqualStructure(a, b *GCEURLMap) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call this Compare() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's only checking ServiceProjectID and Compare makes it sound like it's a full ServicePort check.

}
}

// DecodeIngress returns deserializes an Ingress from yaml.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove "returns" from comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

// hostRules is a mapping from hostnames to path rules for that host.
hostRules map[string][]PathRule
HostRules map[string][]PathRule
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for exposing the host rules? I left them package private so that we never access it without using the public getter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't have an immediate need. Was a little confused why AllRules() is used over HostRules. I have no strong opinion on this... will make it private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, actually, we need exported for serializing/deserializing into JSON.

Copy link
Contributor

Choose a reason for hiding this comment

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

Damn, okay. Let's get rid of AllRules() then too and just replace that with direct access.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

for _, pathRule := range pathRules {
if _, ok := uniquePaths[pathRule.Path]; ok {
glog.V(4).Infof("Equal paths (%v) for host %v. Using backend %+v", pathRule.Path, hostname, pathRule.Backend)
seen := make(map[string]struct{})
Copy link
Contributor

Choose a reason for hiding this comment

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

can the value for this just be a bool? Might read a little better.

@@ -68,6 +63,127 @@ func fakeTranslator(negEnabled bool) *Translator {
return gce
}

func ingressFromFile(filename string) *extensions.Ingress {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can we move these helpers to the bottom of the file? I don't like them being the first thing I see when I open the file :)

return v
}

func TestTranslateIngress(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job on this test, looks awesome. One thing I would like to see is maybe a case that results in 2 or more errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SG

func TestLbCreateDelete(t *testing.T) {
testFirewallName := "quux"
cm := NewFakeClusterManager(flags.DefaultClusterUID, testFirewallName)
func TestIngressSyncError(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a small comment to this test that is a little more descriptive than the function name itself? Same for other tests as well.

@rramkumar1
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 18, 2018
@nicksardo nicksardo merged commit 5642218 into kubernetes:master May 18, 2018
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants