Which fields can you use with Kubernetes field selectors?

Field selectors are a handy filter you can provide kubectl get via the --field-selector option to pare down the list of resources you get back from the server. The docs mention that supported fields vary from resource to resource, but sadly don't mention which resources support which fields. I did a little bit of poking around, and - as far as I can tell - this isn't documented anywhere! So, seeing as reading source code is one of my Maslow's hammers, I broke out that particular hammer and got to reading.

After a little bit of time and effort I managed to find the code that determines which fields are valid for field selectors - you can find it by looking for GetAttrs in **/strategy.go in the Kubernetes repository. So now once this post becomes outdated, you can refresh the list for yourself :)

Here's the list of which resources support which fields (in addition to metadata.namespace and metadata.name, which all resources support) as of Kubernetes 1.20:

CertificateSigningRequestspec.signerName
CronJobstatus.successful
EventinvolvedObject.kind
involvedObject.namespace
involvedObject.name
involvedObject.uid
involvedObject.apiVersion
involvedObject.resourceVersion
involvedObject.fieldPath
reason
source (appears to resolve to metadata.source.component, falls back to reportingComponent)
type
reportingComponent
Jobstatus.successful
JobTemplatestatus.successful
Namespacestatus.phase
Nodespec.unschedulable
Podspec.nodeName
spec.restartPolicy
spec.schedulerName
spec.serviceAccountName
status.phase
status.podIP
status.nominatedNodeName
ReplicationControllerstatus.replicas
Secretstatus.phase
type
StatefulSetstatus.successful
Published on 2022-01-24