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
358c092a
Commit
358c092a
authored
Nov 15, 2018
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix storage unit tests leaking feature flag changes
parent
fd64c082
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
97 additions
and
93 deletions
+97
-93
validation_test.go
pkg/apis/core/validation/validation_test.go
+0
-0
BUILD
pkg/apis/storage/util/BUILD
+2
-0
util_test.go
pkg/apis/storage/util/util_test.go
+4
-10
validation_test.go
pkg/apis/storage/validation/validation_test.go
+5
-35
BUILD
pkg/controller/cloud/BUILD
+2
-0
pvlcontroller_test.go
pkg/controller/cloud/pvlcontroller_test.go
+4
-4
BUILD
pkg/scheduler/BUILD
+1
-0
predicates_test.go
pkg/scheduler/algorithm/predicates/predicates_test.go
+3
-8
scheduler_test.go
pkg/scheduler/scheduler_test.go
+2
-2
csi_block_test.go
pkg/volume/csi/csi_block_test.go
+17
-0
csi_plugin_test.go
pkg/volume/csi/csi_plugin_test.go
+23
-5
BUILD
plugin/pkg/admission/storage/persistentvolume/label/BUILD
+2
-0
admission_test.go
...dmission/storage/persistentvolume/label/admission_test.go
+4
-2
BUILD
.../pkg/admission/storage/storageobjectinuseprotection/BUILD
+2
-0
admission_test.go
...on/storage/storageobjectinuseprotection/admission_test.go
+26
-27
No files found.
pkg/apis/core/validation/validation_test.go
View file @
358c092a
This diff is collapsed.
Click to expand it.
pkg/apis/storage/util/BUILD
View file @
358c092a
...
@@ -41,6 +41,8 @@ go_test(
...
@@ -41,6 +41,8 @@ go_test(
deps = [
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/storage:go_default_library",
"//pkg/apis/storage:go_default_library",
"//pkg/features: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",
],
],
)
)
pkg/apis/storage/util/util_test.go
View file @
358c092a
...
@@ -21,8 +21,10 @@ import (
...
@@ -21,8 +21,10 @@ import (
"testing"
"testing"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/features"
)
)
func
TestDropAlphaFields
(
t
*
testing
.
T
)
{
func
TestDropAlphaFields
(
t
*
testing
.
T
)
{
...
@@ -39,9 +41,7 @@ func TestDropAlphaFields(t *testing.T) {
...
@@ -39,9 +41,7 @@ func TestDropAlphaFields(t *testing.T) {
}
}
// Test that field gets dropped when feature gate is not set
// Test that field gets dropped when feature gate is not set
if
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
);
err
!=
nil
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
false
)()
t
.
Fatalf
(
"Failed to set feature gate for VolumeScheduling: %v"
,
err
)
}
class
:=
&
storage
.
StorageClass
{
class
:=
&
storage
.
StorageClass
{
VolumeBindingMode
:
&
bindingMode
,
VolumeBindingMode
:
&
bindingMode
,
AllowedTopologies
:
allowedTopologies
,
AllowedTopologies
:
allowedTopologies
,
...
@@ -59,9 +59,7 @@ func TestDropAlphaFields(t *testing.T) {
...
@@ -59,9 +59,7 @@ func TestDropAlphaFields(t *testing.T) {
VolumeBindingMode
:
&
bindingMode
,
VolumeBindingMode
:
&
bindingMode
,
AllowedTopologies
:
allowedTopologies
,
AllowedTopologies
:
allowedTopologies
,
}
}
if
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
);
err
!=
nil
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
true
)()
t
.
Fatalf
(
"Failed to set feature gate for VolumeScheduling: %v"
,
err
)
}
DropDisabledAlphaFields
(
class
)
DropDisabledAlphaFields
(
class
)
if
class
.
VolumeBindingMode
!=
&
bindingMode
{
if
class
.
VolumeBindingMode
!=
&
bindingMode
{
t
.
Errorf
(
"VolumeBindingMode field got unexpectantly modified: %+v"
,
class
.
VolumeBindingMode
)
t
.
Errorf
(
"VolumeBindingMode field got unexpectantly modified: %+v"
,
class
.
VolumeBindingMode
)
...
@@ -69,8 +67,4 @@ func TestDropAlphaFields(t *testing.T) {
...
@@ -69,8 +67,4 @@ func TestDropAlphaFields(t *testing.T) {
if
!
reflect
.
DeepEqual
(
class
.
AllowedTopologies
,
allowedTopologies
)
{
if
!
reflect
.
DeepEqual
(
class
.
AllowedTopologies
,
allowedTopologies
)
{
t
.
Errorf
(
"AllowedTopologies field got unexpectantly modified: %+v"
,
class
.
AllowedTopologies
)
t
.
Errorf
(
"AllowedTopologies field got unexpectantly modified: %+v"
,
class
.
AllowedTopologies
)
}
}
if
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for VolumeScheduling: %v"
,
err
)
}
}
}
pkg/apis/storage/validation/validation_test.go
View file @
358c092a
...
@@ -514,10 +514,7 @@ func TestValidateVolumeBindingModeAlphaDisabled(t *testing.T) {
...
@@ -514,10 +514,7 @@ func TestValidateVolumeBindingModeAlphaDisabled(t *testing.T) {
"invalid mode"
:
makeClass
(
&
invalidMode
,
nil
),
"invalid mode"
:
makeClass
(
&
invalidMode
,
nil
),
}
}
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
false
)()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to enable feature gate for VolumeScheduling: %v"
,
err
)
}
for
testName
,
storageClass
:=
range
errorCases
{
for
testName
,
storageClass
:=
range
errorCases
{
if
errs
:=
ValidateStorageClass
(
storageClass
);
len
(
errs
)
==
0
{
if
errs
:=
ValidateStorageClass
(
storageClass
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"Expected failure for test: %v"
,
testName
)
t
.
Errorf
(
"Expected failure for test: %v"
,
testName
)
...
@@ -551,11 +548,7 @@ func TestValidateVolumeBindingMode(t *testing.T) {
...
@@ -551,11 +548,7 @@ func TestValidateVolumeBindingMode(t *testing.T) {
}
}
// TODO: remove when feature gate not required
// TODO: remove when feature gate not required
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
)
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
true
)()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to enable feature gate for VolumeScheduling: %v"
,
err
)
}
for
testName
,
testCase
:=
range
cases
{
for
testName
,
testCase
:=
range
cases
{
errs
:=
ValidateStorageClass
(
testCase
.
class
)
errs
:=
ValidateStorageClass
(
testCase
.
class
)
if
testCase
.
shouldSucceed
&&
len
(
errs
)
!=
0
{
if
testCase
.
shouldSucceed
&&
len
(
errs
)
!=
0
{
...
@@ -565,11 +558,6 @@ func TestValidateVolumeBindingMode(t *testing.T) {
...
@@ -565,11 +558,6 @@ func TestValidateVolumeBindingMode(t *testing.T) {
t
.
Errorf
(
"Expected failure for test %q, got success"
,
testName
)
t
.
Errorf
(
"Expected failure for test %q, got success"
,
testName
)
}
}
}
}
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for VolumeScheduling: %v"
,
err
)
}
}
}
type
updateTest
struct
{
type
updateTest
struct
{
...
@@ -618,11 +606,7 @@ func TestValidateUpdateVolumeBindingMode(t *testing.T) {
...
@@ -618,11 +606,7 @@ func TestValidateUpdateVolumeBindingMode(t *testing.T) {
}
}
// TODO: remove when feature gate not required
// TODO: remove when feature gate not required
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
)
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
true
)()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to enable feature gate for VolumeScheduling: %v"
,
err
)
}
for
testName
,
testCase
:=
range
cases
{
for
testName
,
testCase
:=
range
cases
{
errs
:=
ValidateStorageClassUpdate
(
testCase
.
newClass
,
testCase
.
oldClass
)
errs
:=
ValidateStorageClassUpdate
(
testCase
.
newClass
,
testCase
.
oldClass
)
if
testCase
.
shouldSucceed
&&
len
(
errs
)
!=
0
{
if
testCase
.
shouldSucceed
&&
len
(
errs
)
!=
0
{
...
@@ -632,11 +616,6 @@ func TestValidateUpdateVolumeBindingMode(t *testing.T) {
...
@@ -632,11 +616,6 @@ func TestValidateUpdateVolumeBindingMode(t *testing.T) {
t
.
Errorf
(
"Expected failure for %v, got success"
,
testName
)
t
.
Errorf
(
"Expected failure for %v, got success"
,
testName
)
}
}
}
}
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for VolumeScheduling: %v"
,
err
)
}
}
}
func
TestValidateAllowedTopologies
(
t
*
testing
.
T
)
{
func
TestValidateAllowedTopologies
(
t
*
testing
.
T
)
{
...
@@ -930,12 +909,7 @@ func TestValidateAllowedTopologies(t *testing.T) {
...
@@ -930,12 +909,7 @@ func TestValidateAllowedTopologies(t *testing.T) {
},
},
}
}
// TODO: remove when feature gate not required
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
true
)()
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to enable feature gate for VolumeScheduling: %v"
,
err
)
}
for
testName
,
testCase
:=
range
cases
{
for
testName
,
testCase
:=
range
cases
{
errs
:=
ValidateStorageClass
(
testCase
.
class
)
errs
:=
ValidateStorageClass
(
testCase
.
class
)
if
testCase
.
shouldSucceed
&&
len
(
errs
)
!=
0
{
if
testCase
.
shouldSucceed
&&
len
(
errs
)
!=
0
{
...
@@ -946,11 +920,7 @@ func TestValidateAllowedTopologies(t *testing.T) {
...
@@ -946,11 +920,7 @@ func TestValidateAllowedTopologies(t *testing.T) {
}
}
}
}
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
false
)()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for VolumeScheduling: %v"
,
err
)
}
for
testName
,
testCase
:=
range
cases
{
for
testName
,
testCase
:=
range
cases
{
errs
:=
ValidateStorageClass
(
testCase
.
class
)
errs
:=
ValidateStorageClass
(
testCase
.
class
)
if
len
(
errs
)
==
0
&&
testCase
.
class
.
AllowedTopologies
!=
nil
{
if
len
(
errs
)
==
0
&&
testCase
.
class
.
AllowedTopologies
!=
nil
{
...
...
pkg/controller/cloud/BUILD
View file @
358c092a
...
@@ -58,6 +58,7 @@ go_test(
...
@@ -58,6 +58,7 @@ go_test(
"//pkg/cloudprovider/providers/fake:go_default_library",
"//pkg/cloudprovider/providers/fake:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/controller/testutil:go_default_library",
"//pkg/controller/testutil:go_default_library",
"//pkg/features:go_default_library",
"//pkg/kubelet/apis:go_default_library",
"//pkg/kubelet/apis:go_default_library",
"//pkg/scheduler/api:go_default_library",
"//pkg/scheduler/api:go_default_library",
"//pkg/volume/util:go_default_library",
"//pkg/volume/util:go_default_library",
...
@@ -68,6 +69,7 @@ go_test(
...
@@ -68,6 +69,7 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait: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/client-go/informers:go_default_library",
"//staging/src/k8s.io/client-go/informers:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
...
...
pkg/controller/cloud/pvlcontroller_test.go
View file @
358c092a
...
@@ -28,8 +28,10 @@ import (
...
@@ -28,8 +28,10 @@ import (
sets
"k8s.io/apimachinery/pkg/util/sets"
sets
"k8s.io/apimachinery/pkg/util/sets"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/kubernetes/fake"
core
"k8s.io/client-go/testing"
core
"k8s.io/client-go/testing"
"k8s.io/kubernetes/pkg/features"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
...
@@ -449,8 +451,7 @@ func TestCreatePatch(t *testing.T) {
...
@@ -449,8 +451,7 @@ func TestCreatePatch(t *testing.T) {
},
},
}
}
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
)
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
true
)()
defer
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
for
d
,
tc
:=
range
testCases
{
for
d
,
tc
:=
range
testCases
{
cloud
:=
&
fakecloud
.
FakeCloud
{}
cloud
:=
&
fakecloud
.
FakeCloud
{}
client
:=
fake
.
NewSimpleClientset
()
client
:=
fake
.
NewSimpleClientset
()
...
@@ -519,8 +520,7 @@ func TestAddLabelsToVolume(t *testing.T) {
...
@@ -519,8 +520,7 @@ func TestAddLabelsToVolume(t *testing.T) {
},
},
}
}
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
)
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
true
)()
defer
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
for
d
,
tc
:=
range
testCases
{
for
d
,
tc
:=
range
testCases
{
labeledCh
:=
make
(
chan
bool
,
1
)
labeledCh
:=
make
(
chan
bool
,
1
)
...
...
pkg/scheduler/BUILD
View file @
358c092a
...
@@ -45,6 +45,7 @@ go_test(
...
@@ -45,6 +45,7 @@ go_test(
deps = [
deps = [
"//pkg/api/legacyscheme:go_default_library",
"//pkg/api/legacyscheme:go_default_library",
"//pkg/controller/volume/persistentvolume:go_default_library",
"//pkg/controller/volume/persistentvolume:go_default_library",
"//pkg/features:go_default_library",
"//pkg/scheduler/algorithm:go_default_library",
"//pkg/scheduler/algorithm:go_default_library",
"//pkg/scheduler/algorithm/predicates:go_default_library",
"//pkg/scheduler/algorithm/predicates:go_default_library",
"//pkg/scheduler/api:go_default_library",
"//pkg/scheduler/api:go_default_library",
...
...
pkg/scheduler/algorithm/predicates/predicates_test.go
View file @
358c092a
...
@@ -30,7 +30,9 @@ import (
...
@@ -30,7 +30,9 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
v1helper
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
v1helper
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/features"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
...
@@ -4913,10 +4915,7 @@ func TestVolumeZonePredicateWithVolumeBinding(t *testing.T) {
...
@@ -4913,10 +4915,7 @@ func TestVolumeZonePredicateWithVolumeBinding(t *testing.T) {
},
},
}
}
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
)
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
true
)()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to enable feature gate for VolumeScheduling: %v"
,
err
)
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
...
@@ -4937,10 +4936,6 @@ func TestVolumeZonePredicateWithVolumeBinding(t *testing.T) {
...
@@ -4937,10 +4936,6 @@ func TestVolumeZonePredicateWithVolumeBinding(t *testing.T) {
})
})
}
}
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for VolumeScheduling: %v"
,
err
)
}
}
}
func
TestGetMaxVols
(
t
*
testing
.
T
)
{
func
TestGetMaxVols
(
t
*
testing
.
T
)
{
...
...
pkg/scheduler/scheduler_test.go
View file @
358c092a
...
@@ -40,6 +40,7 @@ import (
...
@@ -40,6 +40,7 @@ import (
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/pkg/scheduler/api"
"k8s.io/kubernetes/pkg/scheduler/api"
...
@@ -774,8 +775,7 @@ func TestSchedulerWithVolumeBinding(t *testing.T) {
...
@@ -774,8 +775,7 @@ func TestSchedulerWithVolumeBinding(t *testing.T) {
// This can be small because we wait for pod to finish scheduling first
// This can be small because we wait for pod to finish scheduling first
chanTimeout
:=
2
*
time
.
Second
chanTimeout
:=
2
*
time
.
Second
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
)
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
true
)()
defer
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
table
:=
[]
struct
{
table
:=
[]
struct
{
name
string
name
string
...
...
pkg/volume/csi/csi_block_test.go
View file @
358c092a
...
@@ -25,7 +25,10 @@ import (
...
@@ -25,7 +25,10 @@ import (
api
"k8s.io/api/core/v1"
api
"k8s.io/api/core/v1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
fakeclient
"k8s.io/client-go/kubernetes/fake"
fakeclient
"k8s.io/client-go/kubernetes/fake"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
volumetest
"k8s.io/kubernetes/pkg/volume/testing"
volumetest
"k8s.io/kubernetes/pkg/volume/testing"
)
)
...
@@ -46,6 +49,8 @@ func prepareBlockMapperTest(plug *csiPlugin, specVolumeName string) (*csiBlockMa
...
@@ -46,6 +49,8 @@ func prepareBlockMapperTest(plug *csiPlugin, specVolumeName string) (*csiBlockMa
}
}
func
TestBlockMapperGetGlobalMapPath
(
t
*
testing
.
T
)
{
func
TestBlockMapperGetGlobalMapPath
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -85,6 +90,8 @@ func TestBlockMapperGetGlobalMapPath(t *testing.T) {
...
@@ -85,6 +90,8 @@ func TestBlockMapperGetGlobalMapPath(t *testing.T) {
}
}
func
TestBlockMapperGetStagingPath
(
t
*
testing
.
T
)
{
func
TestBlockMapperGetStagingPath
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -120,6 +127,8 @@ func TestBlockMapperGetStagingPath(t *testing.T) {
...
@@ -120,6 +127,8 @@ func TestBlockMapperGetStagingPath(t *testing.T) {
}
}
func
TestBlockMapperGetPublishPath
(
t
*
testing
.
T
)
{
func
TestBlockMapperGetPublishPath
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -155,6 +164,8 @@ func TestBlockMapperGetPublishPath(t *testing.T) {
...
@@ -155,6 +164,8 @@ func TestBlockMapperGetPublishPath(t *testing.T) {
}
}
func
TestBlockMapperGetDeviceMapPath
(
t
*
testing
.
T
)
{
func
TestBlockMapperGetDeviceMapPath
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -194,6 +205,8 @@ func TestBlockMapperGetDeviceMapPath(t *testing.T) {
...
@@ -194,6 +205,8 @@ func TestBlockMapperGetDeviceMapPath(t *testing.T) {
}
}
func
TestBlockMapperSetupDevice
(
t
*
testing
.
T
)
{
func
TestBlockMapperSetupDevice
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
fakeClient
:=
fakeclient
.
NewSimpleClientset
()
fakeClient
:=
fakeclient
.
NewSimpleClientset
()
...
@@ -259,6 +272,8 @@ func TestBlockMapperSetupDevice(t *testing.T) {
...
@@ -259,6 +272,8 @@ func TestBlockMapperSetupDevice(t *testing.T) {
}
}
func
TestBlockMapperMapDevice
(
t
*
testing
.
T
)
{
func
TestBlockMapperMapDevice
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
fakeClient
:=
fakeclient
.
NewSimpleClientset
()
fakeClient
:=
fakeclient
.
NewSimpleClientset
()
...
@@ -340,6 +355,8 @@ func TestBlockMapperMapDevice(t *testing.T) {
...
@@ -340,6 +355,8 @@ func TestBlockMapperMapDevice(t *testing.T) {
}
}
func
TestBlockMapperTearDownDevice
(
t
*
testing
.
T
)
{
func
TestBlockMapperTearDownDevice
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
fakeClient
:=
fakeclient
.
NewSimpleClientset
()
fakeClient
:=
fakeclient
.
NewSimpleClientset
()
...
...
pkg/volume/csi/csi_plugin_test.go
View file @
358c092a
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
fakeclient
"k8s.io/client-go/kubernetes/fake"
fakeclient
"k8s.io/client-go/kubernetes/fake"
utiltesting
"k8s.io/client-go/util/testing"
utiltesting
"k8s.io/client-go/util/testing"
fakecsi
"k8s.io/csi-api/pkg/client/clientset/versioned/fake"
fakecsi
"k8s.io/csi-api/pkg/client/clientset/versioned/fake"
...
@@ -39,11 +40,6 @@ import (
...
@@ -39,11 +40,6 @@ import (
// create a plugin mgr to load plugins and setup a fake client
// create a plugin mgr to load plugins and setup a fake client
func
newTestPlugin
(
t
*
testing
.
T
,
client
*
fakeclient
.
Clientset
,
csiClient
*
fakecsi
.
Clientset
)
(
*
csiPlugin
,
string
)
{
func
newTestPlugin
(
t
*
testing
.
T
,
client
*
fakeclient
.
Clientset
,
csiClient
*
fakecsi
.
Clientset
)
(
*
csiPlugin
,
string
)
{
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"CSIBlockVolume=true"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to enable feature gate for CSIBlockVolume: %v"
,
err
)
}
tmpDir
,
err
:=
utiltesting
.
MkTmpdir
(
"csi-test"
)
tmpDir
,
err
:=
utiltesting
.
MkTmpdir
(
"csi-test"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"can't create temp dir: %v"
,
err
)
t
.
Fatalf
(
"can't create temp dir: %v"
,
err
)
...
@@ -109,6 +105,8 @@ func makeTestPV(name string, sizeGig int, driverName, volID string) *api.Persist
...
@@ -109,6 +105,8 @@ func makeTestPV(name string, sizeGig int, driverName, volID string) *api.Persist
}
}
func
TestPluginGetPluginName
(
t
*
testing
.
T
)
{
func
TestPluginGetPluginName
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
if
plug
.
GetPluginName
()
!=
"kubernetes.io/csi"
{
if
plug
.
GetPluginName
()
!=
"kubernetes.io/csi"
{
...
@@ -117,6 +115,8 @@ func TestPluginGetPluginName(t *testing.T) {
...
@@ -117,6 +115,8 @@ func TestPluginGetPluginName(t *testing.T) {
}
}
func
TestPluginGetVolumeName
(
t
*
testing
.
T
)
{
func
TestPluginGetVolumeName
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
...
@@ -146,6 +146,8 @@ func TestPluginGetVolumeName(t *testing.T) {
...
@@ -146,6 +146,8 @@ func TestPluginGetVolumeName(t *testing.T) {
}
}
func
TestPluginCanSupport
(
t
*
testing
.
T
)
{
func
TestPluginCanSupport
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -158,6 +160,8 @@ func TestPluginCanSupport(t *testing.T) {
...
@@ -158,6 +160,8 @@ func TestPluginCanSupport(t *testing.T) {
}
}
func
TestPluginConstructVolumeSpec
(
t
*
testing
.
T
)
{
func
TestPluginConstructVolumeSpec
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -218,6 +222,8 @@ func TestPluginConstructVolumeSpec(t *testing.T) {
...
@@ -218,6 +222,8 @@ func TestPluginConstructVolumeSpec(t *testing.T) {
}
}
func
TestPluginNewMounter
(
t
*
testing
.
T
)
{
func
TestPluginNewMounter
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -266,6 +272,8 @@ func TestPluginNewMounter(t *testing.T) {
...
@@ -266,6 +272,8 @@ func TestPluginNewMounter(t *testing.T) {
}
}
func
TestPluginNewUnmounter
(
t
*
testing
.
T
)
{
func
TestPluginNewUnmounter
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -311,6 +319,8 @@ func TestPluginNewUnmounter(t *testing.T) {
...
@@ -311,6 +319,8 @@ func TestPluginNewUnmounter(t *testing.T) {
}
}
func
TestPluginNewAttacher
(
t
*
testing
.
T
)
{
func
TestPluginNewAttacher
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -329,6 +339,8 @@ func TestPluginNewAttacher(t *testing.T) {
...
@@ -329,6 +339,8 @@ func TestPluginNewAttacher(t *testing.T) {
}
}
func
TestPluginNewDetacher
(
t
*
testing
.
T
)
{
func
TestPluginNewDetacher
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -347,6 +359,8 @@ func TestPluginNewDetacher(t *testing.T) {
...
@@ -347,6 +359,8 @@ func TestPluginNewDetacher(t *testing.T) {
}
}
func
TestPluginNewBlockMapper
(
t
*
testing
.
T
)
{
func
TestPluginNewBlockMapper
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -392,6 +406,8 @@ func TestPluginNewBlockMapper(t *testing.T) {
...
@@ -392,6 +406,8 @@ func TestPluginNewBlockMapper(t *testing.T) {
}
}
func
TestPluginNewUnmapper
(
t
*
testing
.
T
)
{
func
TestPluginNewUnmapper
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
@@ -449,6 +465,8 @@ func TestPluginNewUnmapper(t *testing.T) {
...
@@ -449,6 +465,8 @@ func TestPluginNewUnmapper(t *testing.T) {
}
}
func
TestPluginConstructBlockVolumeSpec
(
t
*
testing
.
T
)
{
func
TestPluginConstructBlockVolumeSpec
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
...
plugin/pkg/admission/storage/persistentvolume/label/BUILD
View file @
358c092a
...
@@ -37,6 +37,7 @@ go_test(
...
@@ -37,6 +37,7 @@ go_test(
deps = [
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/cloudprovider/providers/aws:go_default_library",
"//pkg/cloudprovider/providers/aws:go_default_library",
"//pkg/features:go_default_library",
"//pkg/kubelet/apis:go_default_library",
"//pkg/kubelet/apis:go_default_library",
"//pkg/volume/util:go_default_library",
"//pkg/volume/util:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
...
@@ -44,6 +45,7 @@ go_test(
...
@@ -44,6 +45,7 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/admission:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/admission: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",
],
],
)
)
...
...
plugin/pkg/admission/storage/persistentvolume/label/admission_test.go
View file @
358c092a
...
@@ -28,8 +28,10 @@ import (
...
@@ -28,8 +28,10 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apiserver/pkg/admission"
"k8s.io/apiserver/pkg/admission"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/cloudprovider/providers/aws"
"k8s.io/kubernetes/pkg/cloudprovider/providers/aws"
"k8s.io/kubernetes/pkg/features"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
)
)
...
@@ -122,8 +124,8 @@ func TestAdmission(t *testing.T) {
...
@@ -122,8 +124,8 @@ func TestAdmission(t *testing.T) {
},
},
},
},
}
}
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
)
defer
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
defer
utilfeature
testing
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
VolumeScheduling
,
true
)(
)
// Non-cloud PVs are ignored
// Non-cloud PVs are ignored
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
ignoredPV
,
nil
,
api
.
Kind
(
"PersistentVolume"
)
.
WithVersion
(
"version"
),
ignoredPV
.
Namespace
,
ignoredPV
.
Name
,
api
.
Resource
(
"persistentvolumes"
)
.
WithVersion
(
"version"
),
""
,
admission
.
Create
,
false
,
nil
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
ignoredPV
,
nil
,
api
.
Kind
(
"PersistentVolume"
)
.
WithVersion
(
"version"
),
ignoredPV
.
Namespace
,
ignoredPV
.
Name
,
api
.
Resource
(
"persistentvolumes"
)
.
WithVersion
(
"version"
),
""
,
admission
.
Create
,
false
,
nil
))
...
...
plugin/pkg/admission/storage/storageobjectinuseprotection/BUILD
View file @
358c092a
...
@@ -21,12 +21,14 @@ go_test(
...
@@ -21,12 +21,14 @@ go_test(
embed = [":go_default_library"],
embed = [":go_default_library"],
deps = [
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/features:go_default_library",
"//pkg/volume/util:go_default_library",
"//pkg/volume/util:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/admission:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/admission: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",
"//vendor/github.com/davecgh/go-spew/spew:go_default_library",
"//vendor/github.com/davecgh/go-spew/spew:go_default_library",
],
],
)
)
...
...
plugin/pkg/admission/storage/storageobjectinuseprotection/admission_test.go
View file @
358c092a
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
storageobjectinuseprotection
package
storageobjectinuseprotection
import
(
import
(
"fmt"
"reflect"
"reflect"
"testing"
"testing"
...
@@ -27,8 +26,10 @@ import (
...
@@ -27,8 +26,10 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/admission"
"k8s.io/apiserver/pkg/admission"
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/features"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
)
)
...
@@ -118,31 +119,29 @@ func TestAdmit(t *testing.T) {
...
@@ -118,31 +119,29 @@ func TestAdmit(t *testing.T) {
ctrl
:=
newPlugin
()
ctrl
:=
newPlugin
()
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
feature
.
DefaultFeatureGate
.
Set
(
fmt
.
Sprintf
(
"StorageObjectInUseProtection=%v"
,
test
.
featureEnabled
))
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
obj
:=
test
.
object
.
DeepCopyObject
()
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
StorageObjectInUseProtection
,
test
.
featureEnabled
)()
attrs
:=
admission
.
NewAttributesRecord
(
obj
:=
test
.
object
.
DeepCopyObject
()
obj
,
// new object
attrs
:=
admission
.
NewAttributesRecord
(
obj
.
DeepCopyObject
(),
// old object, copy to be sure it's not modified
obj
,
// new object
schema
.
GroupVersionKind
{},
obj
.
DeepCopyObject
(),
// old object, copy to be sure it's not modified
test
.
namespace
,
schema
.
GroupVersionKind
{},
"foo"
,
test
.
namespace
,
test
.
resource
,
"foo"
,
""
,
// subresource
test
.
resource
,
admission
.
Create
,
""
,
// subresource
false
,
// dryRun
admission
.
Create
,
nil
,
// userInfo
false
,
// dryRun
)
nil
,
// userInfo
)
err
:=
ctrl
.
Admit
(
attrs
)
err
:=
ctrl
.
Admit
(
attrs
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Test %q: got unexpected error: %v"
,
test
.
name
,
err
)
t
.
Errorf
(
"Test %q: got unexpected error: %v"
,
test
.
name
,
err
)
}
}
if
!
reflect
.
DeepEqual
(
test
.
expectedObject
,
obj
)
{
if
!
reflect
.
DeepEqual
(
test
.
expectedObject
,
obj
)
{
t
.
Errorf
(
"Test %q: Expected object:
\n
%s
\n
got:
\n
%s"
,
test
.
name
,
spew
.
Sdump
(
test
.
expectedObject
),
spew
.
Sdump
(
obj
))
t
.
Errorf
(
"Test %q: Expected object:
\n
%s
\n
got:
\n
%s"
,
test
.
name
,
spew
.
Sdump
(
test
.
expectedObject
),
spew
.
Sdump
(
obj
))
}
}
})
}
}
// Disable the feature for rest of the tests.
// TODO: remove after alpha
feature
.
DefaultFeatureGate
.
Set
(
"StorageObjectInUseProtection=false"
)
}
}
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