#1796·k8sgpt

bug: PDB analyzer ignores blocked PodDisruptionBudgets with empty or matchExpressions selectors

Author: lofonehCreated Sep 22, 2026Updated Sep 23, 2026
Labelsbug

Expected Behavior

A PodDisruptionBudget with DisruptionAllowed=False should be reported by the PDB analyzer regardless of which selector shape it uses, since a blocked PDB is what wedges a kubectl drain and stalls a node upgrade.

Current Behavior

The PDB analyzer only reports a blocked PDB when its selector uses matchLabels. A blocked PDB is silently dropped when its selector is:

  • empty ({}) — which, per the policy/v1 contract, selects every pod in the namespace, giving it the widest blast radius of any PDB
  • matchExpressions-only — an ordinary, valid selector

In both cases k8sgpt analyze reports No problems detected on a cluster where evictions are blocked.

The cause is in pkg/analyzer/pdb.go: the only place a failure is ever constructed is inside the loop over Selector.MatchLabels, so any selector without matchLabels produces zero failures.

go
if pdb.Spec.Selector != nil && pdb.Spec.Selector.MatchLabels != nil {
    for k, v := range pdb.Spec.Selector.MatchLabels {
        failures = append(failures, ...)   // only failure path
    }
}

For reference, the policy/v1 API contract (k8s.io/api/policy/v1/types.go) states:

A null selector will match no pods, while an empty ({}) selector will select all pods within the namespace.

(A null selector matching no pods is correctly not reported — it cannot block an eviction. Only the empty and matchExpressions cases are wrong.)

Steps to Reproduce

  1. Create a namespace with a single pod and two blocked PDBs:
yaml
apiVersion: v1
kind: Namespace
metadata:
  name: pdb-demo
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: pdb-demo
spec:
  replicas: 1
  selector:
    matchLabels: { app: web }
  template:
    metadata:
      labels: { app: web }
    spec:
      containers:
        - name: app
          image: registry.k8s.io/pause:3.10
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: blocks-everything
  namespace: pdb-demo
spec:
  minAvailable: 1
  selector: {}                 # selects EVERY pod in the namespace
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: expr-selector
  namespace: pdb-demo
spec:
  minAvailable: 1
  selector:
    matchExpressions:
      - { key: app, operator: In, values: ["web"] }
  1. Confirm both PDBs are genuinely blocking evictions:
$ kubectl get pdb -n pdb-demo
NAME                MIN AVAILABLE   MAX UNAVAILABLE   ALLOWED DISRUPTIONS   AGE
blocks-everything   1               N/A               0                     8s
expr-selector       1               N/A               0                     8s

$ kubectl get pdb -n pdb-demo -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.conditions[*].type}{"="}{.status.conditions[*].status}{"\t"}{.status.conditions[*].reason}{"\n"}{end}'
blocks-everything	DisruptionAllowed=False	InsufficientPods
expr-selector	DisruptionAllowed=False	InsufficientPods
  1. Run the analyzer:
$ k8sgpt analyze --filter PodDisruptionBudget --namespace pdb-demo
AI Provider: AI not used; --explain not set

No problems detected
  1. Both blocked PDBs go unreported. Changing either selector to an equivalent matchLabels form makes it appear, which isolates the selector shape as the trigger.

Environment

  • k8sgpt version: v0.4.40-0.20260917124249-8cb270e0800e, built from main at 8cb270e
  • Kubernetes version: v1.34.0 (kind)
  • AI Backend/Provider: none — reproduces without --explain, this is analyzer-side only
  • OS/Platform: Windows 11

Additional Context

There is a second, separate defect in the same function worth noting but not conflating: pdb.go reads pdb.Status.Conditions[0] and assumes DisruptionAllowed sits at index 0. Conditions are an unordered set, so the correct lookup is apimeta.FindStatusCondition. Today the PDB controller sets only that one condition, so it is latent rather than live.

I have a fix with regression tests ready and will open a PR referencing this issue.