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
76f2cc6a
Commit
76f2cc6a
authored
Jan 17, 2016
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add field selector for pod.spec.restartPolicy
parent
8081956b
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 @
76f2cc6a
...
...
@@ -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"
:
...
...
pkg/registry/pod/strategy.go
View file @
76f2cc6a
...
...
@@ -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
)
}
...
...
pkg/registry/pod/strategy_test.go
View file @
76f2cc6a
...
...
@@ -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
{
...
...
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