Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field selector for pod.spec.restartPolicy #19771

Merged
merged 1 commit into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/api/v1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func addConversionFuncs(scheme *runtime.Scheme) {
"metadata.annotations",
"status.phase",
"status.podIP",
"spec.nodeName":
"spec.nodeName",
"spec.restartPolicy":
return label, value, nil
// This is for backwards compatibility with old v1 clients which send spec.host
case "spec.host":
Expand Down
5 changes: 3 additions & 2 deletions pkg/registry/pod/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher {
func PodToSelectableFields(pod *api.Pod) fields.Set {
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(pod.ObjectMeta, true)
podSpecificFieldsSet := fields.Set{
"spec.nodeName": pod.Spec.NodeName,
"status.phase": string(pod.Status.Phase),
"spec.nodeName": pod.Spec.NodeName,
"spec.restartPolicy": string(pod.Spec.RestartPolicy),
"status.phase": string(pod.Status.Phase),
}
return generic.MergeFieldsSets(objectMetaFieldsSet, podSpecificFieldsSet)
}
Expand Down
61 changes: 61 additions & 0 deletions pkg/registry/pod/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,71 @@ import (
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/testapi"
apitesting "k8s.io/kubernetes/pkg/api/testing"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
)

func TestMatchPod(t *testing.T) {
testCases := []struct {
in *api.Pod
fieldSelector fields.Selector
expectMatch bool
}{
{
in: &api.Pod{
Spec: api.PodSpec{NodeName: "nodeA"},
},
fieldSelector: fields.ParseSelectorOrDie("spec.nodeName=nodeA"),
expectMatch: true,
},
{
in: &api.Pod{
Spec: api.PodSpec{NodeName: "nodeB"},
},
fieldSelector: fields.ParseSelectorOrDie("spec.nodeName=nodeA"),
expectMatch: false,
},
{
in: &api.Pod{
Spec: api.PodSpec{RestartPolicy: api.RestartPolicyAlways},
},
fieldSelector: fields.ParseSelectorOrDie("spec.restartPolicy=Always"),
expectMatch: true,
},
{
in: &api.Pod{
Spec: api.PodSpec{RestartPolicy: api.RestartPolicyAlways},
},
fieldSelector: fields.ParseSelectorOrDie("spec.restartPolicy=Never"),
expectMatch: false,
},
{
in: &api.Pod{
Status: api.PodStatus{Phase: api.PodRunning},
},
fieldSelector: fields.ParseSelectorOrDie("status.phase=Running"),
expectMatch: true,
},
{
in: &api.Pod{
Status: api.PodStatus{Phase: api.PodRunning},
},
fieldSelector: fields.ParseSelectorOrDie("status.phase=Pending"),
expectMatch: false,
},
}
for _, testCase := range testCases {
result, err := MatchPod(labels.Everything(), testCase.fieldSelector).Matches(testCase.in)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
if result != testCase.expectMatch {
t.Errorf("Result %v, Expected %v, Selector: %v, Pod: %v", result, testCase.expectMatch, testCase.fieldSelector.String(), testCase.in)
}
}
}

func TestCheckGracefulDelete(t *testing.T) {
defaultGracePeriod := int64(30)
tcs := []struct {
Expand Down