Refactor plugins system
This commit is contained in:
parent
ffd01fc88a
commit
fed86bd816
9 changed files with 828 additions and 261 deletions
|
|
@ -2,43 +2,62 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-retryablehttp"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v3/pkg/config/static"
|
||||
"github.com/traefik/traefik/v3/pkg/logs"
|
||||
"github.com/traefik/traefik/v3/pkg/plugins"
|
||||
)
|
||||
|
||||
const outputDir = "./plugins-storage/"
|
||||
|
||||
func createPluginBuilder(staticConfiguration *static.Configuration) (*plugins.Builder, error) {
|
||||
client, plgs, localPlgs, err := initPlugins(staticConfiguration)
|
||||
manager, plgs, localPlgs, err := initPlugins(staticConfiguration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return plugins.NewBuilder(client, plgs, localPlgs)
|
||||
return plugins.NewBuilder(manager, plgs, localPlgs)
|
||||
}
|
||||
|
||||
func initPlugins(staticCfg *static.Configuration) (*plugins.Client, map[string]plugins.Descriptor, map[string]plugins.LocalDescriptor, error) {
|
||||
func initPlugins(staticCfg *static.Configuration) (*plugins.Manager, map[string]plugins.Descriptor, map[string]plugins.LocalDescriptor, error) {
|
||||
err := checkUniquePluginNames(staticCfg.Experimental)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
var client *plugins.Client
|
||||
var manager *plugins.Manager
|
||||
plgs := map[string]plugins.Descriptor{}
|
||||
|
||||
if hasPlugins(staticCfg) {
|
||||
opts := plugins.ClientOptions{
|
||||
httpClient := retryablehttp.NewClient()
|
||||
httpClient.Logger = logs.NewRetryableHTTPLogger(log.Logger)
|
||||
httpClient.HTTPClient = &http.Client{Timeout: 10 * time.Second}
|
||||
httpClient.RetryMax = 3
|
||||
|
||||
// Create separate downloader for HTTP operations
|
||||
archivesPath := filepath.Join(outputDir, "archives")
|
||||
downloader, err := plugins.NewRegistryDownloader(plugins.RegistryDownloaderOptions{
|
||||
HTTPClient: httpClient.HTTPClient,
|
||||
ArchivesPath: archivesPath,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("unable to create plugin downloader: %w", err)
|
||||
}
|
||||
|
||||
opts := plugins.ManagerOptions{
|
||||
Output: outputDir,
|
||||
}
|
||||
|
||||
var err error
|
||||
client, err = plugins.NewClient(opts)
|
||||
manager, err = plugins.NewManager(downloader, opts)
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("unable to create plugins client: %w", err)
|
||||
return nil, nil, nil, fmt.Errorf("unable to create plugins manager: %w", err)
|
||||
}
|
||||
|
||||
err = plugins.SetupRemotePlugins(client, staticCfg.Experimental.Plugins)
|
||||
err = plugins.SetupRemotePlugins(manager, staticCfg.Experimental.Plugins)
|
||||
if err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("unable to set up plugins environment: %w", err)
|
||||
}
|
||||
|
|
@ -57,7 +76,7 @@ func initPlugins(staticCfg *static.Configuration) (*plugins.Client, map[string]p
|
|||
localPlgs = staticCfg.Experimental.LocalPlugins
|
||||
}
|
||||
|
||||
return client, plgs, localPlgs, nil
|
||||
return manager, plgs, localPlgs, nil
|
||||
}
|
||||
|
||||
func checkUniquePluginNames(e *static.Experimental) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue