feat: callbacks
This commit is contained in:
parent
c69246d93e
commit
c826cc97e6
8 changed files with 1917 additions and 0 deletions
|
@ -49,6 +49,7 @@ import (
|
||||||
"github.com/traefik/traefik/v3/pkg/tracing"
|
"github.com/traefik/traefik/v3/pkg/tracing"
|
||||||
"github.com/traefik/traefik/v3/pkg/types"
|
"github.com/traefik/traefik/v3/pkg/types"
|
||||||
"github.com/traefik/traefik/v3/pkg/version"
|
"github.com/traefik/traefik/v3/pkg/version"
|
||||||
|
"github.com/traefik/traefik/v3/pkg/updater"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -197,6 +198,8 @@ func setupServer(staticConfiguration *static.Configuration) (*server.Server, err
|
||||||
|
|
||||||
tsProviders := initTailscaleProviders(staticConfiguration, providerAggregator)
|
tsProviders := initTailscaleProviders(staticConfiguration, providerAggregator)
|
||||||
|
|
||||||
|
updaterProvider := updater.New(staticConfiguration);
|
||||||
|
|
||||||
// Observability
|
// Observability
|
||||||
|
|
||||||
metricRegistries := registerMetricClients(staticConfiguration.Metrics)
|
metricRegistries := registerMetricClients(staticConfiguration.Metrics)
|
||||||
|
@ -386,6 +389,9 @@ func setupServer(staticConfiguration *static.Configuration) (*server.Server, err
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Updater
|
||||||
|
watcher.AddListener(updaterProvider.HandleConfigUpdate)
|
||||||
|
|
||||||
return server.NewServer(routinesPool, serverEntryPointsTCP, serverEntryPointsUDP, watcher, observabilityMgr), nil
|
return server.NewServer(routinesPool, serverEntryPointsTCP, serverEntryPointsUDP, watcher, observabilityMgr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -369,6 +369,9 @@ Periodically check if a new version has been released. (Default: ```true```)
|
||||||
`--global.sendanonymoususage`:
|
`--global.sendanonymoususage`:
|
||||||
Periodically send anonymous usage statistics. If the option is not specified, it will be disabled by default. (Default: ```false```)
|
Periodically send anonymous usage statistics. If the option is not specified, it will be disabled by default. (Default: ```false```)
|
||||||
|
|
||||||
|
`--global.updatercallbacks`:
|
||||||
|
Callback urls for updater script (example: https://localhost:8080/callback)
|
||||||
|
|
||||||
`--hostresolver`:
|
`--hostresolver`:
|
||||||
Enable CNAME Flattening. (Default: ```false```)
|
Enable CNAME Flattening. (Default: ```false```)
|
||||||
|
|
||||||
|
|
|
@ -369,6 +369,9 @@ Periodically check if a new version has been released. (Default: ```true```)
|
||||||
`TRAEFIK_GLOBAL_SENDANONYMOUSUSAGE`:
|
`TRAEFIK_GLOBAL_SENDANONYMOUSUSAGE`:
|
||||||
Periodically send anonymous usage statistics. If the option is not specified, it will be disabled by default. (Default: ```false```)
|
Periodically send anonymous usage statistics. If the option is not specified, it will be disabled by default. (Default: ```false```)
|
||||||
|
|
||||||
|
`TRAEFIK_GLOBAL_UPDATERCALLBACKS`:
|
||||||
|
Callback urls for updater script (example: https://localhost:8080/callback)
|
||||||
|
|
||||||
`TRAEFIK_HOSTRESOLVER`:
|
`TRAEFIK_HOSTRESOLVER`:
|
||||||
Enable CNAME Flattening. (Default: ```false```)
|
Enable CNAME Flattening. (Default: ```false```)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
[global]
|
[global]
|
||||||
checkNewVersion = true
|
checkNewVersion = true
|
||||||
sendAnonymousUsage = true
|
sendAnonymousUsage = true
|
||||||
|
updaterCallbacks = ["foobar", "foobar"]
|
||||||
|
|
||||||
[serversTransport]
|
[serversTransport]
|
||||||
insecureSkipVerify = true
|
insecureSkipVerify = true
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
global:
|
global:
|
||||||
checkNewVersion: true
|
checkNewVersion: true
|
||||||
sendAnonymousUsage: true
|
sendAnonymousUsage: true
|
||||||
|
updaterCallbacks:
|
||||||
|
- foobar
|
||||||
|
- foobar
|
||||||
serversTransport:
|
serversTransport:
|
||||||
insecureSkipVerify: true
|
insecureSkipVerify: true
|
||||||
rootCAs:
|
rootCAs:
|
||||||
|
|
|
@ -108,6 +108,7 @@ type CertificateResolver struct {
|
||||||
type Global struct {
|
type Global struct {
|
||||||
CheckNewVersion bool `description:"Periodically check if a new version has been released." json:"checkNewVersion,omitempty" toml:"checkNewVersion,omitempty" yaml:"checkNewVersion,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
CheckNewVersion bool `description:"Periodically check if a new version has been released." json:"checkNewVersion,omitempty" toml:"checkNewVersion,omitempty" yaml:"checkNewVersion,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||||
SendAnonymousUsage bool `description:"Periodically send anonymous usage statistics. If the option is not specified, it will be disabled by default." json:"sendAnonymousUsage,omitempty" toml:"sendAnonymousUsage,omitempty" yaml:"sendAnonymousUsage,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
SendAnonymousUsage bool `description:"Periodically send anonymous usage statistics. If the option is not specified, it will be disabled by default." json:"sendAnonymousUsage,omitempty" toml:"sendAnonymousUsage,omitempty" yaml:"sendAnonymousUsage,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||||
|
UpdaterCallbacks []string `description:"Callback urls for updater script (example: https://localhost:8080/callback)" json:"updaterCallbacks,omitempty" toml:"updaterCallbacks,omitempty" yaml:"updaterCallbacks,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServersTransport options to configure communication between Traefik and the servers.
|
// ServersTransport options to configure communication between Traefik and the servers.
|
||||||
|
|
49
pkg/updater/provider.go
Normal file
49
pkg/updater/provider.go
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package updater
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/traefik/traefik/v3/pkg/config/dynamic"
|
||||||
|
"github.com/traefik/traefik/v3/pkg/config/static"
|
||||||
|
"github.com/traefik/traefik/v3/pkg/safe"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Updater struct {
|
||||||
|
callbackUrls []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(config *static.Configuration) *Updater {
|
||||||
|
updater := &Updater{
|
||||||
|
callbackUrls: config.Global.UpdaterCallbacks,
|
||||||
|
}
|
||||||
|
|
||||||
|
return updater
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *Updater) HandleConfigUpdate(cfg dynamic.Configuration) {
|
||||||
|
body, err := json.Marshal(cfg)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
// should never happen?
|
||||||
|
log.Error().Err(err).Msg("Error while marshalling dynamic configuration data to json")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBody := bytes.NewBuffer(body)
|
||||||
|
|
||||||
|
for _, url := range u.callbackUrls {
|
||||||
|
safe.Go(func() {
|
||||||
|
resp, err := http.Post(url, "application/json", requestBody)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Str("url", url).Msg("Error while sending configuration data to callback")
|
||||||
|
} else {
|
||||||
|
log.Debug().Str("url", url).Msg("Configuration data sent")
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
1851
schema.json
Normal file
1851
schema.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue