Skip to content

Commit

Permalink
fix relaod if controller-manager.Start() returns (#292)
Browse files Browse the repository at this point in the history
currently kubemacpool is waiting on signals in order to reload the
manager, simulating a kubemacpool restart.
An example is if kubevirt is not ready by the time kubemacpol is up.
In the example - when kubevirt is ready, a channel is closed to signal
kubemacpool to restart.
This commit fixes the waitForSignal method to use the new context based
cancel function.

Signed-off-by: Ram Lavi <[email protected]>
  • Loading branch information
RamLavi authored May 4, 2021
1 parent dd99624 commit 99e59c2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ type KubeMacPoolManager struct {
config *rest.Config
metricsAddr string
continueToRunManager bool
kubevirtInstalledChannel chan struct{} // This channel is close after we found kubevirt to reload the manager
stopSignalChannel chan os.Signal // stop channel signal
podNamespace string // manager pod namespace
podName string // manager pod name
waitingTime int // Duration in second to free macs of allocated vms that failed to start.
runtimeManager manager.Manager // Delegated controller-runtime manager
kubevirtInstalledChannel chan struct{} // This channel is close after we found kubevirt to reload the manager
stopSignalChannel chan os.Signal // stop channel signal
cancel context.CancelFunc // cancel() closes the controller-runtime context internal channel
podNamespace string // manager pod namespace
podName string // manager pod name
waitingTime int // Duration in second to free macs of allocated vms that failed to start.
runtimeManager manager.Manager // Delegated controller-runtime manager
}

func NewKubeMacPoolManager(podNamespace, podName, metricsAddr string, waitingTime int) *KubeMacPoolManager {
Expand Down Expand Up @@ -97,6 +98,8 @@ func (k *KubeMacPoolManager) Run(rangeStart, rangeEnd net.HardwareAddr) error {
return errors.Wrap(err, "unable to create pool manager")
}

var ctx context.Context
ctx, k.cancel = context.WithCancel(context.Background())
if !isKubevirtInstalled {
log.Info("kubevirt was not found in the cluster start a watching process")
go k.waitForKubevirt()
Expand All @@ -120,7 +123,7 @@ func (k *KubeMacPoolManager) Run(rangeStart, rangeEnd net.HardwareAddr) error {
return errors.Wrap(err, "failed to start pool manager routines")
}

err = k.runtimeManager.Start(context.Background())
err = k.runtimeManager.Start(ctx)
if err != nil {
log.Error(err, "unable to run the manager")
}
Expand Down Expand Up @@ -164,6 +167,8 @@ func (k *KubeMacPoolManager) waitForKubevirt() {

// wait for the any interrupt to stop the manager and clean the webhook.
func (k *KubeMacPoolManager) waitForSignal() {
defer k.cancel()

select {
// This channel is a system interrupt this will stop the container
case <-k.stopSignalChannel:
Expand Down

0 comments on commit 99e59c2

Please sign in to comment.