Made NamespaceManager.Run indempotent and added graceful shutdown

This commit is contained in:
markturansky
2015-04-18 10:30:00 -04:00
parent 89fba5ff63
commit 13a38f3e52
2 changed files with 37 additions and 3 deletions

View File

@@ -62,14 +62,24 @@ func NewNamespaceManager(kubeClient client.Interface, resyncPeriod time.Duration
)
return &NamespaceManager{
controller: controller,
StopEverything: make(chan struct{}),
controller: controller,
}
}
// Run begins observing the system. It starts a goroutine and returns immediately.
func (nm *NamespaceManager) Run() {
go nm.controller.Run(nm.StopEverything)
if nm.StopEverything == nil {
nm.StopEverything = make(chan struct{})
go nm.controller.Run(nm.StopEverything)
}
}
// Stop gracefully shutsdown this controller
func (nm *NamespaceManager) Stop() {
if nm.StopEverything != nil {
close(nm.StopEverything)
nm.StopEverything = nil
}
}
// finalized returns true if the spec.finalizers is empty list