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
40b2b5e6
Unverified
Commit
40b2b5e6
authored
Dec 26, 2018
by
Kubernetes Prow Robot
Committed by
GitHub
Dec 26, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #72171 from sbezverk/podPriority_field
PodPriority - Update DropDisabled[Alpha]Fields behaviour
parents
6a61a9af
587c5d72
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
132 additions
and
9 deletions
+132
-9
util.go
pkg/api/pod/util.go
+14
-5
util_test.go
pkg/api/pod/util_test.go
+116
-0
validation.go
pkg/apis/core/validation/validation.go
+2
-4
No files found.
pkg/api/pod/util.go
View file @
40b2b5e6
...
@@ -235,13 +235,11 @@ func UpdatePodCondition(status *api.PodStatus, condition *api.PodCondition) bool
...
@@ -235,13 +235,11 @@ func UpdatePodCondition(status *api.PodStatus, condition *api.PodCondition) bool
// DropDisabledFields removes disabled fields from the pod spec.
// DropDisabledFields removes disabled fields from the pod spec.
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pod spec.
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pod spec.
func
DropDisabledFields
(
podSpec
,
oldPodSpec
*
api
.
PodSpec
)
{
func
DropDisabledFields
(
podSpec
,
oldPodSpec
*
api
.
PodSpec
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
PodPriority
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
PodPriority
)
&&
!
podPriorityInUse
(
oldPodSpec
)
{
// Set to nil pod's priority fields if the feature is disabled and the old pod
// does not specify any values for these fields.
podSpec
.
Priority
=
nil
podSpec
.
Priority
=
nil
podSpec
.
PriorityClassName
=
""
podSpec
.
PriorityClassName
=
""
if
oldPodSpec
!=
nil
{
oldPodSpec
.
Priority
=
nil
oldPodSpec
.
PriorityClassName
=
""
}
}
}
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
LocalStorageCapacityIsolation
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
LocalStorageCapacityIsolation
)
{
...
@@ -419,3 +417,14 @@ func procMountInUse(podSpec *api.PodSpec) bool {
...
@@ -419,3 +417,14 @@ func procMountInUse(podSpec *api.PodSpec) bool {
}
}
return
false
return
false
}
}
// podPriorityInUse returns true if the pod spec is non-nil and has Priority or PriorityClassName set.
func
podPriorityInUse
(
podSpec
*
api
.
PodSpec
)
bool
{
if
podSpec
==
nil
{
return
false
}
if
podSpec
.
Priority
!=
nil
||
podSpec
.
PriorityClassName
!=
""
{
return
true
}
return
false
}
pkg/api/pod/util_test.go
View file @
40b2b5e6
...
@@ -612,3 +612,119 @@ func TestDropProcMount(t *testing.T) {
...
@@ -612,3 +612,119 @@ func TestDropProcMount(t *testing.T) {
}
}
}
}
}
}
func
TestDropPodPriority
(
t
*
testing
.
T
)
{
podPriority
:=
int32
(
1000
)
podWithoutPriority
:=
func
()
*
api
.
Pod
{
return
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Priority
:
nil
,
PriorityClassName
:
""
,
},
}
}
podWithPriority
:=
func
()
*
api
.
Pod
{
return
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Priority
:
&
podPriority
,
PriorityClassName
:
""
,
},
}
}
podWithPriorityClassOnly
:=
func
()
*
api
.
Pod
{
return
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Priority
:
nil
,
PriorityClassName
:
"HighPriorityClass"
,
},
}
}
podWithBothPriorityFields
:=
func
()
*
api
.
Pod
{
return
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Priority
:
&
podPriority
,
PriorityClassName
:
"HighPriorityClass"
,
},
}
}
podInfo
:=
[]
struct
{
description
string
hasPodPriority
bool
pod
func
()
*
api
.
Pod
}{
{
description
:
"pod With no PodPriority fields set"
,
hasPodPriority
:
false
,
pod
:
podWithoutPriority
,
},
{
description
:
"feature disabled and pod With PodPriority field set but class name not set"
,
hasPodPriority
:
true
,
pod
:
podWithPriority
,
},
{
description
:
"feature disabled and pod With PodPriority ClassName field set but PortPriority not set"
,
hasPodPriority
:
true
,
pod
:
podWithPriorityClassOnly
,
},
{
description
:
"feature disabled and pod With both PodPriority ClassName and PodPriority fields set"
,
hasPodPriority
:
true
,
pod
:
podWithBothPriorityFields
,
},
{
description
:
"is nil"
,
hasPodPriority
:
false
,
pod
:
func
()
*
api
.
Pod
{
return
nil
},
},
}
for
_
,
enabled
:=
range
[]
bool
{
true
,
false
}
{
for
_
,
oldPodInfo
:=
range
podInfo
{
for
_
,
newPodInfo
:=
range
podInfo
{
oldPodHasPodPriority
,
oldPod
:=
oldPodInfo
.
hasPodPriority
,
oldPodInfo
.
pod
()
newPodHasPodPriority
,
newPod
:=
newPodInfo
.
hasPodPriority
,
newPodInfo
.
pod
()
if
newPod
==
nil
{
continue
}
t
.
Run
(
fmt
.
Sprintf
(
"feature enabled=%v, old pod %v, new pod %v"
,
enabled
,
oldPodInfo
.
description
,
newPodInfo
.
description
),
func
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
PodPriority
,
enabled
)()
var
oldPodSpec
*
api
.
PodSpec
if
oldPod
!=
nil
{
oldPodSpec
=
&
oldPod
.
Spec
}
DropDisabledFields
(
&
newPod
.
Spec
,
oldPodSpec
)
// old pod should never be changed
if
!
reflect
.
DeepEqual
(
oldPod
,
oldPodInfo
.
pod
())
{
t
.
Errorf
(
"old pod changed: %v"
,
diff
.
ObjectReflectDiff
(
oldPod
,
oldPodInfo
.
pod
()))
}
switch
{
case
enabled
||
oldPodHasPodPriority
:
// new pod should not be changed if the feature is enabled, or if the old pod had PodPriority
if
!
reflect
.
DeepEqual
(
newPod
,
newPodInfo
.
pod
())
{
t
.
Errorf
(
"new pod changed: %v"
,
diff
.
ObjectReflectDiff
(
newPod
,
newPodInfo
.
pod
()))
}
case
newPodHasPodPriority
:
// new pod should be changed
if
reflect
.
DeepEqual
(
newPod
,
newPodInfo
.
pod
())
{
t
.
Errorf
(
"new pod was not changed"
)
}
// new pod should not have PodPriority
if
!
reflect
.
DeepEqual
(
newPod
,
podWithoutPriority
())
{
t
.
Errorf
(
"new pod had PodPriority: %v"
,
diff
.
ObjectReflectDiff
(
newPod
,
podWithoutPriority
()))
}
default
:
// new pod should not need to be changed
if
!
reflect
.
DeepEqual
(
newPod
,
newPodInfo
.
pod
())
{
t
.
Errorf
(
"new pod changed: %v"
,
diff
.
ObjectReflectDiff
(
newPod
,
newPodInfo
.
pod
()))
}
}
})
}
}
}
}
pkg/apis/core/validation/validation.go
View file @
40b2b5e6
...
@@ -3046,10 +3046,8 @@ func ValidatePodSpec(spec *core.PodSpec, fldPath *field.Path) field.ErrorList {
...
@@ -3046,10 +3046,8 @@ func ValidatePodSpec(spec *core.PodSpec, fldPath *field.Path) field.ErrorList {
}
}
if
len
(
spec
.
PriorityClassName
)
>
0
{
if
len
(
spec
.
PriorityClassName
)
>
0
{
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
PodPriority
)
{
for
_
,
msg
:=
range
ValidatePriorityClassName
(
spec
.
PriorityClassName
,
false
)
{
for
_
,
msg
:=
range
ValidatePriorityClassName
(
spec
.
PriorityClassName
,
false
)
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"priorityClassName"
),
spec
.
PriorityClassName
,
msg
))
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"priorityClassName"
),
spec
.
PriorityClassName
,
msg
))
}
}
}
}
}
...
...
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