Refactoring of TCP and UDP services
This commit is contained in:
parent
33ab550290
commit
84324af140
7 changed files with 71 additions and 116 deletions
|
|
@ -299,8 +299,8 @@ type TemplateConfig struct {
|
|||
Backends []*ingress.Backend
|
||||
PassthroughBackends []*ingress.SSLPassthroughBackend
|
||||
Servers []*ingress.Server
|
||||
TCPBackends []*ingress.Location
|
||||
UDPBackends []*ingress.Location
|
||||
TCPBackends []ingress.L4Service
|
||||
UDPBackends []ingress.L4Service
|
||||
HealthzURI string
|
||||
CustomErrors bool
|
||||
Cfg Configuration
|
||||
|
|
|
|||
|
|
@ -134,7 +134,6 @@ var (
|
|||
"buildSSLPassthroughUpstreams": buildSSLPassthroughUpstreams,
|
||||
"buildResolvers": buildResolvers,
|
||||
"isLocationAllowed": isLocationAllowed,
|
||||
"buildStreamUpstreams": buildStreamUpstreams,
|
||||
|
||||
"contains": strings.Contains,
|
||||
"hasPrefix": strings.HasPrefix,
|
||||
|
|
@ -193,34 +192,6 @@ func buildSSLPassthroughUpstreams(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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue