Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ef505d8f
Commit
ef505d8f
authored
Feb 17, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19771 from derekwaynecarr/field_selector
Auto commit by PR queue bot
parents
0866c377
76f2cc6a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
3 deletions
+66
-3
conversion.go
pkg/api/v1/conversion.go
+2
-1
strategy.go
pkg/registry/pod/strategy.go
+3
-2
strategy_test.go
pkg/registry/pod/strategy_test.go
+61
-0
No files found.
pkg/api/v1/conversion.go
View file @
ef505d8f
...
@@ -87,7 +87,8 @@ func addConversionFuncs(scheme *runtime.Scheme) {
...
@@ -87,7 +87,8 @@ func addConversionFuncs(scheme *runtime.Scheme) {
"metadata.annotations"
,
"metadata.annotations"
,
"status.phase"
,
"status.phase"
,
"status.podIP"
,
"status.podIP"
,
"spec.nodeName"
:
"spec.nodeName"
,
"spec.restartPolicy"
:
return
label
,
value
,
nil
return
label
,
value
,
nil
// This is for backwards compatibility with old v1 clients which send spec.host
// This is for backwards compatibility with old v1 clients which send spec.host
case
"spec.host"
:
case
"spec.host"
:
...
...
pkg/registry/pod/strategy.go
View file @
ef505d8f
...
@@ -173,8 +173,9 @@ func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher {
...
@@ -173,8 +173,9 @@ func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher {
func
PodToSelectableFields
(
pod
*
api
.
Pod
)
fields
.
Set
{
func
PodToSelectableFields
(
pod
*
api
.
Pod
)
fields
.
Set
{
objectMetaFieldsSet
:=
generic
.
ObjectMetaFieldsSet
(
pod
.
ObjectMeta
,
true
)
objectMetaFieldsSet
:=
generic
.
ObjectMetaFieldsSet
(
pod
.
ObjectMeta
,
true
)
podSpecificFieldsSet
:=
fields
.
Set
{
podSpecificFieldsSet
:=
fields
.
Set
{
"spec.nodeName"
:
pod
.
Spec
.
NodeName
,
"spec.nodeName"
:
pod
.
Spec
.
NodeName
,
"status.phase"
:
string
(
pod
.
Status
.
Phase
),
"spec.restartPolicy"
:
string
(
pod
.
Spec
.
RestartPolicy
),
"status.phase"
:
string
(
pod
.
Status
.
Phase
),
}
}
return
generic
.
MergeFieldsSets
(
objectMetaFieldsSet
,
podSpecificFieldsSet
)
return
generic
.
MergeFieldsSets
(
objectMetaFieldsSet
,
podSpecificFieldsSet
)
}
}
...
...
pkg/registry/pod/strategy_test.go
View file @
ef505d8f
...
@@ -24,10 +24,71 @@ import (
...
@@ -24,10 +24,71 @@ import (
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"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
)
{
func
TestCheckGracefulDelete
(
t
*
testing
.
T
)
{
defaultGracePeriod
:=
int64
(
30
)
defaultGracePeriod
:=
int64
(
30
)
tcs
:=
[]
struct
{
tcs
:=
[]
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment