Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: try to cache mesh contexts #9145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 27 additions & 15 deletions pkg/core/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@

initializeTokenIssuers(builder)

initializeMeshContextBuilderComponent(builder)
if err := initializeMeshCache(builder); err != nil {
return nil, err
}
Expand All @@ -199,6 +200,10 @@
return nil, err
}

if err := rt.Add(builder.MeshContextBuilderComponent()); err != nil {
return nil, err
}

for name, plugin := range core_plugins.Plugins().RuntimePlugins() {
if err := plugin.Customize(rt); err != nil {
return nil, errors.Wrapf(err, "failed to configure runtime plugin:'%s'", name)
Expand Down Expand Up @@ -493,25 +498,11 @@
builder.WithConfigManager(config_manager.NewConfigManager(builder.ConfigStore()))
}

func initializeMeshCache(builder *core_runtime.Builder) error {

Check failure on line 501 in pkg/core/bootstrap/bootstrap.go

View workflow job for this annotation

GitHub Actions / check

unnecessary leading newline (whitespace)
rsGraphBuilder := xds_context.AnyToAnyReachableServicesGraphBuilder
if builder.Config().Experimental.AutoReachableServices {
rsGraphBuilder = graph.Builder
}
meshContextBuilder := xds_context.NewMeshContextBuilder(
builder.ReadOnlyResourceManager(),
xds_server.MeshResourceTypes(),
builder.LookupIP(),
builder.Config().Multizone.Zone.Name,
vips.NewPersistence(builder.ReadOnlyResourceManager(), builder.ConfigManager(), builder.Config().Experimental.UseTagFirstVirtualOutboundModel),
builder.Config().DNSServer.Domain,
builder.Config().DNSServer.ServiceVipPort,
rsGraphBuilder,
)

Check failure on line 502 in pkg/core/bootstrap/bootstrap.go

View workflow job for this annotation

GitHub Actions / check

File is not `gofumpt`-ed (gofumpt)
meshSnapshotCache, err := mesh_cache.NewCache(
builder.Config().Store.Cache.ExpirationTime.Duration,
meshContextBuilder,
builder.MeshContextBuilderComponent(),
builder.Metrics(),
)
if err != nil {
Expand All @@ -538,3 +529,24 @@
}
builder.WithTokenIssuers(issuers)
}

func initializeMeshContextBuilderComponent(builder *core_runtime.Builder) {
rsGraphBuilder := xds_context.AnyToAnyReachableServicesGraphBuilder
if builder.Config().Experimental.AutoReachableServices {
rsGraphBuilder = graph.Builder
}

meshContextBuilderComponent := xds_context.NewMeshContextBuilderComponent(
builder.ReadOnlyResourceManager(),
xds_server.MeshResourceTypes(),
builder.LookupIP(),
builder.Config().Multizone.Zone.Name,
vips.NewPersistence(builder.ReadOnlyResourceManager(), builder.ConfigManager(), builder.Config().Experimental.UseTagFirstVirtualOutboundModel),
builder.Config().DNSServer.Domain,
builder.Config().DNSServer.ServiceVipPort,
rsGraphBuilder,
builder.EventBus(),
)

builder.WithMeshContextBuilderComponent(meshContextBuilderComponent)
}
77 changes: 46 additions & 31 deletions pkg/core/runtime/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"github.com/kumahq/kuma/pkg/plugins/resources/postgres/config"
"github.com/kumahq/kuma/pkg/tokens/builtin"
"github.com/kumahq/kuma/pkg/xds/cache/mesh"
xds_context "github.com/kumahq/kuma/pkg/xds/context"
xds_runtime "github.com/kumahq/kuma/pkg/xds/runtime"
"github.com/kumahq/kuma/pkg/xds/secrets"
)
Expand Down Expand Up @@ -59,6 +60,7 @@
APIServerAuthenticator() authn.Authenticator
Access() Access
TokenIssuers() builtin.TokenIssuers
MeshContextBuilderComponent() xds_context.MeshContextBuilderComponent
MeshCache() *mesh.Cache
InterCPClientPool() *client.Pool
PgxConfigCustomizationFn() config.PgxConfigCustomization
Expand All @@ -69,37 +71,38 @@

// Builder represents a multi-step initialization process.
type Builder struct {
cfg kuma_cp.Config
cm component.Manager
rs core_store.CustomizableResourceStore
ss store.SecretStore
cs core_store.ResourceStore
txs core_store.Transactions
rm core_manager.CustomizableResourceManager
rom core_manager.ReadOnlyResourceManager
gis globalinsight.GlobalInsightService
cam core_ca.Managers
dsl datasource.Loader
ext context.Context
configm config_manager.ConfigManager
leadInfo component.LeaderInfo
lif lookup.LookupIPFunc
eac admin.EnvoyAdminClient
metrics metrics.Metrics
erf events.EventBus
apim api_server.APIManager
xds xds_runtime.XDSRuntimeContext
cap secrets.CaProvider
dps *dp_server.DpServer
kdsctx *kds_context.Context
rv ResourceValidators
au authn.Authenticator
acc Access
appCtx context.Context
extraReportsFn ExtraReportsFn
tokenIssuers builtin.TokenIssuers
meshCache *mesh.Cache
interCpPool *client.Pool
cfg kuma_cp.Config

Check failure on line 74 in pkg/core/runtime/builder.go

View workflow job for this annotation

GitHub Actions / check

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kumahq/kuma) --custom-order (gci)
cm component.Manager
rs core_store.CustomizableResourceStore
ss store.SecretStore
cs core_store.ResourceStore
txs core_store.Transactions
rm core_manager.CustomizableResourceManager
rom core_manager.ReadOnlyResourceManager
gis globalinsight.GlobalInsightService
cam core_ca.Managers
dsl datasource.Loader
ext context.Context
configm config_manager.ConfigManager
leadInfo component.LeaderInfo
lif lookup.LookupIPFunc
eac admin.EnvoyAdminClient
metrics metrics.Metrics
erf events.EventBus
apim api_server.APIManager
xds xds_runtime.XDSRuntimeContext
cap secrets.CaProvider
dps *dp_server.DpServer
kdsctx *kds_context.Context
rv ResourceValidators
au authn.Authenticator
acc Access
appCtx context.Context
extraReportsFn ExtraReportsFn
tokenIssuers builtin.TokenIssuers
meshContextBuilderComponent xds_context.MeshContextBuilderComponent
meshCache *mesh.Cache

Check failure on line 104 in pkg/core/runtime/builder.go

View workflow job for this annotation

GitHub Actions / check

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kumahq/kuma) --custom-order (gci)
interCpPool *client.Pool
*runtimeInfo
pgxConfigCustomizationFn config.PgxConfigCustomization
tenants multitenant.Tenants
Expand Down Expand Up @@ -270,6 +273,11 @@
return b
}

func (b *Builder) WithMeshContextBuilderComponent(meshContextBuilderComponent xds_context.MeshContextBuilderComponent) *Builder {
b.meshContextBuilderComponent = meshContextBuilderComponent
return b
}

func (b *Builder) WithMeshCache(meshCache *mesh.Cache) *Builder {
b.meshCache = meshCache
return b
Expand Down Expand Up @@ -359,6 +367,9 @@
if b.tokenIssuers == (builtin.TokenIssuers{}) {
return nil, errors.Errorf("TokenIssuers has not been configured")
}
if b.meshContextBuilderComponent == nil {
return nil, errors.Errorf("MeshContextBuilderComponent has not been configured")
}
if b.meshCache == nil {
return nil, errors.Errorf("MeshCache has not been configured")
}
Expand Down Expand Up @@ -523,6 +534,10 @@
return b.eac
}

func (b *Builder) MeshContextBuilderComponent() xds_context.MeshContextBuilderComponent {
return b.meshContextBuilderComponent
}

func (b *Builder) MeshCache() *mesh.Cache {
return b.meshCache
}
Expand Down