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
c666bd00
Commit
c666bd00
authored
Apr 24, 2019
by
Tim Allclair
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drop RuntimeClass from PSP when feature is disabled
parent
1bd4340c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
0 deletions
+59
-0
BUILD
pkg/api/podsecuritypolicy/BUILD
+1
-0
util.go
pkg/api/podsecuritypolicy/util.go
+4
-0
util_test.go
pkg/api/podsecuritypolicy/util_test.go
+54
-0
No files found.
pkg/api/podsecuritypolicy/BUILD
View file @
c666bd00
...
@@ -41,5 +41,6 @@ go_test(
...
@@ -41,5 +41,6 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
],
)
)
pkg/api/podsecuritypolicy/util.go
View file @
c666bd00
...
@@ -38,6 +38,10 @@ func DropDisabledFields(pspSpec, oldPSPSpec *policy.PodSecurityPolicySpec) {
...
@@ -38,6 +38,10 @@ func DropDisabledFields(pspSpec, oldPSPSpec *policy.PodSecurityPolicySpec) {
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
CSIInlineVolume
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
CSIInlineVolume
)
{
pspSpec
.
AllowedCSIDrivers
=
nil
pspSpec
.
AllowedCSIDrivers
=
nil
}
}
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
RuntimeClass
)
&&
(
oldPSPSpec
==
nil
||
oldPSPSpec
.
RuntimeClass
==
nil
)
{
pspSpec
.
RuntimeClass
=
nil
}
}
}
func
allowedProcMountTypesInUse
(
oldPSPSpec
*
policy
.
PodSecurityPolicySpec
)
bool
{
func
allowedProcMountTypesInUse
(
oldPSPSpec
*
policy
.
PodSecurityPolicySpec
)
bool
{
...
...
pkg/api/podsecuritypolicy/util_test.go
View file @
c666bd00
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
"reflect"
"reflect"
"testing"
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/diff"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
...
@@ -276,3 +278,55 @@ func TestDropSysctls(t *testing.T) {
...
@@ -276,3 +278,55 @@ func TestDropSysctls(t *testing.T) {
}
}
}
}
}
}
func
TestDropRuntimeClass
(
t
*
testing
.
T
)
{
type
testcase
struct
{
name
string
featureEnabled
bool
pspSpec
,
oldPSPSpec
*
policy
.
PodSecurityPolicySpec
expectRuntimeClass
bool
}
tests
:=
[]
testcase
{}
pspGenerator
:=
func
(
withRuntimeClass
bool
)
*
policy
.
PodSecurityPolicySpec
{
psp
:=
&
policy
.
PodSecurityPolicySpec
{}
if
withRuntimeClass
{
psp
.
RuntimeClass
=
&
policy
.
RuntimeClassStrategyOptions
{
AllowedRuntimeClassNames
:
[]
string
{
policy
.
AllowAllRuntimeClassNames
},
}
}
return
psp
}
for
_
,
enabled
:=
range
[]
bool
{
true
,
false
}
{
for
_
,
hasRuntimeClass
:=
range
[]
bool
{
true
,
false
}
{
tests
=
append
(
tests
,
testcase
{
name
:
fmt
.
Sprintf
(
"create feature:%t hasRC:%t"
,
enabled
,
hasRuntimeClass
),
featureEnabled
:
enabled
,
pspSpec
:
pspGenerator
(
hasRuntimeClass
),
expectRuntimeClass
:
enabled
&&
hasRuntimeClass
,
})
for
_
,
hadRuntimeClass
:=
range
[]
bool
{
true
,
false
}
{
tests
=
append
(
tests
,
testcase
{
name
:
fmt
.
Sprintf
(
"update feature:%t hasRC:%t hadRC:%t"
,
enabled
,
hasRuntimeClass
,
hadRuntimeClass
),
featureEnabled
:
enabled
,
pspSpec
:
pspGenerator
(
hasRuntimeClass
),
oldPSPSpec
:
pspGenerator
(
hadRuntimeClass
),
expectRuntimeClass
:
hasRuntimeClass
&&
(
enabled
||
hadRuntimeClass
),
})
}
}
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
RuntimeClass
,
test
.
featureEnabled
)()
DropDisabledFields
(
test
.
pspSpec
,
test
.
oldPSPSpec
)
if
test
.
expectRuntimeClass
{
assert
.
NotNil
(
t
,
test
.
pspSpec
.
RuntimeClass
)
}
else
{
assert
.
Nil
(
t
,
test
.
pspSpec
.
RuntimeClass
)
}
})
}
}
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