Skip to content

Empty NodeSelectorTerm is confusing in pod.nodeAffinity #126325

@astraw99

Description

@astraw99

What happened?

Pod node affinity with empty NodeSelectorTerm, result in pod Pending.

apiVersion: v1
kind: Pod
metadata:
  name: with-node-affinity
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - {}
  containers:
  - name: with-node-affinity
    image: nginx:1.7.9

k apply -f pod.yaml

k get po
                                 
NAME                                     READY   STATUS    RESTARTS   AGE
with-node-affinity                       0/1     Pending   0          5m3s

Events:
  Type     Reason             Age    From                Message
  ----     ------             ----   ----                -------
  Warning  FailedScheduling   2m52s  default-scheduler   0/3 nodes are available: 3 node(s) didn't match Pod's node affinity/selector. preemption: 0/3 nodes are available: 3 Preemption is not helpful for scheduling..

What did you expect to happen?

Empty NodeSelectorTerm represents no selector, should select all nodes available.
Or empty NodeSelectorTerm should not be allowed in pod.nodeAffinity.

How can we reproduce it (as minimally and precisely as possible)?

See above yaml.

Kubernetes version

$ kubectl version
Client Version: v1.30.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.30.0

Metadata

Metadata

Assignees

Labels

kind/bugCategorizes issue or PR as related to a bug.sig/api-machineryCategorizes an issue or PR as relevant to SIG API Machinery.sig/appsCategorizes an issue or PR as relevant to SIG Apps.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

Status

Needs Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions