V1 Compat Exported Services Controller Optimizations (#20517)

V1 compat exported services controller optimizations

* Don't start the v2 exported services controller in v1 mode.
* Use the controller cache.
This commit is contained in:
Eric Haberkorn 2024-02-07 14:05:42 -05:00 committed by GitHub
parent 3ca4f39fa1
commit 1bd253021b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 57 additions and 20 deletions

View File

@ -1043,11 +1043,12 @@ func (s *Server) registerControllers(deps Deps, proxyUpdater ProxyUpdater) error
})
auth.RegisterControllers(s.controllerManager, auth.DefaultControllerDependencies())
multicluster.RegisterControllers(s.controllerManager)
} else {
shim := NewExportedServicesShim(s)
multicluster.RegisterCompatControllers(s.controllerManager, multicluster.DefaultCompatControllerDependencies(shim))
}
shim := NewExportedServicesShim(s)
multicluster.RegisterControllers(s.controllerManager, multicluster.DefaultControllerDependencies(shim))
reaper.RegisterControllers(s.controllerManager)
if s.config.DevMode {

View File

@ -26,16 +26,26 @@ func RegisterTypes(r resource.Registry) {
}
type ControllerDependencies = controllers.Dependencies
type CompatControllerDependencies = controllers.CompatDependencies
func DefaultControllerDependencies(ac v1compat.AggregatedConfig) ControllerDependencies {
func DefaultControllerDependencies() ControllerDependencies {
return ControllerDependencies{
ExportedServicesSamenessGroupsExpander: exportedServicesSamenessGroupExpander.New(),
ConfigEntryExports: ac,
}
}
func DefaultCompatControllerDependencies(ac v1compat.AggregatedConfig) CompatControllerDependencies {
return CompatControllerDependencies{
ConfigEntryExports: ac,
}
}
// RegisterControllers registers controllers for the multicluster types with
// the given controller Manager.
func RegisterControllers(mgr *controller.Manager, deps ControllerDependencies) {
controllers.Register(mgr, deps)
func RegisterControllers(mgr *controller.Manager) {
controllers.Register(mgr, DefaultControllerDependencies())
}
func RegisterCompatControllers(mgr *controller.Manager, deps CompatControllerDependencies) {
controllers.RegisterCompat(mgr, deps)
}

View File

@ -11,10 +11,16 @@ import (
type Dependencies struct {
ExportedServicesSamenessGroupsExpander exportedservices.ExportedServicesSamenessGroupExpander
ConfigEntryExports v1compat.AggregatedConfig
}
type CompatDependencies struct {
ConfigEntryExports v1compat.AggregatedConfig
}
func Register(mgr *controller.Manager, deps Dependencies) {
mgr.Register(exportedservices.Controller(deps.ExportedServicesSamenessGroupsExpander))
}
func RegisterCompat(mgr *controller.Manager, deps CompatDependencies) {
mgr.Register(v1compat.Controller(deps.ConfigEntryExports))
}

View File

@ -11,6 +11,8 @@ import (
"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/internal/controller"
"github.com/hashicorp/consul/internal/controller/cache"
"github.com/hashicorp/consul/internal/controller/cache/index"
"github.com/hashicorp/consul/internal/multicluster/internal/types"
"github.com/hashicorp/consul/internal/resource"
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v2beta1"
@ -105,30 +107,48 @@ func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req c
EnterpriseMeta: *entMeta,
}
partitionExports, err := resource.ListDecodedResource[*pbmulticluster.PartitionExportedServices](ctx, rt.Client, &pbresource.ListRequest{
Type: pbmulticluster.PartitionExportedServicesType,
Tenancy: req.ID.Tenancy,
})
partitionExports, err := cache.ListDecoded[*pbmulticluster.PartitionExportedServices](
rt.Cache,
pbmulticluster.PartitionExportedServicesType,
"id",
&pbresource.ID{
Type: pbmulticluster.PartitionExportedServicesType,
Tenancy: req.ID.Tenancy,
},
index.IndexQueryOptions{Prefix: true},
)
if err != nil {
rt.Logger.Error("error retrieving partition exported services", "error", err)
return err
}
namespaceExports, err := resource.ListDecodedResource[*pbmulticluster.NamespaceExportedServices](ctx, rt.Client, &pbresource.ListRequest{
Type: pbmulticluster.NamespaceExportedServicesType,
Tenancy: req.ID.Tenancy,
})
namespaceExports, err := cache.ListDecoded[*pbmulticluster.NamespaceExportedServices](
rt.Cache,
pbmulticluster.NamespaceExportedServicesType,
"id",
&pbresource.ID{
Type: pbmulticluster.NamespaceExportedServicesType,
Tenancy: req.ID.Tenancy,
},
index.IndexQueryOptions{Prefix: true},
)
if err != nil {
rt.Logger.Error("error retrieving namespace exported service", "error", err)
return err
}
serviceExports, err := resource.ListDecodedResource[*pbmulticluster.ExportedServices](ctx, rt.Client, &pbresource.ListRequest{
Type: pbmulticluster.ExportedServicesType,
Tenancy: req.ID.Tenancy,
})
serviceExports, err := cache.ListDecoded[*pbmulticluster.ExportedServices](
rt.Cache,
pbmulticluster.ExportedServicesType,
"id",
&pbresource.ID{
Type: pbmulticluster.ExportedServicesType,
Tenancy: req.ID.Tenancy,
},
index.IndexQueryOptions{Prefix: true},
)
if err != nil {
rt.Logger.Error("error retrieving exported services", "error", err)