diff --git a/pkg/analysis/analysis.go b/pkg/analysis/analysis.go index 20ced22e..cfd78ce7 100644 --- a/pkg/analysis/analysis.go +++ b/pkg/analysis/analysis.go @@ -35,6 +35,7 @@ import ( "github.com/k8sgpt-ai/k8sgpt/pkg/util" "github.com/schollz/progressbar/v3" "github.com/spf13/viper" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) type Analysis struct { @@ -227,6 +228,15 @@ func (a *Analysis) CustomAnalyzersAreAvailable() bool { } func (a *Analysis) RunCustomAnalysis() { + // Validate namespace if specified, consistent with built-in filter behavior + if a.Namespace != "" && a.Client != nil { + _, err := a.Client.Client.CoreV1().Namespaces().Get(a.Context, a.Namespace, metav1.GetOptions{}) + if err != nil { + a.Errors = append(a.Errors, fmt.Sprintf("namespace %q not found: %s", a.Namespace, err)) + return + } + } + var customAnalyzers []custom.CustomAnalyzer if err := viper.UnmarshalKey("custom_analyzers", &customAnalyzers); err != nil { a.Errors = append(a.Errors, err.Error())