From 58669f6f1d0c894c7a1dc8e2805bcde946987dd7 Mon Sep 17 00:00:00 2001 From: Di Xu Date: Mon, 14 Aug 2017 09:49:46 +0800 Subject: [PATCH] support fieldSelector spec.schedulerName --- pkg/api/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/api/v1/conversion.go b/pkg/api/v1/conversion.go index 72b07cffd58..f53f24858a9 100644 --- a/pkg/api/v1/conversion.go +++ b/pkg/api/v1/conversion.go @@ -192,6 +192,7 @@ func addConversionFuncs(scheme *runtime.Scheme) error { "spec.nodeName", "spec.restartPolicy", "spec.serviceAccountName", + "spec.schedulerName", "status.phase", "status.hostIP", "status.podIP": diff --git a/pkg/registry/core/pod/strategy.go b/pkg/registry/core/pod/strategy.go index 9337ef9b994..2c6bbf52376 100644 --- a/pkg/registry/core/pod/strategy.go +++ b/pkg/registry/core/pod/strategy.go @@ -196,9 +196,10 @@ 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, 6) + podSpecificFieldsSet := make(fields.Set, 7) podSpecificFieldsSet["spec.nodeName"] = pod.Spec.NodeName podSpecificFieldsSet["spec.restartPolicy"] = string(pod.Spec.RestartPolicy) + podSpecificFieldsSet["spec.schedulerName"] = string(pod.Spec.SchedulerName) podSpecificFieldsSet["status.phase"] = string(pod.Status.Phase) podSpecificFieldsSet["status.podIP"] = string(pod.Status.PodIP) return generic.AddObjectMetaFieldsSet(podSpecificFieldsSet, &pod.ObjectMeta, true) diff --git a/pkg/registry/core/pod/strategy_test.go b/pkg/registry/core/pod/strategy_test.go index e2f34621085..4d602cb0656 100644 --- a/pkg/registry/core/pod/strategy_test.go +++ b/pkg/registry/core/pod/strategy_test.go @@ -71,6 +71,20 @@ func TestMatchPod(t *testing.T) { fieldSelector: fields.ParseSelectorOrDie("spec.restartPolicy=Never"), expectMatch: false, }, + { + in: &api.Pod{ + Spec: api.PodSpec{SchedulerName: "scheduler1"}, + }, + fieldSelector: fields.ParseSelectorOrDie("spec.schedulerName=scheduler1"), + expectMatch: true, + }, + { + in: &api.Pod{ + Spec: api.PodSpec{SchedulerName: "scheduler1"}, + }, + fieldSelector: fields.ParseSelectorOrDie("spec.schedulerName=scheduler2"), + expectMatch: false, + }, { in: &api.Pod{ Status: api.PodStatus{Phase: api.PodRunning},