Skip to content

Commit

Permalink
add pluginBuilderParams (#9355)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgadban authored Apr 11, 2024
1 parent 203ad62 commit 2ae5cfb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
6 changes: 6 additions & 0 deletions changelog/v1.17.0-beta19/gg-plugin-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: NON_USER_FACING
issueLink: https://github.com/solo-io/solo-projects/issues/5934
resolvesIssue: false
description: >-
Move objects needed for construction of OSS GGv2 plugins to a param object
2 changes: 1 addition & 1 deletion projects/gateway2/controller/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var _ = BeforeSuite(func() {

var gatewayClassObjName api.ObjectName = api.ObjectName(gatewayClassName)

exts, err := extensions.NewK8sGatewayExtensions(mgr, nil, nil)
exts, err := extensions.NewK8sGatewayExtensions(mgr)
Expect(err).ToNot(HaveOccurred())
cfg := controller.GatewayConfig{
Mgr: mgr,
Expand Down
4 changes: 3 additions & 1 deletion projects/gateway2/controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Start(ctx context.Context, cfg StartConfig) error {
var sanz sanitizer.XdsSanitizers
inputChannels := xds.NewXdsInputChannels()

k8sGwExtensions, err := cfg.ExtensionsFactory(mgr, cfg.RouteOptionClient, cfg.StatusReporter)
k8sGwExtensions, err := cfg.ExtensionsFactory(mgr)
if err != nil {
setupLog.Error(err, "unable to create k8s gw extensions")
return err
Expand All @@ -109,6 +109,8 @@ func Start(ctx context.Context, cfg StartConfig) error {
mgr,
k8sGwExtensions,
cfg.ProxyClient,
cfg.RouteOptionClient,
cfg.StatusReporter,
)
if err := mgr.Add(xdsSyncer); err != nil {
setupLog.Error(err, "unable to add xdsSyncer runnable")
Expand Down
6 changes: 3 additions & 3 deletions projects/gateway2/deployer/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var _ = Describe("Deployer", func() {
}
mgr, err := ctrl.NewManager(&rest.Config{}, ctrl.Options{})
Expect(err).NotTo(HaveOccurred())
k8sGatewayExt, err = extensions.NewK8sGatewayExtensions(mgr, nil, nil)
k8sGatewayExt, err = extensions.NewK8sGatewayExtensions(mgr)
Expect(err).NotTo(HaveOccurred())

})
Expand Down Expand Up @@ -149,7 +149,7 @@ var _ = Describe("Deployer", func() {
It("support segmenting by release", func() {
mgr, err := ctrl.NewManager(&rest.Config{}, ctrl.Options{})
Expect(err).NotTo(HaveOccurred())
k8sGatewayExt, err := extensions.NewK8sGatewayExtensions(mgr, nil, nil)
k8sGatewayExt, err := extensions.NewK8sGatewayExtensions(mgr)
Expect(err).NotTo(HaveOccurred())

d1, err := deployer.NewDeployer(newFakeClientWithObjs(gwc), &deployer.Inputs{
Expand Down Expand Up @@ -250,7 +250,7 @@ var _ = Describe("Deployer", func() {
defaultDeployerInputs = func() *deployer.Inputs {
mgr, err := ctrl.NewManager(&rest.Config{}, ctrl.Options{})
Expect(err).NotTo(HaveOccurred())
k8sGatewayExt, err := extensions.NewK8sGatewayExtensions(mgr, nil, nil)
k8sGatewayExt, err := extensions.NewK8sGatewayExtensions(mgr)
Expect(err).NotTo(HaveOccurred())
return &deployer.Inputs{
ControllerName: wellknown.GatewayControllerName,
Expand Down
23 changes: 10 additions & 13 deletions projects/gateway2/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,46 @@ import (
// which have Enterprise variants.
type K8sGatewayExtensions interface {
// CreatePluginRegistry returns the PluginRegistry
CreatePluginRegistry(ctx context.Context) registry.PluginRegistry
CreatePluginRegistry(ctx context.Context, params PluginBuilderParams) registry.PluginRegistry

// GetEnvoyImage returns the envoy image and tag used by the proxy deployment.
GetEnvoyImage() Image
}

type PluginBuilderParams struct {
RouteOptionClient gatewayv1.RouteOptionClient
StatusReporter reporter.StatusReporter
}

// K8sGatewayExtensionsFactory returns an extensions.K8sGatewayExtensions
type K8sGatewayExtensionsFactory func(
mgr controllerruntime.Manager,
routeOptionClient gatewayv1.RouteOptionClient,
statusReporter reporter.StatusReporter,
) (K8sGatewayExtensions, error)

// NewK8sGatewayExtensions returns the Open Source implementation of K8sGatewayExtensions
func NewK8sGatewayExtensions(
mgr controllerruntime.Manager,
routeOptionClient gatewayv1.RouteOptionClient,
statusReporter reporter.StatusReporter,
) (K8sGatewayExtensions, error) {
return &k8sGatewayExtensions{
mgr,
routeOptionClient,
statusReporter,
}, nil
}

type k8sGatewayExtensions struct {
mgr controllerruntime.Manager
routeOptionClient gatewayv1.RouteOptionClient
statusReporter reporter.StatusReporter
mgr controllerruntime.Manager
}

// CreatePluginRegistry returns the PluginRegistry
func (e *k8sGatewayExtensions) CreatePluginRegistry(_ context.Context) registry.PluginRegistry {
func (e *k8sGatewayExtensions) CreatePluginRegistry(_ context.Context, params PluginBuilderParams) registry.PluginRegistry {
queries := query.NewData(
e.mgr.GetClient(),
e.mgr.GetScheme(),
)
plugins := registry.BuildPlugins(
queries,
e.mgr.GetClient(),
e.routeOptionClient,
e.statusReporter,
params.RouteOptionClient,
params.StatusReporter,
)
return registry.NewPluginRegistry(plugins)
}
Expand Down
14 changes: 13 additions & 1 deletion projects/gateway2/xds/xds_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/solo-io/gloo/projects/gateway2/translator/translatorutils"
"sigs.k8s.io/controller-runtime/pkg/manager"

gatewayv1 "github.com/solo-io/gloo/projects/gateway/pkg/api/v1"
"github.com/solo-io/gloo/projects/gateway2/reports"
gloot "github.com/solo-io/gloo/projects/gateway2/translator"
"github.com/solo-io/gloo/projects/gateway2/translator/plugins/registry"
Expand Down Expand Up @@ -94,6 +95,9 @@ type XdsSyncer struct {
// proxyReconciler wraps the client that writes Proxy resources into an in-memory cache
// This cache is utilized by the debug.ProxyEndpointServer
proxyReconciler gloo_solo_io.ProxyReconciler

routeOptionClient gatewayv1.RouteOptionClient
statusReporter reporter.StatusReporter
}

type XdsInputChannels struct {
Expand Down Expand Up @@ -132,6 +136,8 @@ func NewXdsSyncer(
mgr manager.Manager,
k8sGwExtensions extensions.K8sGatewayExtensions,
proxyClient gloo_solo_io.ProxyClient,
routeOptionClient gatewayv1.RouteOptionClient,
statusReporter reporter.StatusReporter,
) *XdsSyncer {
return &XdsSyncer{
controllerName: controllerName,
Expand All @@ -143,6 +149,8 @@ func NewXdsSyncer(
mgr: mgr,
k8sGwExtensions: k8sGwExtensions,
proxyReconciler: gloo_solo_io.NewProxyReconciler(proxyClient, statusutils.NewNoOpStatusClient()),
routeOptionClient: routeOptionClient,
statusReporter: statusReporter,
}
}

Expand All @@ -168,7 +176,11 @@ func (s *XdsSyncer) Start(ctx context.Context) error {

gatewayQueries := query.NewData(s.mgr.GetClient(), s.mgr.GetScheme())

pluginRegistry := s.k8sGwExtensions.CreatePluginRegistry(ctx)
pluginParams := extensions.PluginBuilderParams{
RouteOptionClient: s.routeOptionClient,
StatusReporter: s.statusReporter,
}
pluginRegistry := s.k8sGwExtensions.CreatePluginRegistry(ctx, pluginParams)
gatewayTranslator := gloot.NewTranslator(gatewayQueries, pluginRegistry)

proxies := gloo_solo_io.ProxyList{}
Expand Down

0 comments on commit 2ae5cfb

Please sign in to comment.