2022-05-18 15:22:08 +00:00
|
|
|
package static
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2022-11-21 17:36:05 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2023-02-03 14:24:05 +00:00
|
|
|
"github.com/traefik/traefik/v3/pkg/logs"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/provider/hub"
|
2022-05-18 15:22:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Configuration) initHubProvider() error {
|
|
|
|
// Hub provider is an experimental feature. It requires the experimental flag to be enabled before continuing.
|
|
|
|
if c.Experimental == nil || !c.Experimental.Hub {
|
|
|
|
return errors.New("the experimental flag for Hub is not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := c.EntryPoints[hub.TunnelEntrypoint]; !ok {
|
|
|
|
var ep EntryPoint
|
|
|
|
ep.SetDefaults()
|
|
|
|
ep.Address = ":9901"
|
|
|
|
c.EntryPoints[hub.TunnelEntrypoint] = &ep
|
2022-11-21 17:36:05 +00:00
|
|
|
|
|
|
|
log.Info().Str(logs.EntryPointName, hub.TunnelEntrypoint).
|
|
|
|
Msg("The entryPoint is created on port 9901 to allow exposition of services.")
|
2022-05-18 15:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.Hub.TLS == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Hub.TLS.Insecure && (c.Hub.TLS.CA != "" || c.Hub.TLS.Cert != "" || c.Hub.TLS.Key != "") {
|
|
|
|
return errors.New("mTLS configuration for Hub and insecure TLS for Hub are mutually exclusive")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !c.Hub.TLS.Insecure && (c.Hub.TLS.CA == "" || c.Hub.TLS.Cert == "" || c.Hub.TLS.Key == "") {
|
|
|
|
return errors.New("incomplete mTLS configuration for Hub")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Hub.TLS.Insecure {
|
2022-11-21 17:36:05 +00:00
|
|
|
log.Warn().Msg("Hub is in `insecure` mode. Do not run in production with this setup.")
|
2022-05-18 15:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := c.EntryPoints[hub.APIEntrypoint]; !ok {
|
|
|
|
var ep EntryPoint
|
|
|
|
ep.SetDefaults()
|
|
|
|
ep.Address = ":9900"
|
|
|
|
c.EntryPoints[hub.APIEntrypoint] = &ep
|
2022-11-21 17:36:05 +00:00
|
|
|
|
|
|
|
log.Info().Str(logs.EntryPointName, hub.APIEntrypoint).
|
|
|
|
Msg("The entryPoint is created on port 9900 to allow Traefik to communicate with the Hub Agent for Traefik.")
|
2022-05-18 15:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.EntryPoints[hub.APIEntrypoint].HTTP.TLS = &TLSConfig{
|
|
|
|
Options: "traefik-hub",
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|