Merge pull request #133 from aledbf/fix-tcp-stream
Add TCP and UDP services removed in migration
This commit is contained in:
commit
0ed8260704
3 changed files with 51 additions and 2 deletions
|
@ -138,6 +138,7 @@ var (
|
|||
"buildSSPassthroughUpstreams": buildSSPassthroughUpstreams,
|
||||
"buildResolvers": buildResolvers,
|
||||
"isLocationAllowed": isLocationAllowed,
|
||||
"buildStreamUpstreams": buildStreamUpstreams,
|
||||
|
||||
"contains": strings.Contains,
|
||||
"hasPrefix": strings.HasPrefix,
|
||||
|
@ -196,6 +197,34 @@ func buildSSPassthroughUpstreams(b interface{}, sslb interface{}) string {
|
|||
return buf.String()
|
||||
}
|
||||
|
||||
func buildStreamUpstreams(proto string, b interface{}, s interface{}) string {
|
||||
backends := b.([]*ingress.Backend)
|
||||
streams := s.([]*ingress.Location)
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 10))
|
||||
// multiple services can use the same upstream.
|
||||
// avoid duplications using a map[name]=true
|
||||
u := make(map[string]bool)
|
||||
for _, stream := range streams {
|
||||
if u[stream.Backend] {
|
||||
continue
|
||||
}
|
||||
u[stream.Backend] = true
|
||||
fmt.Fprintf(buf, "upstream %v-%v {\n", proto, stream.Backend)
|
||||
// TODO: find a better way to avoid empty stream upstreams
|
||||
fmt.Fprintf(buf, "\t\tserver 127.0.0.1:8181 down;\n")
|
||||
for _, backend := range backends {
|
||||
if backend.Name == stream.Backend {
|
||||
for _, server := range backend.Endpoints {
|
||||
fmt.Fprintf(buf, "\t\tserver %v:%v;\n", server.Address, server.Port)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Fprint(buf, "\t}\n\n")
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// buildLocation produces the location string, if the ingress has redirects
|
||||
// (specified through the ingress.kubernetes.io/rewrite-to annotation)
|
||||
func buildLocation(input interface{}) string {
|
||||
|
|
|
@ -433,7 +433,27 @@ stream {
|
|||
proxy_pass $stream_upstream;
|
||||
ssl_preread on;
|
||||
}
|
||||
|
||||
{{ buildStreamUpstreams "tcp" $backends .TCPBackends }}
|
||||
|
||||
{{ buildStreamUpstreams "udp" $backends .UDPBackends }}
|
||||
|
||||
# TCP services
|
||||
{{ range $i, $tcpServer := .TCPBackends }}
|
||||
server {
|
||||
listen {{ $tcpServer.Path }};
|
||||
proxy_pass tcp-{{ $tcpServer.Backend }};
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
# UDP services
|
||||
{{ range $i, $udpServer := .UDPBackends }}
|
||||
server {
|
||||
listen {{ $udpServer.Path }} udp;
|
||||
proxy_responses 1;
|
||||
proxy_pass udp-{{ $udpServer.Backend }};
|
||||
}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{/* definition of templates to avoid repetitions */}}
|
||||
|
|
|
@ -425,7 +425,7 @@ func (ic *GenericController) getStreamServices(data map[string]string, proto api
|
|||
// k -> port to expose
|
||||
// v -> <namespace>/<service name>:<port from service to be used>
|
||||
for k, v := range data {
|
||||
port, err := strconv.Atoi(k)
|
||||
_, err := strconv.Atoi(k)
|
||||
if err != nil {
|
||||
glog.Warningf("%v is not valid as a TCP port", k)
|
||||
continue
|
||||
|
@ -495,7 +495,7 @@ func (ic *GenericController) getStreamServices(data map[string]string, proto api
|
|||
|
||||
svcs = append(svcs, &ingress.Location{
|
||||
Path: k,
|
||||
Backend: fmt.Sprintf("%v-%v-%v", svcNs, svcName, port),
|
||||
Backend: fmt.Sprintf("%v-%v-%v", svcNs, svcName, svcPort),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue