Skip to content

Commit

Permalink
OSSM-6289 Only watch required resources in analysis controller (maist…
Browse files Browse the repository at this point in the history
…ra#978)

Co-authored-by: Marko Lukša <[email protected]>
Signed-off-by: Yann Liu <[email protected]>
  • Loading branch information
luksa authored and yannuil committed Jun 5, 2024
1 parent 1f3a0b4 commit 3e1a060
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/config/analysis/incluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"istio.io/istio/pkg/config/analysis/local"
"istio.io/istio/pkg/config/legacy/util/kuberesource"
"istio.io/istio/pkg/config/resource"
"istio.io/istio/pkg/config/schema/collection"
"istio.io/istio/pkg/config/schema/collections"
"istio.io/istio/pkg/kube"
"istio.io/istio/pkg/log"
"istio.io/istio/pkg/util/concurrent"
Expand All @@ -50,21 +52,26 @@ func NewController(stop <-chan struct{}, rwConfigStore model.ConfigStoreControll
kubeClient kube.Client, revision, namespace string, statusManager *status.Manager, domainSuffix string,
) (*Controller, error) {
analyzer := analyzers.AllCombined()
all := kuberesource.ConvertInputsToSchemas(analyzer.Metadata().Inputs)

ia := local.NewIstiodAnalyzer(analyzer, "", resource.Namespace(namespace), func(name config.GroupVersionKind) {})
ia.AddSource(rwConfigStore)

schemas := kuberesource.ConvertInputsToSchemas(analyzer.Metadata().Inputs).
Remove(collections.MeshConfig). // this is not an actual resource
Remove(collections.MeshNetworks) // this is not an actual resource
if kubeClient.IsMultiTenant() {
schemas = removeClusterScoped(schemas)
}
// Filter out configs watched by rwConfigStore so we don't watch multiple times
schemas = schemas.Remove(rwConfigStore.Schemas().All()...)
store := crdclient.NewForSchemas(kubeClient,
crdclient.Option{
Revision: revision,
DomainSuffix: domainSuffix,
Identifier: "analysis-controller",
FiltersByGVK: ia.GetFiltersByGVK(),
},
all.Remove(rwConfigStore.Schemas().All()...))

schemas)
ia.AddSource(store)
kubeClient.RunAndWait(stop)
err := ia.Init(stop)
Expand All @@ -83,6 +90,16 @@ func NewController(stop <-chan struct{}, rwConfigStore model.ConfigStoreControll
return &Controller{analyzer: ia, statusctl: ctl}, nil
}

func removeClusterScoped(schemas collection.Schemas) collection.Schemas {
b := collection.NewSchemasBuilder()
for _, s := range schemas.All() {
if !s.IsClusterScoped() {
b.MustAdd(s)
}
}
return b.Build()
}

// Run is blocking
func (c *Controller) Run(stop <-chan struct{}) {
db := concurrent.Debouncer[config.GroupVersionKind]{}
Expand Down

0 comments on commit 3e1a060

Please sign in to comment.