Merge pull request #212 from aledbf/udp-services
Simplify code to obtain TCP or UDP services
This commit is contained in:
commit
2b4a044d21
1 changed files with 12 additions and 35 deletions
|
@ -390,8 +390,8 @@ func (ic *GenericController) sync(key interface{}) error {
|
||||||
data, err := ic.cfg.Backend.OnUpdate(ingress.Configuration{
|
data, err := ic.cfg.Backend.OnUpdate(ingress.Configuration{
|
||||||
Backends: upstreams,
|
Backends: upstreams,
|
||||||
Servers: servers,
|
Servers: servers,
|
||||||
TCPEndpoints: ic.getTCPServices(),
|
TCPEndpoints: ic.getStreamServices(ic.cfg.TCPConfigMapName, api.ProtocolTCP),
|
||||||
UPDEndpoints: ic.getUDPServices(),
|
UPDEndpoints: ic.getStreamServices(ic.cfg.UDPConfigMapName, api.ProtocolUDP),
|
||||||
PassthroughBackends: passUpstreams,
|
PassthroughBackends: passUpstreams,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -411,54 +411,31 @@ func (ic *GenericController) sync(key interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ic *GenericController) getTCPServices() []*ingress.Location {
|
func (ic *GenericController) getStreamServices(configmapName string, proto api.Protocol) []*ingress.Location {
|
||||||
if ic.cfg.TCPConfigMapName == "" {
|
if configmapName == "" {
|
||||||
// no configmap for TCP services
|
// no configmap configured
|
||||||
return []*ingress.Location{}
|
return []*ingress.Location{}
|
||||||
}
|
}
|
||||||
|
|
||||||
ns, name, err := k8s.ParseNameNS(ic.cfg.TCPConfigMapName)
|
ns, name, err := k8s.ParseNameNS(configmapName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("%v", err)
|
glog.Errorf("unexpected error reading configmap %v: %v", name, err)
|
||||||
return []*ingress.Location{}
|
return []*ingress.Location{}
|
||||||
}
|
}
|
||||||
tcpMap, err := ic.getConfigMap(ns, name)
|
|
||||||
|
configmap, err := ic.getConfigMap(ns, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(5).Infof("no configured tcp services found: %v", err)
|
glog.Errorf("unexpected error reading configmap %v: %v", name, err)
|
||||||
return []*ingress.Location{}
|
return []*ingress.Location{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ic.getStreamServices(tcpMap.Data, api.ProtocolTCP)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ic *GenericController) getUDPServices() []*ingress.Location {
|
|
||||||
if ic.cfg.UDPConfigMapName == "" {
|
|
||||||
// no configmap for TCP services
|
|
||||||
return []*ingress.Location{}
|
|
||||||
}
|
|
||||||
|
|
||||||
ns, name, err := k8s.ParseNameNS(ic.cfg.UDPConfigMapName)
|
|
||||||
if err != nil {
|
|
||||||
glog.Warningf("%v", err)
|
|
||||||
return []*ingress.Location{}
|
|
||||||
}
|
|
||||||
tcpMap, err := ic.getConfigMap(ns, name)
|
|
||||||
if err != nil {
|
|
||||||
glog.V(3).Infof("no configured tcp services found: %v", err)
|
|
||||||
return []*ingress.Location{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ic.getStreamServices(tcpMap.Data, api.ProtocolUDP)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ic *GenericController) getStreamServices(data map[string]string, proto api.Protocol) []*ingress.Location {
|
|
||||||
var svcs []*ingress.Location
|
var svcs []*ingress.Location
|
||||||
// k -> port to expose
|
// k -> port to expose
|
||||||
// v -> <namespace>/<service name>:<port from service to be used>
|
// v -> <namespace>/<service name>:<port from service to be used>
|
||||||
for k, v := range data {
|
for k, v := range configmap.Data {
|
||||||
_, err := strconv.Atoi(k)
|
_, err := strconv.Atoi(k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("%v is not valid as a TCP port", k)
|
glog.Warningf("%v is not valid as a TCP/UDP port", k)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue