mirror of https://github.com/status-im/consul.git
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:
parent
3ca4f39fa1
commit
1bd253021b
|
@ -1043,10 +1043,11 @@ func (s *Server) registerControllers(deps Deps, proxyUpdater ProxyUpdater) error
|
||||||
})
|
})
|
||||||
|
|
||||||
auth.RegisterControllers(s.controllerManager, auth.DefaultControllerDependencies())
|
auth.RegisterControllers(s.controllerManager, auth.DefaultControllerDependencies())
|
||||||
}
|
multicluster.RegisterControllers(s.controllerManager)
|
||||||
|
} else {
|
||||||
shim := NewExportedServicesShim(s)
|
shim := NewExportedServicesShim(s)
|
||||||
multicluster.RegisterControllers(s.controllerManager, multicluster.DefaultControllerDependencies(shim))
|
multicluster.RegisterCompatControllers(s.controllerManager, multicluster.DefaultCompatControllerDependencies(shim))
|
||||||
|
}
|
||||||
|
|
||||||
reaper.RegisterControllers(s.controllerManager)
|
reaper.RegisterControllers(s.controllerManager)
|
||||||
|
|
||||||
|
|
|
@ -26,16 +26,26 @@ func RegisterTypes(r resource.Registry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ControllerDependencies = controllers.Dependencies
|
type ControllerDependencies = controllers.Dependencies
|
||||||
|
type CompatControllerDependencies = controllers.CompatDependencies
|
||||||
|
|
||||||
func DefaultControllerDependencies(ac v1compat.AggregatedConfig) ControllerDependencies {
|
func DefaultControllerDependencies() ControllerDependencies {
|
||||||
return ControllerDependencies{
|
return ControllerDependencies{
|
||||||
ExportedServicesSamenessGroupsExpander: exportedServicesSamenessGroupExpander.New(),
|
ExportedServicesSamenessGroupsExpander: exportedServicesSamenessGroupExpander.New(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DefaultCompatControllerDependencies(ac v1compat.AggregatedConfig) CompatControllerDependencies {
|
||||||
|
return CompatControllerDependencies{
|
||||||
ConfigEntryExports: ac,
|
ConfigEntryExports: ac,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterControllers registers controllers for the multicluster types with
|
// RegisterControllers registers controllers for the multicluster types with
|
||||||
// the given controller Manager.
|
// the given controller Manager.
|
||||||
func RegisterControllers(mgr *controller.Manager, deps ControllerDependencies) {
|
func RegisterControllers(mgr *controller.Manager) {
|
||||||
controllers.Register(mgr, deps)
|
controllers.Register(mgr, DefaultControllerDependencies())
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterCompatControllers(mgr *controller.Manager, deps CompatControllerDependencies) {
|
||||||
|
controllers.RegisterCompat(mgr, deps)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,16 @@ import (
|
||||||
|
|
||||||
type Dependencies struct {
|
type Dependencies struct {
|
||||||
ExportedServicesSamenessGroupsExpander exportedservices.ExportedServicesSamenessGroupExpander
|
ExportedServicesSamenessGroupsExpander exportedservices.ExportedServicesSamenessGroupExpander
|
||||||
|
}
|
||||||
|
|
||||||
|
type CompatDependencies struct {
|
||||||
ConfigEntryExports v1compat.AggregatedConfig
|
ConfigEntryExports v1compat.AggregatedConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func Register(mgr *controller.Manager, deps Dependencies) {
|
func Register(mgr *controller.Manager, deps Dependencies) {
|
||||||
mgr.Register(exportedservices.Controller(deps.ExportedServicesSamenessGroupsExpander))
|
mgr.Register(exportedservices.Controller(deps.ExportedServicesSamenessGroupsExpander))
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterCompat(mgr *controller.Manager, deps CompatDependencies) {
|
||||||
mgr.Register(v1compat.Controller(deps.ConfigEntryExports))
|
mgr.Register(v1compat.Controller(deps.ConfigEntryExports))
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"github.com/hashicorp/consul/acl"
|
"github.com/hashicorp/consul/acl"
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
"github.com/hashicorp/consul/internal/controller"
|
"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/multicluster/internal/types"
|
||||||
"github.com/hashicorp/consul/internal/resource"
|
"github.com/hashicorp/consul/internal/resource"
|
||||||
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v2beta1"
|
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,
|
EnterpriseMeta: *entMeta,
|
||||||
}
|
}
|
||||||
|
|
||||||
partitionExports, err := resource.ListDecodedResource[*pbmulticluster.PartitionExportedServices](ctx, rt.Client, &pbresource.ListRequest{
|
partitionExports, err := cache.ListDecoded[*pbmulticluster.PartitionExportedServices](
|
||||||
|
rt.Cache,
|
||||||
|
pbmulticluster.PartitionExportedServicesType,
|
||||||
|
"id",
|
||||||
|
&pbresource.ID{
|
||||||
Type: pbmulticluster.PartitionExportedServicesType,
|
Type: pbmulticluster.PartitionExportedServicesType,
|
||||||
Tenancy: req.ID.Tenancy,
|
Tenancy: req.ID.Tenancy,
|
||||||
})
|
},
|
||||||
|
index.IndexQueryOptions{Prefix: true},
|
||||||
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rt.Logger.Error("error retrieving partition exported services", "error", err)
|
rt.Logger.Error("error retrieving partition exported services", "error", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
namespaceExports, err := resource.ListDecodedResource[*pbmulticluster.NamespaceExportedServices](ctx, rt.Client, &pbresource.ListRequest{
|
namespaceExports, err := cache.ListDecoded[*pbmulticluster.NamespaceExportedServices](
|
||||||
|
rt.Cache,
|
||||||
|
pbmulticluster.NamespaceExportedServicesType,
|
||||||
|
"id",
|
||||||
|
&pbresource.ID{
|
||||||
Type: pbmulticluster.NamespaceExportedServicesType,
|
Type: pbmulticluster.NamespaceExportedServicesType,
|
||||||
Tenancy: req.ID.Tenancy,
|
Tenancy: req.ID.Tenancy,
|
||||||
})
|
},
|
||||||
|
index.IndexQueryOptions{Prefix: true},
|
||||||
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rt.Logger.Error("error retrieving namespace exported service", "error", err)
|
rt.Logger.Error("error retrieving namespace exported service", "error", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceExports, err := resource.ListDecodedResource[*pbmulticluster.ExportedServices](ctx, rt.Client, &pbresource.ListRequest{
|
serviceExports, err := cache.ListDecoded[*pbmulticluster.ExportedServices](
|
||||||
|
rt.Cache,
|
||||||
|
pbmulticluster.ExportedServicesType,
|
||||||
|
"id",
|
||||||
|
&pbresource.ID{
|
||||||
Type: pbmulticluster.ExportedServicesType,
|
Type: pbmulticluster.ExportedServicesType,
|
||||||
Tenancy: req.ID.Tenancy,
|
Tenancy: req.ID.Tenancy,
|
||||||
})
|
},
|
||||||
|
index.IndexQueryOptions{Prefix: true},
|
||||||
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rt.Logger.Error("error retrieving exported services", "error", err)
|
rt.Logger.Error("error retrieving exported services", "error", err)
|
||||||
|
|
Loading…
Reference in New Issue