5b072029f2
This PR adds initial support for running Consul Connect Ingress Gateways (CIGs) in Nomad. These gateways are declared as part of a task group level service definition within the connect stanza. ```hcl service { connect { gateway { proxy { // envoy proxy configuration } ingress { // ingress-gateway configuration entry } } } } ``` A gateway can be run in `bridge` or `host` networking mode, with the caveat that host networking necessitates manually specifying the Envoy admin listener (which cannot be disabled) via the service port value. Currently Envoy is the only supported gateway implementation in Consul, and Nomad only supports running Envoy as a gateway using the docker driver. Aims to address #8294 and tangentially #8647
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package consul
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/hashicorp/consul/api"
|
|
"github.com/hashicorp/go-hclog"
|
|
)
|
|
|
|
var _ ConfigAPI = (*MockConfigsAPI)(nil)
|
|
|
|
type MockConfigsAPI struct {
|
|
logger hclog.Logger
|
|
|
|
lock sync.Mutex
|
|
state struct {
|
|
error error
|
|
entries map[string]api.ConfigEntry
|
|
}
|
|
}
|
|
|
|
func NewMockConfigsAPI(l hclog.Logger) *MockConfigsAPI {
|
|
return &MockConfigsAPI{
|
|
logger: l.Named("mock_consul"),
|
|
state: struct {
|
|
error error
|
|
entries map[string]api.ConfigEntry
|
|
}{entries: make(map[string]api.ConfigEntry)},
|
|
}
|
|
}
|
|
|
|
// Set is a mock of ConfigAPI.Set
|
|
func (m *MockConfigsAPI) Set(entry api.ConfigEntry, w *api.WriteOptions) (bool, *api.WriteMeta, error) {
|
|
m.lock.Lock()
|
|
defer m.lock.Unlock()
|
|
|
|
if m.state.error != nil {
|
|
return false, nil, m.state.error
|
|
}
|
|
|
|
m.state.entries[entry.GetName()] = entry
|
|
|
|
return true, &api.WriteMeta{
|
|
RequestTime: 1,
|
|
}, nil
|
|
}
|
|
|
|
// SetError is a helper method for configuring an error that will be returned
|
|
// on future calls to mocked methods.
|
|
func (m *MockConfigsAPI) SetError(err error) {
|
|
m.lock.Lock()
|
|
defer m.lock.Unlock()
|
|
|
|
m.state.error = err
|
|
}
|