Add TCP Middlewares support
This commit is contained in:
parent
679def0151
commit
fc9f41b955
134 changed files with 5865 additions and 1852 deletions
|
@ -17,13 +17,14 @@ const (
|
|||
|
||||
// Configuration holds the information about the currently running traefik instance.
|
||||
type Configuration struct {
|
||||
Routers map[string]*RouterInfo `json:"routers,omitempty"`
|
||||
Middlewares map[string]*MiddlewareInfo `json:"middlewares,omitempty"`
|
||||
Services map[string]*ServiceInfo `json:"services,omitempty"`
|
||||
TCPRouters map[string]*TCPRouterInfo `json:"tcpRouters,omitempty"`
|
||||
TCPServices map[string]*TCPServiceInfo `json:"tcpServices,omitempty"`
|
||||
UDPRouters map[string]*UDPRouterInfo `json:"udpRouters,omitempty"`
|
||||
UDPServices map[string]*UDPServiceInfo `json:"udpServices,omitempty"`
|
||||
Routers map[string]*RouterInfo `json:"routers,omitempty"`
|
||||
Middlewares map[string]*MiddlewareInfo `json:"middlewares,omitempty"`
|
||||
TCPMiddlewares map[string]*TCPMiddlewareInfo `json:"tcpMiddlewares,omitempty"`
|
||||
Services map[string]*ServiceInfo `json:"services,omitempty"`
|
||||
TCPRouters map[string]*TCPRouterInfo `json:"tcpRouters,omitempty"`
|
||||
TCPServices map[string]*TCPServiceInfo `json:"tcpServices,omitempty"`
|
||||
UDPRouters map[string]*UDPRouterInfo `json:"udpRouters,omitempty"`
|
||||
UDPServices map[string]*UDPServiceInfo `json:"udpServices,omitempty"`
|
||||
}
|
||||
|
||||
// NewConfig returns a Configuration initialized with the given conf. It never returns nil.
|
||||
|
@ -74,6 +75,13 @@ func NewConfig(conf dynamic.Configuration) *Configuration {
|
|||
runtimeConfig.TCPServices[k] = &TCPServiceInfo{TCPService: v, Status: StatusEnabled}
|
||||
}
|
||||
}
|
||||
|
||||
if len(conf.TCP.Middlewares) > 0 {
|
||||
runtimeConfig.TCPMiddlewares = make(map[string]*TCPMiddlewareInfo, len(conf.TCP.Middlewares))
|
||||
for k, v := range conf.TCP.Middlewares {
|
||||
runtimeConfig.TCPMiddlewares[k] = &TCPMiddlewareInfo{TCPMiddleware: v, Status: StatusEnabled}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if conf.UDP != nil {
|
||||
|
@ -177,6 +185,15 @@ func (c *Configuration) PopulateUsedBy() {
|
|||
sort.Strings(c.TCPServices[k].UsedBy)
|
||||
}
|
||||
|
||||
for midName, mid := range c.TCPMiddlewares {
|
||||
// lazily initialize Status in case caller forgot to do it
|
||||
if mid.Status == "" {
|
||||
mid.Status = StatusEnabled
|
||||
}
|
||||
|
||||
sort.Strings(c.TCPMiddlewares[midName].UsedBy)
|
||||
}
|
||||
|
||||
for routerName, routerInfo := range c.UDPRouters {
|
||||
// lazily initialize Status in case caller forgot to do it
|
||||
if routerInfo.Status == "" {
|
||||
|
|
|
@ -112,3 +112,33 @@ func (s *TCPServiceInfo) AddError(err error, critical bool) {
|
|||
s.Status = StatusWarning
|
||||
}
|
||||
}
|
||||
|
||||
// TCPMiddlewareInfo holds information about a currently running middleware.
|
||||
type TCPMiddlewareInfo struct {
|
||||
*dynamic.TCPMiddleware // dynamic configuration
|
||||
// Err contains all the errors that occurred during service creation.
|
||||
Err []string `json:"error,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
UsedBy []string `json:"usedBy,omitempty"` // list of TCP routers and services using that middleware.
|
||||
}
|
||||
|
||||
// AddError adds err to s.Err, if it does not already exist.
|
||||
// If critical is set, m is marked as disabled.
|
||||
func (m *TCPMiddlewareInfo) AddError(err error, critical bool) {
|
||||
for _, value := range m.Err {
|
||||
if value == err.Error() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.Err = append(m.Err, err.Error())
|
||||
if critical {
|
||||
m.Status = StatusDisabled
|
||||
return
|
||||
}
|
||||
|
||||
// only set it to "warning" if not already in a worse state
|
||||
if m.Status != StatusDisabled {
|
||||
m.Status = StatusWarning
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue