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 utils for retrieving backendconfigs for service (and reversely) #252

Merged
merged 2 commits into from
May 11, 2018

Conversation

MrHohn
Copy link
Member

@MrHohn MrHohn commented May 7, 2018

@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 May 7, 2018

// GetServicesForBackendConfig returns all services that reference the given
// BackendConfig.
func GetServicesForBackendConfig(svcLister cache.Store, backendConfig *backendconfigv1alpha1.BackendConfig) []*apiv1.Service {
Copy link
Member Author

Choose a reason for hiding this comment

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

Planing to plug this to trigger Ingress sync.


// GetBackendConfigForServicePort returns the corresponding BackendConfig for
// the given ServicePort if specified.
func GetBackendConfigForServicePort(backendConfigLister cache.Store, svc *apiv1.Service, svcPort *apiv1.ServicePort) (*backendconfigv1alpha1.BackendConfig, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Planing to plug this into servicePort():

func servicePort(ib v1beta1.IngressBackend, svc v1.Service) (ServicePort, error) {
// If service is not of type NodePort, return an error.
if svc.Spec.Type != v1.ServiceTypeNodePort {
return ServicePort{}, fmt.Errorf("service %v/%v for backend %+v is type %v, expected type NodePort", svc.Namespace, svc.Name, ib, svc.Spec.Type)
}
appProtocols, err := annotations.FromService(&svc).ApplicationProtocols()
if err != nil {
return ServicePort{}, err
}
var port *v1.ServicePort
PortLoop:
for _, p := range svc.Spec.Ports {
np := p
switch ib.ServicePort.Type {
case intstr.Int:
if p.Port == ib.ServicePort.IntVal {
port = &np
break PortLoop
}
default:
if p.Name == ib.ServicePort.StrVal {
port = &np
break PortLoop
}
}
}
if port == nil {
return ServicePort{}, fmt.Errorf("could not find matching port on service %v/%v for backend %+v. Looking for port %+v in %v", svc.Namespace, ib.ServiceName, ib, ib.ServicePort, svc.Spec.Ports)
}
proto := annotations.ProtocolHTTP
if protoStr, exists := appProtocols[port.Name]; exists {
glog.V(2).Infof("service %v/%v, port %q: using protocol to %q", svc.Namespace, ib.ServiceName, port, protoStr)
proto = annotations.AppProtocol(protoStr)
}
p := ServicePort{
NodePort: int64(port.NodePort),
Protocol: proto,
SvcName: types.NamespacedName{Namespace: svc.Namespace, Name: ib.ServiceName},
SvcPort: ib.ServicePort,
}
return p, nil
}
.

@rramkumar1
Copy link
Contributor

rramkumar1 commented May 11, 2018

/lgtm
Leaving to @nicksardo for approval.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 11, 2018
@nicksardo nicksardo merged commit c17a42f into kubernetes:master May 11, 2018
@MrHohn
Copy link
Member Author

MrHohn commented May 11, 2018

Thanks for the review!

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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants