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
4c43d626
Commit
4c43d626
authored
Aug 15, 2018
by
lichuqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
related test update
parent
b4a57f68
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
90 deletions
+67
-90
util_test.go
pkg/apis/storage/util/util_test.go
+6
-6
validation_test.go
pkg/apis/storage/validation/validation_test.go
+18
-24
pv_controller_test.go
pkg/controller/volume/persistentvolume/pv_controller_test.go
+21
-47
scheduler_binder_test.go
...ntroller/volume/persistentvolume/scheduler_binder_test.go
+10
-10
util_test.go
pkg/volume/util/util_test.go
+0
-0
cluster-roles.yaml
...thorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml
+10
-0
volume_binding_test.go
test/integration/scheduler/volume_binding_test.go
+2
-3
No files found.
pkg/apis/storage/util/util_test.go
View file @
4c43d626
...
...
@@ -39,8 +39,8 @@ func TestDropAlphaFields(t *testing.T) {
}
// Test that field gets dropped when feature gate is not set
if
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false
,DynamicProvisioningScheduling=false
"
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to set feature gate for VolumeScheduling
or DynamicProvisioningScheduling
: %v"
,
err
)
if
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to set feature gate for VolumeScheduling: %v"
,
err
)
}
class
:=
&
storage
.
StorageClass
{
VolumeBindingMode
:
&
bindingMode
,
...
...
@@ -59,8 +59,8 @@ func TestDropAlphaFields(t *testing.T) {
VolumeBindingMode
:
&
bindingMode
,
AllowedTopologies
:
allowedTopologies
,
}
if
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true
,DynamicProvisioningScheduling=true
"
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to set feature gate for VolumeScheduling
or DynamicProvisioningScheduling
: %v"
,
err
)
if
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to set feature gate for VolumeScheduling: %v"
,
err
)
}
DropDisabledAlphaFields
(
class
)
if
class
.
VolumeBindingMode
!=
&
bindingMode
{
...
...
@@ -70,7 +70,7 @@ func TestDropAlphaFields(t *testing.T) {
t
.
Errorf
(
"AllowedTopologies field got unexpectantly modified: %+v"
,
class
.
AllowedTopologies
)
}
if
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false
,DynamicProvisioningScheduling=false
"
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for VolumeScheduling
or DynamicProvisioningScheduling
: %v"
,
err
)
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 @
4c43d626
...
...
@@ -827,73 +827,67 @@ func TestValidateAllowedTopologies(t *testing.T) {
cases
:=
map
[
string
]
bindingTest
{
"no topology"
:
{
class
:
makeClass
(
nil
,
nil
),
class
:
makeClass
(
&
waitingMode
,
nil
),
shouldSucceed
:
true
,
},
"valid topology"
:
{
class
:
makeClass
(
nil
,
validTopology
),
class
:
makeClass
(
&
waitingMode
,
validTopology
),
shouldSucceed
:
true
,
},
"topology invalid key"
:
{
class
:
makeClass
(
nil
,
topologyInvalidKey
),
class
:
makeClass
(
&
waitingMode
,
topologyInvalidKey
),
shouldSucceed
:
false
,
},
"topology lack of values"
:
{
class
:
makeClass
(
nil
,
topologyLackOfValues
),
class
:
makeClass
(
&
waitingMode
,
topologyLackOfValues
),
shouldSucceed
:
false
,
},
"duplicate TopologySelectorRequirement values"
:
{
class
:
makeClass
(
nil
,
topologyDupValues
),
class
:
makeClass
(
&
waitingMode
,
topologyDupValues
),
shouldSucceed
:
false
,
},
"multiple TopologySelectorRequirement values"
:
{
class
:
makeClass
(
nil
,
topologyMultiValues
),
class
:
makeClass
(
&
waitingMode
,
topologyMultiValues
),
shouldSucceed
:
true
,
},
"empty MatchLabelExpressions"
:
{
class
:
makeClass
(
nil
,
topologyEmptyMatchLabelExpressions
),
class
:
makeClass
(
&
waitingMode
,
topologyEmptyMatchLabelExpressions
),
shouldSucceed
:
false
,
},
"duplicate MatchLabelExpression keys"
:
{
class
:
makeClass
(
nil
,
topologyDupKeys
),
class
:
makeClass
(
&
waitingMode
,
topologyDupKeys
),
shouldSucceed
:
false
,
},
"duplicate MatchLabelExpression keys but across separate terms"
:
{
class
:
makeClass
(
nil
,
topologyMultiTerm
),
class
:
makeClass
(
&
waitingMode
,
topologyMultiTerm
),
shouldSucceed
:
true
,
},
"duplicate AllowedTopologies terms - identical"
:
{
class
:
makeClass
(
nil
,
topologyDupTermsIdentical
),
class
:
makeClass
(
&
waitingMode
,
topologyDupTermsIdentical
),
shouldSucceed
:
false
,
},
"two AllowedTopologies terms, with a pair of the same MatchLabelExpressions and a pair of different ones"
:
{
class
:
makeClass
(
nil
,
topologyExprsOneSameOneDiff
),
class
:
makeClass
(
&
waitingMode
,
topologyExprsOneSameOneDiff
),
shouldSucceed
:
true
,
},
"two AllowedTopologies terms, with a pair of the same Values and a pair of different ones"
:
{
class
:
makeClass
(
nil
,
topologyValuesOneSameOneDiff
),
class
:
makeClass
(
&
waitingMode
,
topologyValuesOneSameOneDiff
),
shouldSucceed
:
true
,
},
"duplicate AllowedTopologies terms - different MatchLabelExpressions order"
:
{
class
:
makeClass
(
nil
,
topologyDupTermsDiffExprOrder
),
class
:
makeClass
(
&
waitingMode
,
topologyDupTermsDiffExprOrder
),
shouldSucceed
:
false
,
},
"duplicate AllowedTopologies terms - different TopologySelectorRequirement values order"
:
{
class
:
makeClass
(
nil
,
topologyDupTermsDiffValueOrder
),
class
:
makeClass
(
&
waitingMode
,
topologyDupTermsDiffValueOrder
),
shouldSucceed
:
false
,
},
}
// Disable VolumeScheduling so nil VolumeBindingMode doesn't fail to validate.
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for VolumeScheduling: %v"
,
err
)
}
// TODO: remove when feature gate not required
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"DynamicProvisioning
Scheduling=true"
)
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"Volume
Scheduling=true"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to enable feature gate for
DynamicProvisioning
Scheduling: %v"
,
err
)
t
.
Fatalf
(
"Failed to enable feature gate for
Volume
Scheduling: %v"
,
err
)
}
for
testName
,
testCase
:=
range
cases
{
...
...
@@ -906,9 +900,9 @@ func TestValidateAllowedTopologies(t *testing.T) {
}
}
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"
DynamicProvisioning
Scheduling=false"
)
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"
Volume
Scheduling=false"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for
DynamicProvisioning
Scheduling: %v"
,
err
)
t
.
Fatalf
(
"Failed to disable feature gate for
Volume
Scheduling: %v"
,
err
)
}
for
testName
,
testCase
:=
range
cases
{
...
...
pkg/controller/volume/persistentvolume/pv_controller_test.go
View file @
4c43d626
...
...
@@ -237,12 +237,21 @@ func addVolumeAnnotation(volume *v1.PersistentVolume, annName, annValue string)
return
volume
}
func
makePVCClass
(
scName
*
string
)
*
v1
.
PersistentVolumeClaim
{
return
&
v1
.
PersistentVolumeClaim
{
func
makePVCClass
(
scName
*
string
,
hasSelectNodeAnno
bool
)
*
v1
.
PersistentVolumeClaim
{
claim
:=
&
v1
.
PersistentVolumeClaim
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{},
},
Spec
:
v1
.
PersistentVolumeClaimSpec
{
StorageClassName
:
scName
,
},
}
if
hasSelectNodeAnno
{
claim
.
Annotations
[
annSelectedNode
]
=
"node-name"
}
return
claim
}
func
makeStorageClass
(
scName
string
,
mode
*
storagev1
.
VolumeBindingMode
)
*
storagev1
.
StorageClass
{
...
...
@@ -271,26 +280,30 @@ func TestDelayBinding(t *testing.T) {
shouldFail
bool
}{
"nil-class"
:
{
pvc
:
makePVCClass
(
nil
),
pvc
:
makePVCClass
(
nil
,
false
),
shouldDelay
:
false
,
},
"class-not-found"
:
{
pvc
:
makePVCClass
(
&
classNotHere
),
pvc
:
makePVCClass
(
&
classNotHere
,
false
),
shouldDelay
:
false
,
},
"no-mode-class"
:
{
pvc
:
makePVCClass
(
&
classNoMode
),
pvc
:
makePVCClass
(
&
classNoMode
,
false
),
shouldDelay
:
false
,
shouldFail
:
true
,
},
"immediate-mode-class"
:
{
pvc
:
makePVCClass
(
&
classImmediateMode
),
pvc
:
makePVCClass
(
&
classImmediateMode
,
false
),
shouldDelay
:
false
,
},
"wait-mode-class"
:
{
pvc
:
makePVCClass
(
&
classWaitMode
),
pvc
:
makePVCClass
(
&
classWaitMode
,
false
),
shouldDelay
:
true
,
},
"wait-mode-class-with-selectedNode"
:
{
pvc
:
makePVCClass
(
&
classWaitMode
,
true
),
shouldDelay
:
false
,
},
}
classes
:=
[]
*
storagev1
.
StorageClass
{
...
...
@@ -314,7 +327,7 @@ func TestDelayBinding(t *testing.T) {
// When volumeScheduling feature gate is disabled, should always be delayed
name
:=
"volumeScheduling-feature-disabled"
shouldDelay
,
err
:=
ctrl
.
shouldDelayBinding
(
makePVCClass
(
&
classWaitMode
))
shouldDelay
,
err
:=
ctrl
.
shouldDelayBinding
(
makePVCClass
(
&
classWaitMode
,
false
))
if
err
!=
nil
{
t
.
Errorf
(
"Test %q returned error: %v"
,
name
,
err
)
}
...
...
@@ -338,43 +351,4 @@ func TestDelayBinding(t *testing.T) {
t
.
Errorf
(
"Test %q returned unexpected %v"
,
name
,
test
.
shouldDelay
)
}
}
// When dynamicProvisioningScheduling feature gate is disabled, should be delayed,
// even if the pvc has selectedNode annotation.
provisionedClaim
:=
makePVCClass
(
&
classWaitMode
)
provisionedClaim
.
Annotations
=
map
[
string
]
string
{
annSelectedNode
:
"node-name"
}
name
=
"dynamicProvisioningScheduling-feature-disabled"
shouldDelay
,
err
=
ctrl
.
shouldDelayBinding
(
provisionedClaim
)
if
err
!=
nil
{
t
.
Errorf
(
"Test %q returned error: %v"
,
name
,
err
)
}
if
!
shouldDelay
{
t
.
Errorf
(
"Test %q returned false, expected true"
,
name
)
}
// Enable DynamicProvisioningScheduling feature gate
utilfeature
.
DefaultFeatureGate
.
Set
(
"DynamicProvisioningScheduling=true"
)
defer
utilfeature
.
DefaultFeatureGate
.
Set
(
"DynamicProvisioningScheduling=false"
)
// When the pvc does not have selectedNode annotation, should be delayed,
// even if dynamicProvisioningScheduling feature gate is enabled.
name
=
"dynamicProvisioningScheduling-feature-enabled, selectedNode-annotation-not-set"
shouldDelay
,
err
=
ctrl
.
shouldDelayBinding
(
makePVCClass
(
&
classWaitMode
))
if
err
!=
nil
{
t
.
Errorf
(
"Test %q returned error: %v"
,
name
,
err
)
}
if
!
shouldDelay
{
t
.
Errorf
(
"Test %q returned false, expected true"
,
name
)
}
// Should not be delayed when dynamicProvisioningScheduling feature gate is enabled,
// and the pvc has selectedNode annotation.
name
=
"dynamicProvisioningScheduling-feature-enabled, selectedNode-annotation-set"
shouldDelay
,
err
=
ctrl
.
shouldDelayBinding
(
provisionedClaim
)
if
err
!=
nil
{
t
.
Errorf
(
"Test %q returned error: %v"
,
name
,
err
)
}
if
shouldDelay
{
t
.
Errorf
(
"Test %q returned true, expected false"
,
name
)
}
}
pkg/controller/volume/persistentvolume/scheduler_binder_test.go
View file @
4c43d626
...
...
@@ -46,10 +46,10 @@ var (
badPVC
=
makeBadPVC
()
immediateUnboundPVC
=
makeTestPVC
(
"immediate-unbound-pvc"
,
"1G"
,
pvcUnbound
,
""
,
"1"
,
&
immediateClass
)
immediateBoundPVC
=
makeTestPVC
(
"immediate-bound-pvc"
,
"1G"
,
pvcBound
,
"pv-bound-immediate"
,
"1"
,
&
immediateClass
)
provisionedPVC
=
makeTestPVC
(
"provisioned-pvc"
,
"1Gi"
,
pvcUnbound
,
""
,
"1"
,
&
waitClass
)
provisionedPVC2
=
makeTestPVC
(
"provisioned-pvc2"
,
"1Gi"
,
pvcUnbound
,
""
,
"1"
,
&
waitClass
)
provisionedPVCHigherVersion
=
makeTestPVC
(
"provisioned-pvc2"
,
"1Gi"
,
pvcUnbound
,
""
,
"2"
,
&
waitClass
)
noProvisionerPVC
=
makeTestPVC
(
"no-provisioner-pvc"
,
"1Gi"
,
pvcUnbound
,
""
,
"1"
,
&
provisionNotSuppor
tClass
)
provisionedPVC
=
makeTestPVC
(
"provisioned-pvc"
,
"1Gi"
,
pvcUnbound
,
""
,
"1"
,
&
waitClass
WithProvisioner
)
provisionedPVC2
=
makeTestPVC
(
"provisioned-pvc2"
,
"1Gi"
,
pvcUnbound
,
""
,
"1"
,
&
waitClass
WithProvisioner
)
provisionedPVCHigherVersion
=
makeTestPVC
(
"provisioned-pvc2"
,
"1Gi"
,
pvcUnbound
,
""
,
"2"
,
&
waitClass
WithProvisioner
)
noProvisionerPVC
=
makeTestPVC
(
"no-provisioner-pvc"
,
"1Gi"
,
pvcUnbound
,
""
,
"1"
,
&
wai
tClass
)
topoMismatchPVC
=
makeTestPVC
(
"topo-mismatch-pvc"
,
"1Gi"
,
pvcUnbound
,
""
,
"1"
,
&
topoMismatchClass
)
pvNoNode
=
makeTestPV
(
"pv-no-node"
,
""
,
"1G"
,
"1"
,
nil
,
waitClass
)
...
...
@@ -74,7 +74,7 @@ var (
waitClass
=
"waitClass"
immediateClass
=
"immediateClass"
provisionNotSupportClass
=
"provisionNotSupportedClass
"
waitClassWithProvisioner
=
"waitClassWithProvisioner
"
topoMismatchClass
=
"topoMismatchClass"
nodeLabelKey
=
"nodeKey"
...
...
@@ -110,7 +110,7 @@ func newTestBinder(t *testing.T) *testEnv {
classes
:=
[]
*
storagev1
.
StorageClass
{
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
waitClass
,
Name
:
waitClass
WithProvisioner
,
},
VolumeBindingMode
:
&
waitMode
,
Provisioner
:
"test-provisioner"
,
...
...
@@ -133,7 +133,7 @@ func newTestBinder(t *testing.T) *testEnv {
},
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
provisionNotSuppor
tClass
,
Name
:
wai
tClass
,
},
VolumeBindingMode
:
&
waitMode
,
Provisioner
:
"kubernetes.io/no-provisioner"
,
...
...
@@ -776,9 +776,9 @@ func TestFindPodVolumesWithProvisioning(t *testing.T) {
},
}
// Set VolumeScheduling
and DynamicProvisioningScheduling
feature gate
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true
,DynamicProvisioningScheduling=true
"
)
defer
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false
,DynamicProvisioningScheduling=false
"
)
// Set VolumeScheduling feature gate
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=true"
)
defer
utilfeature
.
DefaultFeatureGate
.
Set
(
"VolumeScheduling=false"
)
testNode
:=
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
...
...
pkg/volume/util/util_test.go
View file @
4c43d626
This diff is collapsed.
Click to expand it.
plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml
View file @
4c43d626
...
...
@@ -1116,6 +1116,16 @@ items:
-
get
-
list
-
watch
-
apiGroups
:
-
"
"
resources
:
-
persistentvolumeclaims
verbs
:
-
get
-
list
-
patch
-
update
-
watch
-
aggregationRule
:
clusterRoleSelectors
:
-
matchLabels
:
...
...
test/integration/scheduler/volume_binding_test.go
View file @
4c43d626
...
...
@@ -264,9 +264,8 @@ func TestVolumeBinding(t *testing.T) {
// TestVolumeBindingRescheduling tests scheduler will retry scheduling when needed.
func
TestVolumeBindingRescheduling
(
t
*
testing
.
T
)
{
features
:=
map
[
string
]
bool
{
"VolumeScheduling"
:
true
,
"PersistentLocalVolumes"
:
true
,
"DynamicProvisioningScheduling"
:
true
,
"VolumeScheduling"
:
true
,
"PersistentLocalVolumes"
:
true
,
}
config
:=
setupCluster
(
t
,
"volume-scheduling"
,
2
,
features
,
0
)
defer
config
.
teardown
()
...
...
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