Skip to content

Commit

Permalink
OSSM-6289 Only watch required resources in analysis controller
Browse files Browse the repository at this point in the history
  • Loading branch information
luksa committed Apr 11, 2024
1 parent d8f16bb commit e391246
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pkg/config/analysis/incluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import (
"istio.io/istio/pkg/config/analysis/analyzers"
"istio.io/istio/pkg/config/analysis/diag"
"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/collections"
"istio.io/istio/pkg/config/schema/collection"
"istio.io/istio/pkg/kube"
"istio.io/pkg/log"
)
Expand All @@ -47,12 +48,19 @@ type Controller struct {
func NewController(stop <-chan struct{}, rwConfigStore model.ConfigStoreController,
kubeClient kube.Client, revision, namespace string, statusManager *status.Manager, domainSuffix string, enableCRDScan bool,
) (*Controller, error) {
ia := local.NewIstiodAnalyzer(analyzers.AllCombined(), "", resource.Namespace(namespace), func(name config.GroupVersionKind) {})
analyzer := analyzers.AllCombined()
ia := local.NewIstiodAnalyzer(analyzer, "", resource.Namespace(namespace), func(name config.GroupVersionKind) {})
ia.AddSource(rwConfigStore)

schemas := kuberesource.ConvertInputsToSchemas(analyzer.Metadata().Inputs)
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, err := crdclient.NewForSchemas(kubeClient,
crdclient.Option{Revision: revision, DomainSuffix: domainSuffix, Identifier: "analysis-controller", EnableCRDScan: enableCRDScan},
collections.All.Remove(rwConfigStore.Schemas().All()...))
schemas)
if err != nil {
return nil, fmt.Errorf("unable to load common types for analysis, releasing lease: %v", err)
}
Expand All @@ -74,6 +82,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{}) {
t := time.NewTicker(features.AnalysisInterval)
Expand Down

0 comments on commit e391246

Please sign in to comment.