Add TCP and UDP services removed in migration
This commit is contained in:
parent
28c67257e3
commit
ba98383c2d
3 changed files with 51 additions and 2 deletions
|
@ -138,6 +138,7 @@ var (
|
||||||
"buildSSPassthroughUpstreams": buildSSPassthroughUpstreams,
|
"buildSSPassthroughUpstreams": buildSSPassthroughUpstreams,
|
||||||
"buildResolvers": buildResolvers,
|
"buildResolvers": buildResolvers,
|
||||||
"isLocationAllowed": isLocationAllowed,
|
"isLocationAllowed": isLocationAllowed,
|
||||||
|
"buildStreamUpstreams": buildStreamUpstreams,
|
||||||
|
|
||||||
"contains": strings.Contains,
|
"contains": strings.Contains,
|
||||||
"hasPrefix": strings.HasPrefix,
|
"hasPrefix": strings.HasPrefix,
|
||||||
|
@ -196,6 +197,34 @@ func buildSSPassthroughUpstreams(b interface{}, sslb interface{}) string {
|
||||||
return buf.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
|
// buildLocation produces the location string, if the ingress has redirects
|
||||||
// (specified through the ingress.kubernetes.io/rewrite-to annotation)
|
// (specified through the ingress.kubernetes.io/rewrite-to annotation)
|
||||||
func buildLocation(input interface{}) string {
|
func buildLocation(input interface{}) string {
|
||||||
|
|
|
@ -430,7 +430,27 @@ stream {
|
||||||
proxy_pass $stream_upstream;
|
proxy_pass $stream_upstream;
|
||||||
ssl_preread on;
|
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 */}}
|
{{/* definition of templates to avoid repetitions */}}
|
||||||
|
|
|
@ -425,7 +425,7 @@ func (ic *GenericController) getStreamServices(data map[string]string, proto api
|
||||||
// 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 data {
|
||||||
port, 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 port", k)
|
||||||
continue
|
continue
|
||||||
|
@ -495,7 +495,7 @@ func (ic *GenericController) getStreamServices(data map[string]string, proto api
|
||||||
|
|
||||||
svcs = append(svcs, &ingress.Location{
|
svcs = append(svcs, &ingress.Location{
|
||||||
Path: k,
|
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