fix: correct pod/deployment filtering logic and fix test helper calls

- Remove unused sets import from kubernetesagent
- Fix inverted filtering logic: keep problem pods/deployments, skip healthy ones
- Fix test helper calls: use slice literals instead of undefined makeNamespaceSet
This commit is contained in:
rcourtman 2025-12-18 16:59:37 +00:00
parent 1e955255a6
commit 90a9b78e02
2 changed files with 11 additions and 11 deletions

View file

@ -468,7 +468,7 @@ func (a *Agent) collectPods(ctx context.Context) ([]agentsk8s.Pod, error) {
if !a.namespaceAllowed(pod.Namespace) { if !a.namespaceAllowed(pod.Namespace) {
continue continue
} }
if !a.cfg.IncludeAllPods && isProblemPod(pod) { if !a.cfg.IncludeAllPods && !isProblemPod(pod) {
continue continue
} }
@ -600,7 +600,7 @@ func (a *Agent) collectDeployments(ctx context.Context) ([]agentsk8s.Deployment,
if !a.namespaceAllowed(dep.Namespace) { if !a.namespaceAllowed(dep.Namespace) {
continue continue
} }
if isProblemDeployment(dep) { if !isProblemDeployment(dep) {
continue continue
} }

View file

@ -62,8 +62,8 @@ users:
func TestNamespaceAllowed_IncludeExclude(t *testing.T) { func TestNamespaceAllowed_IncludeExclude(t *testing.T) {
a := &Agent{ a := &Agent{
includeNamespaces: makeNamespaceSet([]string{"a", "b"}), includeNamespaces: []string{"a", "b"},
excludeNamespaces: makeNamespaceSet([]string{"b"}), excludeNamespaces: []string{"b"},
} }
if !a.namespaceAllowed("a") { if !a.namespaceAllowed("a") {
@ -122,9 +122,9 @@ func TestCollectPods_FiltersProblemsAndSorts(t *testing.T) {
MaxPods: 2, MaxPods: 2,
IncludeAllPods: false, IncludeAllPods: false,
}, },
kubeClient: clientset, kubeClient: clientset,
includeNamespaces: makeNamespaceSet(nil), includeNamespaces: nil,
excludeNamespaces: makeNamespaceSet(nil), excludeNamespaces: nil,
} }
pods, err := a.collectPods(context.Background()) pods, err := a.collectPods(context.Background())
@ -165,10 +165,10 @@ func TestCollectDeployments_FiltersProblems(t *testing.T) {
) )
a := &Agent{ a := &Agent{
cfg: Config{IncludeAllPods: false}, cfg: Config{IncludeAllPods: false},
kubeClient: clientset, kubeClient: clientset,
includeNamespaces: makeNamespaceSet(nil), includeNamespaces: nil,
excludeNamespaces: makeNamespaceSet(nil), excludeNamespaces: nil,
} }
deps, err := a.collectDeployments(context.Background()) deps, err := a.collectDeployments(context.Background())