mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Merge pull request #7022 from markturansky/ns_controller_indempotent
Made NamespaceManager.Run idempotent and added graceful shutdown
This commit is contained in:
commit
74d6f30b3c
@ -63,13 +63,23 @@ func NewNamespaceManager(kubeClient client.Interface, resyncPeriod time.Duration
|
|||||||
|
|
||||||
return &NamespaceManager{
|
return &NamespaceManager{
|
||||||
controller: controller,
|
controller: controller,
|
||||||
StopEverything: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run begins observing the system. It starts a goroutine and returns immediately.
|
// Run begins observing the system. It starts a goroutine and returns immediately.
|
||||||
func (nm *NamespaceManager) Run() {
|
func (nm *NamespaceManager) Run() {
|
||||||
|
if nm.StopEverything == nil {
|
||||||
|
nm.StopEverything = make(chan struct{})
|
||||||
go nm.controller.Run(nm.StopEverything)
|
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
|
// finalized returns true if the spec.finalizers is empty list
|
||||||
|
@ -18,8 +18,10 @@ package namespace
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
)
|
)
|
||||||
@ -131,3 +133,25 @@ func TestSyncNamespaceThatIsActive(t *testing.T) {
|
|||||||
t.Errorf("Expected no action from controller, but got: %v", actionSet)
|
t.Errorf("Expected no action from controller, but got: %v", actionSet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunStop(t *testing.T) {
|
||||||
|
o := testclient.NewObjects(api.Scheme)
|
||||||
|
client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, latest.RESTMapper)}
|
||||||
|
nsMgr := NewNamespaceManager(client, 1*time.Second)
|
||||||
|
|
||||||
|
if nsMgr.StopEverything != nil {
|
||||||
|
t.Errorf("Non-running manager should not have a stop channel. Got %v", nsMgr.StopEverything)
|
||||||
|
}
|
||||||
|
|
||||||
|
nsMgr.Run()
|
||||||
|
|
||||||
|
if nsMgr.StopEverything == nil {
|
||||||
|
t.Errorf("Running manager should have a stop channel. Got nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
nsMgr.Stop()
|
||||||
|
|
||||||
|
if nsMgr.StopEverything != nil {
|
||||||
|
t.Errorf("Non-running manager should not have a stop channel. Got %v", nsMgr.StopEverything)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user