diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 3c87eb26a..e12848f67 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -524,9 +524,6 @@ func (c *controller) Run(ctx context.Context, workers int) { klog.V(1).Info("Shutting down Machine Controller Manager ") handlers.UpdateHealth(false) - - // TODO: We need to figure out when the shared informers have stopped. - time.Sleep(2 * time.Second) } func (c *controller) shutdownQueues() { diff --git a/pkg/util/permits/permits.go b/pkg/util/permits/permits.go index d1b353a9e..191b4a15b 100644 --- a/pkg/util/permits/permits.go +++ b/pkg/util/permits/permits.go @@ -41,7 +41,7 @@ type permit struct { // NewPermitGiver returns a new PermitGiver func NewPermitGiver(stalePermitKeyTimeout time.Duration, janitorFrequency time.Duration) PermitGiver { - stopC := make(chan struct{}) + stopC := make(chan bool) pg := permitGiver{ keyPermitsMap: sync.Map{}, stopC: stopC, @@ -52,6 +52,7 @@ func NewPermitGiver(stalePermitKeyTimeout time.Duration, janitorFrequency time.D for { select { case <-stopC: + klog.Info("Janitor stopped") return case <-ticker.C: pg.cleanupStalePermitEntries(stalePermitKeyTimeout) @@ -63,7 +64,7 @@ func NewPermitGiver(stalePermitKeyTimeout time.Duration, janitorFrequency time.D type permitGiver struct { keyPermitsMap sync.Map - stopC chan struct{} + stopC chan bool } func (pg *permitGiver) RegisterPermits(key string, numPermits int) { @@ -179,7 +180,9 @@ func (pg *permitGiver) cleanupStalePermitEntries(stalePermitKeyTimeout time.Dura } func (pg *permitGiver) Close() { - close(pg.stopC) + if !pg.isClosed() { + close(pg.stopC) + } // close all permit channels pg.keyPermitsMap.Range(func(key, value interface{}) bool { p := value.(permit) diff --git a/pkg/util/provider/app/app.go b/pkg/util/provider/app/app.go index 5967483d3..756f7713e 100644 --- a/pkg/util/provider/app/app.go +++ b/pkg/util/provider/app/app.go @@ -191,6 +191,7 @@ func Run(ctx context.Context, s *options.MCServer, driver driver.Driver) error { OnStartedLeading: startControllers, OnStoppedLeading: func() { klog.Errorf("leaderelection lost") + waitGroup.Wait() }, }, }) @@ -278,6 +279,7 @@ func StartControllers( klog.V(5).Infof("Creating controllers...") machineController, err := machinecontroller.NewController( + ctx, s.Namespace, controlMachineClient, controlCoreClient, diff --git a/pkg/util/provider/machinecontroller/controller.go b/pkg/util/provider/machinecontroller/controller.go index 056c818fc..0960510fa 100644 --- a/pkg/util/provider/machinecontroller/controller.go +++ b/pkg/util/provider/machinecontroller/controller.go @@ -75,27 +75,7 @@ const ( ) // NewController returns a new Node controller. -func NewController( - namespace string, - controlMachineClient machineapi.MachineV1alpha1Interface, - controlCoreClient kubernetes.Interface, - targetCoreClient kubernetes.Interface, - driver driver.Driver, - pvcInformer coreinformers.PersistentVolumeClaimInformer, - pvInformer coreinformers.PersistentVolumeInformer, - secretInformer coreinformers.SecretInformer, - nodeInformer coreinformers.NodeInformer, - pdbV1beta1Informer policyv1beta1informers.PodDisruptionBudgetInformer, - pdbV1Informer policyv1informers.PodDisruptionBudgetInformer, - volumeAttachmentInformer storageinformers.VolumeAttachmentInformer, - machineClassInformer machineinformers.MachineClassInformer, - machineInformer machineinformers.MachineInformer, - recorder record.EventRecorder, - safetyOptions options.SafetyOptions, - nodeConditions string, - bootstrapTokenAuthExtraGroups string, - targetKubernetesVersion *semver.Version, -) (Controller, error) { +func NewController(ctx context.Context, namespace string, controlMachineClient machineapi.MachineV1alpha1Interface, controlCoreClient kubernetes.Interface, targetCoreClient kubernetes.Interface, driver driver.Driver, pvcInformer coreinformers.PersistentVolumeClaimInformer, pvInformer coreinformers.PersistentVolumeInformer, secretInformer coreinformers.SecretInformer, nodeInformer coreinformers.NodeInformer, pdbV1beta1Informer policyv1beta1informers.PodDisruptionBudgetInformer, pdbV1Informer policyv1informers.PodDisruptionBudgetInformer, volumeAttachmentInformer storageinformers.VolumeAttachmentInformer, machineClassInformer machineinformers.MachineClassInformer, machineInformer machineinformers.MachineInformer, recorder record.EventRecorder, safetyOptions options.SafetyOptions, nodeConditions string, bootstrapTokenAuthExtraGroups string, targetKubernetesVersion *semver.Version) (Controller, error) { const ( // volumeAttachmentGroupName group name volumeAttachmentGroupName = "storage.k8s.io" @@ -343,9 +323,6 @@ func (c *controller) Run(ctx context.Context, workers int) { klog.V(1).Info("Shutting down Machine Controller Manager ") handlers.UpdateHealth(false) - - // TODO: We need to figure out when the shared informers have stopped. - time.Sleep(2 * time.Second) } func (c *controller) shutDown() {