Skip to content

Commit

Permalink
Add context to permitgiver
Browse files Browse the repository at this point in the history
  • Loading branch information
afritzler committed Nov 9, 2022
1 parent d456e17 commit 6913520
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 30 deletions.
3 changes: 0 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 6 additions & 3 deletions pkg/util/permits/permits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/provider/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
},
})
Expand Down Expand Up @@ -278,6 +279,7 @@ func StartControllers(

klog.V(5).Infof("Creating controllers...")
machineController, err := machinecontroller.NewController(
ctx,
s.Namespace,
controlMachineClient,
controlCoreClient,
Expand Down
25 changes: 1 addition & 24 deletions pkg/util/provider/machinecontroller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 6913520

Please sign in to comment.