Marc-Antoine cce8e52ddd
feat: Add plugin system to controller (#86)
* feat: Add plugin system to controller

* add priority system and default empty tls connection policy
2022-04-15 13:53:58 +02:00

48 lines
1.2 KiB
Go

package global
import (
"encoding/json"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/caddyserver/ingress/pkg/converter"
"github.com/caddyserver/ingress/pkg/store"
)
type MetricsPlugin struct{}
func (p MetricsPlugin) IngressPlugin() converter.PluginInfo {
return converter.PluginInfo{
Name: "metrics",
New: func() converter.Plugin { return new(MetricsPlugin) },
}
}
func init() {
converter.RegisterPlugin(MetricsPlugin{})
}
func (p MetricsPlugin) GlobalHandler(config *converter.Config, store *store.Store) error {
httpApp := config.Apps["http"].(*caddyhttp.App)
if store.ConfigMap.Metrics {
httpApp.Servers[converter.MetricsServer] = &caddyhttp.Server{
Listen: []string{":9765"},
AutoHTTPS: &caddyhttp.AutoHTTPSConfig{Disabled: true},
Routes: []caddyhttp.Route{{
HandlersRaw: []json.RawMessage{json.RawMessage(`{ "handler": "metrics" }`)},
MatcherSetsRaw: []caddy.ModuleMap{{
"path": caddyconfig.JSON(caddyhttp.MatchPath{"/metrics"}, nil),
}},
}},
}
}
return nil
}
// Interface guards
var (
_ = converter.GlobalMiddleware(MetricsPlugin{})
)