Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions consul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Upstream struct {
Service string
LocalBindAddress string
LocalBindPort int
Protocol string

TLS

Expand Down Expand Up @@ -47,6 +48,7 @@ func (n UpstreamNode) Equal(o UpstreamNode) bool {
type Downstream struct {
LocalBindAddress string
LocalBindPort int
Protocol string
TargetAddress string
TargetPort int

Expand Down
20 changes: 17 additions & 3 deletions consul/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type upstream struct {
LocalBindPort int
Service string
Datacenter string
Protocol string
Nodes []*api.ServiceEntry

done bool
Expand All @@ -29,6 +30,7 @@ type upstream struct {
type downstream struct {
LocalBindAddress string
LocalBindPort int
Protocol string
TargetAddress string
TargetPort int
}
Expand Down Expand Up @@ -111,6 +113,13 @@ func (w *Watcher) handleProxyChange(first bool, srv *api.AgentService) {
w.downstream.LocalBindAddress = defaultDownstreamBindAddr
w.downstream.LocalBindPort = srv.Port
w.downstream.TargetAddress = defaultUpstreamBindAddr

if srv.Proxy != nil && srv.Proxy.Config != nil {
if c, ok := srv.Proxy.Config["protocol"].(string); ok {
w.downstream.Protocol = c
}
}

if srv.Connect != nil && srv.Connect.SidecarService != nil && srv.Connect.SidecarService.Proxy != nil && srv.Connect.SidecarService.Proxy.Config != nil {
if b, ok := srv.Connect.SidecarService.Proxy.Config["bind_address"].(string); ok {
w.downstream.LocalBindAddress = b
Expand Down Expand Up @@ -155,6 +164,12 @@ func (w *Watcher) startUpstream(up api.Upstream) {
Datacenter: up.Datacenter,
}

if up.Config["protocol"] != nil {
if p, ok := up.Config["protocol"].(string); ok {
u.Protocol = p
}
}

w.lock.Lock()
w.upstreams[up.DestinationName] = u
w.lock.Unlock()
Expand Down Expand Up @@ -332,7 +347,7 @@ func (w *Watcher) genCfg() Config {
LocalBindPort: w.downstream.LocalBindPort,
TargetAddress: w.downstream.TargetAddress,
TargetPort: w.downstream.TargetPort,

Protocol: w.downstream.Protocol,
TLS: TLS{
CAs: w.certCAs,
Cert: w.leaf.Cert,
Expand All @@ -346,14 +361,13 @@ func (w *Watcher) genCfg() Config {
Service: up.Service,
LocalBindAddress: up.LocalBindAddress,
LocalBindPort: up.LocalBindPort,

Protocol: up.Protocol,
TLS: TLS{
CAs: w.certCAs,
Cert: w.leaf.Cert,
Key: w.leaf.Key,
},
}

for _, s := range up.Nodes {
serviceInstancesTotal++
host := s.Service.Address
Expand Down
11 changes: 9 additions & 2 deletions haproxy/state/downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@ import (
func generateDownstream(opts Options, certStore CertificateStore, cfg consul.Downstream, state State) (State, error) {
feName := "front_downstream"
beName := "back_downstream"
feMode := models.FrontendModeHTTP
beMode := models.BackendModeHTTP

caPath, crtPath, err := certStore.CertsPath(cfg.TLS)
if err != nil {
return state, err
}

if cfg.Protocol != "" && cfg.Protocol == "tcp" {
feMode = models.FrontendModeTCP
beMode = models.BackendModeTCP
}

// Main config
fe := Frontend{
Frontend: models.Frontend{
Name: feName,
DefaultBackend: beName,
ClientTimeout: &clientTimeout,
Mode: models.FrontendModeHTTP,
Mode: feMode,
Httplog: opts.LogRequests,
},
Bind: models.Bind{
Expand Down Expand Up @@ -73,7 +80,7 @@ func generateDownstream(opts Options, certStore CertificateStore, cfg consul.Dow
Name: beName,
ServerTimeout: &serverTimeout,
ConnectTimeout: &connectTimeout,
Mode: models.BackendModeHTTP,
Mode: beMode,
},
Servers: []models.Server{
models.Server{
Expand Down
12 changes: 10 additions & 2 deletions haproxy/state/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ import (
func generateUpstream(opts Options, certStore CertificateStore, cfg consul.Upstream, oldState, newState State) (State, error) {
feName := fmt.Sprintf("front_%s", cfg.Service)
beName := fmt.Sprintf("back_%s", cfg.Service)
feMode := models.FrontendModeHTTP
beMode := models.BackendModeHTTP

fePort64 := int64(cfg.LocalBindPort)

if cfg.Protocol != "" && cfg.Protocol == "tcp" {
feMode = models.FrontendModeTCP
beMode = models.BackendModeTCP
}

fe := Frontend{
Frontend: models.Frontend{
Name: feName,
DefaultBackend: beName,
ClientTimeout: &clientTimeout,
Mode: models.FrontendModeHTTP,
Mode: feMode,
Httplog: opts.LogRequests,
},
Bind: models.Bind{
Expand Down Expand Up @@ -45,7 +53,7 @@ func generateUpstream(opts Options, certStore CertificateStore, cfg consul.Upstr
Balance: &models.Balance{
Algorithm: models.BalanceAlgorithmLeastconn,
},
Mode: models.BackendModeHTTP,
Mode: beMode,
},
}
if opts.LogRequests && opts.LogSocket != "" {
Expand Down