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

Integrate ClusterServiceMapper into translator. #223

Merged
merged 1 commit into from
Apr 18, 2018

Conversation

rramkumar1
Copy link
Contributor

@rramkumar1 rramkumar1 commented Apr 17, 2018

Extracts ServicePort logic out of translator using the new ClusterServiceMapper implementation. Also adds tests for untested code paths.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 17, 2018
@rramkumar1 rramkumar1 force-pushed the use-cluster-service-mapper branch 2 times, most recently from eb595a7 to a48f71b Compare April 17, 2018 21:22
@rramkumar1
Copy link
Contributor Author

/retest

@rramkumar1
Copy link
Contributor Author

/assign @nicksardo

@rramkumar1 rramkumar1 changed the title Integrate ClusterServiceMapper into translator. [WIP] Integrate ClusterServiceMapper into translator. Apr 17, 2018
@rramkumar1
Copy link
Contributor Author

/retest

@@ -242,7 +248,14 @@ func (lbc *LoadBalancerController) sync(key string) (retErr error) {
}

// gceNodePorts contains the ServicePorts used by only single-cluster ingress.
gceNodePorts := lbc.Translator.ToNodePorts(&gceIngresses)
gceNodePorts := make([]backends.ServicePort, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: var gceNodePorts []backends.ServicePort

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

@@ -441,3 +465,11 @@ func updateAnnotations(client kubernetes.Interface, name, namespace string, anno
}
return nil
}

func extractSvcPorts(svcPortMapping map[extensions.IngressBackend]backends.ServicePort) []backends.ServicePort {
svcPorts := make([]backends.ServicePort, 0)
Copy link
Contributor

@nicksardo nicksardo Apr 18, 2018

Choose a reason for hiding this comment

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

same nit as above. Can also name the return and immediately append to it.

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, named the return.

@@ -282,7 +295,18 @@ func (lbc *LoadBalancerController) sync(key string) (retErr error) {
}

func (lbc *LoadBalancerController) ensureIngress(key string, ing *extensions.Ingress, nodeNames []string, gceNodePorts []backends.ServicePort) error {
ingNodePorts := lbc.Translator.IngressToNodePorts(ing)
// svcPortMapping is reused by the Translator in ToURLMap()
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you change this comment to explain what the mapping is instead of where else it's used.
i.e. Given an ingress, returns a mapping of K8s Service name/port -> backends.ServicePort.

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.

msg := fmt.Sprintf("%v", e)
lbc.ctx.Recorder(ing.Namespace).Eventf(ing, apiv1.EventTypeWarning, "Service", msg)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, would be nicer to show that code can handle non-multierror case. Maybe a type switch with a default case?

Copy link
Contributor Author

@rramkumar1 rramkumar1 Apr 18, 2018

Choose a reason for hiding this comment

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

Done. Left a TODO for myself to clean that error handling code up.

if err != nil {
return fmt.Errorf("convert to URL Map error %v", err)
return fmt.Errorf("convert to URL Map error: %v", err)
Copy link
Contributor

@nicksardo nicksardo Apr 18, 2018

Choose a reason for hiding this comment

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

While you're at it, could you change this to "error converting to URLMap: %v"

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. I assume you want to change it for the ones below as well so I fixed those too.

type ErrNodePortNotFound struct {
Backend v1beta1.IngressBackend
Err error
}
Copy link
Contributor

@nicksardo nicksardo Apr 18, 2018

Choose a reason for hiding this comment

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

Why don't we want/need these anymore? Not necessary to make structs with internal data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After these changes, they won't be used anymore. I don't think they are necessary but I'm fine with leaving them around. Just figured we could delete code that isn't being used.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine then.

return &GCE{
recorders,
namer,
svcLister,
nodeLister,
podLister,
endpointLister,
svcMapper,
Copy link
Contributor

Choose a reason for hiding this comment

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

So you're making the mapper apart of controller context so we can update it from the MCI event handlers/goroutines, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't thought about how the best way to do it is yet but yes, something of that nature :)

// So keep requeuing the l7 till all backends exist.
return utils.GCEURLMap{}, err
// Get the corresponding ServicePort for this backend.
svcPort, ok := svcPorts[p.Backend]
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome

t.recorders.Recorder(ing.Namespace).Eventf(ing, api_v1.EventTypeNormal, "Service", msg)
svcPort, ok := svcPorts[*ing.Spec.Backend]
if ok {
defaultBackendName = t.namer.Backend(svcPort.NodePort)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment explaining what happens in the !ok case.

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. Not sure if the comment I added is 100% true so PTAL.

func TestToURLMap(t *testing.T) {
ing, err := test.GetTestIngress("../../test/manifests/ing1.yaml")
if err != nil {
t.Errorf("Error occured when getting test Ingress: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fatal

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.

if err != nil {
t.Errorf("Error occured when constructing test Ingress: %v", err)
t.Errorf("Error occured when getting test Ingress: %v", err)
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Also fatal

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.

@nicksardo
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 Apr 18, 2018
@nicksardo nicksardo merged commit 11ff79f into kubernetes:mci-dev Apr 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/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.

3 participants