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
79b91b9e
Commit
79b91b9e
authored
May 17, 2016
by
Jan Safranek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor persistent volume initialization
There should be only one initialization function, shared by the real controller and unit tests.
parent
7f549511
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
58 deletions
+62
-58
controllermanager.go
cmd/kube-controller-manager/app/controllermanager.go
+1
-0
controllermanager.go
contrib/mesos/pkg/controllermanager/controllermanager.go
+3
-0
controller_base.go
pkg/controller/persistentvolume/controller_base.go
+39
-39
controller_test.go
pkg/controller/persistentvolume/controller_test.go
+1
-1
framework_test.go
pkg/controller/persistentvolume/framework_test.go
+17
-17
persistent_volumes_test.go
test/integration/persistent_volumes_test.go
+1
-1
No files found.
cmd/kube-controller-manager/app/controllermanager.go
View file @
79b91b9e
...
@@ -385,6 +385,7 @@ func StartControllers(s *options.CMServer, kubeClient *client.Client, kubeconfig
...
@@ -385,6 +385,7 @@ func StartControllers(s *options.CMServer, kubeClient *client.Client, kubeconfig
ProbeRecyclableVolumePlugins
(
s
.
VolumeConfiguration
),
ProbeRecyclableVolumePlugins
(
s
.
VolumeConfiguration
),
cloud
,
cloud
,
s
.
ClusterName
,
s
.
ClusterName
,
nil
,
nil
,
nil
,
)
)
volumeController
.
Run
()
volumeController
.
Run
()
time
.
Sleep
(
wait
.
Jitter
(
s
.
ControllerStartInterval
.
Duration
,
ControllerStartJitter
))
time
.
Sleep
(
wait
.
Jitter
(
s
.
ControllerStartInterval
.
Duration
,
ControllerStartJitter
))
...
...
contrib/mesos/pkg/controllermanager/controllermanager.go
View file @
79b91b9e
...
@@ -283,6 +283,9 @@ func (s *CMServer) Run(_ []string) error {
...
@@ -283,6 +283,9 @@ func (s *CMServer) Run(_ []string) error {
kubecontrollermanager
.
ProbeRecyclableVolumePlugins
(
s
.
VolumeConfiguration
),
kubecontrollermanager
.
ProbeRecyclableVolumePlugins
(
s
.
VolumeConfiguration
),
cloud
,
cloud
,
s
.
ClusterName
,
s
.
ClusterName
,
nil
,
nil
,
nil
,
)
)
volumeController
.
Run
()
volumeController
.
Run
()
...
...
pkg/controller/persistentvolume/controller_base.go
View file @
79b91b9e
...
@@ -46,15 +46,20 @@ func NewPersistentVolumeController(
...
@@ -46,15 +46,20 @@ func NewPersistentVolumeController(
provisioner
vol
.
ProvisionableVolumePlugin
,
provisioner
vol
.
ProvisionableVolumePlugin
,
recyclers
[]
vol
.
VolumePlugin
,
recyclers
[]
vol
.
VolumePlugin
,
cloud
cloudprovider
.
Interface
,
cloud
cloudprovider
.
Interface
,
clusterName
string
)
*
PersistentVolumeController
{
clusterName
string
,
volumeSource
,
claimSource
cache
.
ListerWatcher
,
broadcaster
:=
record
.
NewBroadcaster
()
eventRecorder
record
.
EventRecorder
,
broadcaster
.
StartRecordingToSink
(
&
unversioned_core
.
EventSinkImpl
{
Interface
:
kubeClient
.
Core
()
.
Events
(
""
)})
)
*
PersistentVolumeController
{
recorder
:=
broadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"persistentvolume-controller"
})
if
eventRecorder
==
nil
{
broadcaster
:=
record
.
NewBroadcaster
()
broadcaster
.
StartRecordingToSink
(
&
unversioned_core
.
EventSinkImpl
{
Interface
:
kubeClient
.
Core
()
.
Events
(
""
)})
eventRecorder
=
broadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"persistentvolume-controller"
})
}
controller
:=
&
PersistentVolumeController
{
controller
:=
&
PersistentVolumeController
{
kubeClient
:
kubeClient
,
kubeClient
:
kubeClient
,
eventRecorder
:
r
ecorder
,
eventRecorder
:
eventR
ecorder
,
runningOperations
:
make
(
map
[
string
]
bool
),
runningOperations
:
make
(
map
[
string
]
bool
),
cloud
:
cloud
,
cloud
:
cloud
,
provisioner
:
provisioner
,
provisioner
:
provisioner
,
...
@@ -62,6 +67,7 @@ func NewPersistentVolumeController(
...
@@ -62,6 +67,7 @@ func NewPersistentVolumeController(
createProvisionedPVRetryCount
:
createProvisionedPVRetryCount
,
createProvisionedPVRetryCount
:
createProvisionedPVRetryCount
,
createProvisionedPVInterval
:
createProvisionedPVInterval
,
createProvisionedPVInterval
:
createProvisionedPVInterval
,
}
}
controller
.
recyclePluginMgr
.
InitPlugins
(
recyclers
,
controller
)
controller
.
recyclePluginMgr
.
InitPlugins
(
recyclers
,
controller
)
if
controller
.
provisioner
!=
nil
{
if
controller
.
provisioner
!=
nil
{
if
err
:=
controller
.
provisioner
.
Init
(
controller
);
err
!=
nil
{
if
err
:=
controller
.
provisioner
.
Init
(
controller
);
err
!=
nil
{
...
@@ -69,56 +75,50 @@ func NewPersistentVolumeController(
...
@@ -69,56 +75,50 @@ func NewPersistentVolumeController(
}
}
}
}
volumeSource
:=
&
cache
.
ListWatch
{
if
volumeSource
==
nil
{
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
volumeSource
=
&
cache
.
ListWatch
{
return
kubeClient
.
Core
()
.
PersistentVolumes
()
.
List
(
options
)
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
},
return
kubeClient
.
Core
()
.
PersistentVolumes
()
.
List
(
options
)
WatchFunc
:
func
(
options
api
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
},
return
kubeClient
.
Core
()
.
PersistentVolumes
()
.
Watch
(
options
)
WatchFunc
:
func
(
options
api
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
},
return
kubeClient
.
Core
()
.
PersistentVolumes
()
.
Watch
(
options
)
},
}
}
}
claimSource
:=
&
cache
.
ListWatch
{
if
claimSource
==
nil
{
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
claimSource
=
&
cache
.
ListWatch
{
return
kubeClient
.
Core
()
.
PersistentVolumeClaims
(
api
.
NamespaceAll
)
.
List
(
options
)
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
},
return
kubeClient
.
Core
()
.
PersistentVolumeClaims
(
api
.
NamespaceAll
)
.
List
(
options
)
WatchFunc
:
func
(
options
api
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
},
return
kubeClient
.
Core
()
.
PersistentVolumeClaims
(
api
.
NamespaceAll
)
.
Watch
(
options
)
WatchFunc
:
func
(
options
api
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
},
return
kubeClient
.
Core
()
.
PersistentVolumeClaims
(
api
.
NamespaceAll
)
.
Watch
(
options
)
},
}
}
}
controller
.
initializeController
(
syncPeriod
,
volumeSource
,
claimSource
)
controller
.
volumes
.
store
,
controller
.
volumeController
=
framework
.
NewIndexerInformer
(
return
controller
}
// initializeController prepares watching for PersistentVolume and
// PersistentVolumeClaim events from given sources. This should be used to
// initialize the controller for real operation (with real event sources) and
// also during testing (with fake ones).
func
(
ctrl
*
PersistentVolumeController
)
initializeController
(
syncPeriod
time
.
Duration
,
volumeSource
,
claimSource
cache
.
ListerWatcher
)
{
glog
.
V
(
4
)
.
Infof
(
"initializing PersistentVolumeController, sync every %s"
,
syncPeriod
.
String
())
ctrl
.
volumes
.
store
,
ctrl
.
volumeController
=
framework
.
NewIndexerInformer
(
volumeSource
,
volumeSource
,
&
api
.
PersistentVolume
{},
&
api
.
PersistentVolume
{},
syncPeriod
,
syncPeriod
,
framework
.
ResourceEventHandlerFuncs
{
framework
.
ResourceEventHandlerFuncs
{
AddFunc
:
c
trl
.
addVolume
,
AddFunc
:
c
ontroller
.
addVolume
,
UpdateFunc
:
c
trl
.
updateVolume
,
UpdateFunc
:
c
ontroller
.
updateVolume
,
DeleteFunc
:
c
trl
.
deleteVolume
,
DeleteFunc
:
c
ontroller
.
deleteVolume
,
},
},
cache
.
Indexers
{
"accessmodes"
:
accessModesIndexFunc
},
cache
.
Indexers
{
"accessmodes"
:
accessModesIndexFunc
},
)
)
c
trl
.
claims
,
ctrl
.
claimController
=
framework
.
NewInformer
(
c
ontroller
.
claims
,
controller
.
claimController
=
framework
.
NewInformer
(
claimSource
,
claimSource
,
&
api
.
PersistentVolumeClaim
{},
&
api
.
PersistentVolumeClaim
{},
syncPeriod
,
syncPeriod
,
framework
.
ResourceEventHandlerFuncs
{
framework
.
ResourceEventHandlerFuncs
{
AddFunc
:
c
trl
.
addClaim
,
AddFunc
:
c
ontroller
.
addClaim
,
UpdateFunc
:
c
trl
.
updateClaim
,
UpdateFunc
:
c
ontroller
.
updateClaim
,
DeleteFunc
:
c
trl
.
deleteClaim
,
DeleteFunc
:
c
ontroller
.
deleteClaim
,
},
},
)
)
return
controller
}
}
// addVolume is callback from framework.Controller watching PersistentVolume
// addVolume is callback from framework.Controller watching PersistentVolume
...
...
pkg/controller/persistentvolume/controller_test.go
View file @
79b91b9e
...
@@ -128,7 +128,7 @@ func TestControllerSync(t *testing.T) {
...
@@ -128,7 +128,7 @@ func TestControllerSync(t *testing.T) {
client
:=
&
fake
.
Clientset
{}
client
:=
&
fake
.
Clientset
{}
volumeSource
:=
framework
.
NewFakeControllerSource
()
volumeSource
:=
framework
.
NewFakeControllerSource
()
claimSource
:=
framework
.
NewFakeControllerSource
()
claimSource
:=
framework
.
NewFakeControllerSource
()
ctrl
:=
new
PersistentVolume
Controller
(
client
,
volumeSource
,
claimSource
)
ctrl
:=
new
Test
Controller
(
client
,
volumeSource
,
claimSource
)
reactor
:=
newVolumeReactor
(
client
,
ctrl
,
volumeSource
,
claimSource
,
test
.
errors
)
reactor
:=
newVolumeReactor
(
client
,
ctrl
,
volumeSource
,
claimSource
,
test
.
errors
)
for
_
,
claim
:=
range
test
.
initialClaims
{
for
_
,
claim
:=
range
test
.
initialClaims
{
claimSource
.
Add
(
claim
)
claimSource
.
Add
(
claim
)
...
...
pkg/controller/persistentvolume/framework_test.go
View file @
79b91b9e
...
@@ -484,27 +484,27 @@ func newVolumeReactor(client *fake.Clientset, ctrl *PersistentVolumeController,
...
@@ -484,27 +484,27 @@ func newVolumeReactor(client *fake.Clientset, ctrl *PersistentVolumeController,
return
reactor
return
reactor
}
}
func
newPersistentVolumeController
(
kubeClient
clientset
.
Interface
,
volumeSource
,
claimSource
cache
.
ListerWatcher
)
*
PersistentVolumeController
{
func
newTestController
(
kubeClient
clientset
.
Interface
,
volumeSource
,
claimSource
cache
.
ListerWatcher
)
*
PersistentVolumeController
{
ctrl
:=
&
PersistentVolumeController
{
volumes
:
newPersistentVolumeOrderedIndex
(),
claims
:
cache
.
NewStore
(
cache
.
MetaNamespaceKeyFunc
),
kubeClient
:
kubeClient
,
eventRecorder
:
record
.
NewFakeRecorder
(
1000
),
runningOperations
:
make
(
map
[
string
]
bool
),
// Speed up the testing
createProvisionedPVRetryCount
:
createProvisionedPVRetryCount
,
createProvisionedPVInterval
:
5
*
time
.
Millisecond
,
}
// Create dummy volume/claim sources for controller watchers when needed
if
volumeSource
==
nil
{
if
volumeSource
==
nil
{
volumeSource
=
framework
.
NewFakeControllerSource
()
volumeSource
=
framework
.
NewFakeControllerSource
()
}
}
if
claimSource
==
nil
{
if
claimSource
==
nil
{
claimSource
=
framework
.
NewFakeControllerSource
()
claimSource
=
framework
.
NewFakeControllerSource
()
}
}
ctrl
.
initializeController
(
5
*
time
.
Second
,
volumeSource
,
claimSource
)
ctrl
:=
NewPersistentVolumeController
(
kubeClient
,
5
*
time
.
Second
,
// sync period
nil
,
// provisioner
[]
vol
.
VolumePlugin
{},
// recyclers
nil
,
// cloud
""
,
volumeSource
,
claimSource
,
record
.
NewFakeRecorder
(
1000
),
// event recorder
)
// Speed up the test
ctrl
.
createProvisionedPVInterval
=
5
*
time
.
Millisecond
return
ctrl
return
ctrl
}
}
...
@@ -732,7 +732,7 @@ func runSyncTests(t *testing.T, tests []controllerTest) {
...
@@ -732,7 +732,7 @@ func runSyncTests(t *testing.T, tests []controllerTest) {
// Initialize the controller
// Initialize the controller
client
:=
&
fake
.
Clientset
{}
client
:=
&
fake
.
Clientset
{}
ctrl
:=
new
PersistentVolume
Controller
(
client
,
nil
,
nil
)
ctrl
:=
new
Test
Controller
(
client
,
nil
,
nil
)
reactor
:=
newVolumeReactor
(
client
,
ctrl
,
nil
,
nil
,
test
.
errors
)
reactor
:=
newVolumeReactor
(
client
,
ctrl
,
nil
,
nil
,
test
.
errors
)
for
_
,
claim
:=
range
test
.
initialClaims
{
for
_
,
claim
:=
range
test
.
initialClaims
{
ctrl
.
claims
.
Add
(
claim
)
ctrl
.
claims
.
Add
(
claim
)
...
@@ -776,7 +776,7 @@ func runMultisyncTests(t *testing.T, tests []controllerTest) {
...
@@ -776,7 +776,7 @@ func runMultisyncTests(t *testing.T, tests []controllerTest) {
// Initialize the controller
// Initialize the controller
client
:=
&
fake
.
Clientset
{}
client
:=
&
fake
.
Clientset
{}
ctrl
:=
new
PersistentVolume
Controller
(
client
,
nil
,
nil
)
ctrl
:=
new
Test
Controller
(
client
,
nil
,
nil
)
reactor
:=
newVolumeReactor
(
client
,
ctrl
,
nil
,
nil
,
test
.
errors
)
reactor
:=
newVolumeReactor
(
client
,
ctrl
,
nil
,
nil
,
test
.
errors
)
for
_
,
claim
:=
range
test
.
initialClaims
{
for
_
,
claim
:=
range
test
.
initialClaims
{
ctrl
.
claims
.
Add
(
claim
)
ctrl
.
claims
.
Add
(
claim
)
...
...
test/integration/persistent_volumes_test.go
View file @
79b91b9e
...
@@ -55,7 +55,7 @@ func TestPersistentVolumeRecycler(t *testing.T) {
...
@@ -55,7 +55,7 @@ func TestPersistentVolumeRecycler(t *testing.T) {
plugins
:=
[]
volume
.
VolumePlugin
{
&
volumetest
.
FakeVolumePlugin
{
"plugin-name"
,
host
,
volume
.
VolumeConfig
{},
volume
.
VolumeOptions
{},
0
,
0
,
nil
,
nil
,
nil
,
nil
}}
plugins
:=
[]
volume
.
VolumePlugin
{
&
volumetest
.
FakeVolumePlugin
{
"plugin-name"
,
host
,
volume
.
VolumeConfig
{},
volume
.
VolumeOptions
{},
0
,
0
,
nil
,
nil
,
nil
,
nil
}}
cloud
:=
&
fake_cloud
.
FakeCloud
{}
cloud
:=
&
fake_cloud
.
FakeCloud
{}
ctrl
:=
persistentvolumecontroller
.
NewPersistentVolumeController
(
testClient
,
10
*
time
.
Second
,
nil
,
plugins
,
cloud
,
""
)
ctrl
:=
persistentvolumecontroller
.
NewPersistentVolumeController
(
testClient
,
10
*
time
.
Second
,
nil
,
plugins
,
cloud
,
""
,
nil
,
nil
,
nil
)
ctrl
.
Run
()
ctrl
.
Run
()
defer
ctrl
.
Stop
()
defer
ctrl
.
Stop
()
...
...
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