Advisor: Avoid evaluating a check for another namespace (#101885)

This commit is contained in:
Andres Martinez Gotor
2025-03-10 17:09:11 +01:00
committed by GitHub
parent 8c51af49e5
commit 8142aef64d
+14
View File
@@ -13,6 +13,7 @@ import (
"github.com/grafana/grafana/apps/advisor/pkg/app/checks"
"github.com/grafana/grafana/apps/advisor/pkg/app/checkscheduler"
"github.com/grafana/grafana/apps/advisor/pkg/app/checktyperegisterer"
"github.com/grafana/grafana/pkg/infra/log"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
)
@@ -24,6 +25,12 @@ func New(cfg app.Config) (app.App, error) {
return nil, fmt.Errorf("invalid config type")
}
checkRegistry := specificConfig.CheckRegistry
stackID := specificConfig.StackID
namespace, err := checks.GetNamespace(stackID)
if err != nil {
return nil, err
}
log := log.New("advisor.app")
// Prepare storage client
clientGenerator := k8s.NewClientRegistry(cfg.KubeConfig, k8s.ClientConfig{})
@@ -60,6 +67,13 @@ func New(cfg app.Config) (app.App, error) {
},
Watcher: &simple.Watcher{
AddFunc: func(ctx context.Context, obj resource.Object) error {
log.Debug("Adding check", "namespace", obj.GetNamespace())
if obj.GetNamespace() != namespace {
log.Debug("Skipping check in namespace", "namespace", obj.GetNamespace())
return nil
} else {
log.Debug("Processing check in namespace", "namespace", obj.GetNamespace())
}
check, err := getCheck(obj, checkMap)
if err != nil {
return err