From 4ba7fd5f3cd8cbe8c7db926dbb423aa78a9ca671 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Thu, 12 Jul 2018 11:13:25 +0200 Subject: [PATCH] added serviceAccountName to field selectors --- pkg/apis/core/v1/conversion.go | 1 + pkg/registry/core/pod/strategy.go | 3 ++- pkg/registry/core/pod/strategy_test.go | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/apis/core/v1/conversion.go b/pkg/apis/core/v1/conversion.go index b8a769921354e..d7a2cf59472d9 100644 --- a/pkg/apis/core/v1/conversion.go +++ b/pkg/apis/core/v1/conversion.go @@ -162,6 +162,7 @@ func addConversionFuncs(scheme *runtime.Scheme) error { "spec.nodeName", "spec.restartPolicy", "spec.schedulerName", + "spec.serviceAccountName", "status.phase", "status.podIP", "status.nominatedNodeName": diff --git a/pkg/registry/core/pod/strategy.go b/pkg/registry/core/pod/strategy.go index a365891112081..87b8bed814918 100644 --- a/pkg/registry/core/pod/strategy.go +++ b/pkg/registry/core/pod/strategy.go @@ -237,10 +237,11 @@ func PodToSelectableFields(pod *api.Pod) fields.Set { // amount of allocations needed to create the fields.Set. If you add any // field here or the number of object-meta related fields changes, this should // be adjusted. - podSpecificFieldsSet := make(fields.Set, 8) + podSpecificFieldsSet := make(fields.Set, 9) podSpecificFieldsSet["spec.nodeName"] = pod.Spec.NodeName podSpecificFieldsSet["spec.restartPolicy"] = string(pod.Spec.RestartPolicy) podSpecificFieldsSet["spec.schedulerName"] = string(pod.Spec.SchedulerName) + podSpecificFieldsSet["spec.serviceAccountName"] = string(pod.Spec.ServiceAccountName) podSpecificFieldsSet["status.phase"] = string(pod.Status.Phase) podSpecificFieldsSet["status.podIP"] = string(pod.Status.PodIP) podSpecificFieldsSet["status.nominatedNodeName"] = string(pod.Status.NominatedNodeName) diff --git a/pkg/registry/core/pod/strategy_test.go b/pkg/registry/core/pod/strategy_test.go index b1c207307f230..e1d6a17669b65 100644 --- a/pkg/registry/core/pod/strategy_test.go +++ b/pkg/registry/core/pod/strategy_test.go @@ -86,6 +86,20 @@ func TestMatchPod(t *testing.T) { fieldSelector: fields.ParseSelectorOrDie("spec.schedulerName=scheduler2"), expectMatch: false, }, + { + in: &api.Pod{ + Spec: api.PodSpec{ServiceAccountName: "serviceAccount1"}, + }, + fieldSelector: fields.ParseSelectorOrDie("spec.serviceAccountName=serviceAccount1"), + expectMatch: true, + }, + { + in: &api.Pod{ + Spec: api.PodSpec{SchedulerName: "serviceAccount1"}, + }, + fieldSelector: fields.ParseSelectorOrDie("spec.serviceAccountName=serviceAccount2"), + expectMatch: false, + }, { in: &api.Pod{ Status: api.PodStatus{Phase: api.PodRunning},