-
Notifications
You must be signed in to change notification settings - Fork 301
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
Conversation
|
||
// GetServicesForBackendConfig returns all services that reference the given | ||
// BackendConfig. | ||
func GetServicesForBackendConfig(svcLister cache.Store, backendConfig *backendconfigv1alpha1.BackendConfig) []*apiv1.Service { |
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.
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) { |
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.
Planing to plug this into servicePort()
:
ingress-gce/pkg/backends/utils.go
Lines 50 to 95 in 16d4f39
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 | |
} |
/lgtm |
Thanks for the review! |
/assign @rramkumar1 @nicksardo
cc @bowei