Skip to content

Commit

Permalink
Set up controllers using goroutines to start the manager quickly (#1869)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Iwai <[email protected]>
  • Loading branch information
tenzen-y committed Jul 24, 2023
1 parent 497e759 commit fdf6b83
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions cmd/training-operator.v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package main

import (
"errors"
"flag"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -120,6 +120,30 @@ func main() {
os.Exit(1)
}

// Set up controllers using goroutines to start the manager quickly.
go setupControllers(mgr, enabledSchemes, gangSchedulerName, controllerThreads)

//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}

func setupControllers(mgr ctrl.Manager, enabledSchemes controllerv1.EnabledSchemes, gangSchedulerName string, controllerThreads int) {
setupLog.Info("registering controllers...")

// Prepare GangSchedulingSetupFunc
gangSchedulingSetupFunc := common.GenNonGangSchedulerSetupFunc()
if strings.EqualFold(gangSchedulerName, string(common.GangSchedulerVolcano)) {
Expand All @@ -135,32 +159,16 @@ func main() {
if enabledSchemes.Empty() {
enabledSchemes.FillAll()
}
errMsg := "failed to set up controllers"
for _, s := range enabledSchemes {
setupFunc, supported := controllerv1.SupportedSchemeReconciler[s]
if !supported {
setupLog.Error(fmt.Errorf("cannot find %s in supportedSchemeReconciler", s),
"scheme not supported", "scheme", s)
setupLog.Error(errors.New(errMsg), "scheme is not supported", "scheme", s)
os.Exit(1)
}
if err = setupFunc(mgr, gangSchedulingSetupFunc, controllerThreads); err != nil {
setupLog.Error(err, "unable to create controller", "controller", s)
if err := setupFunc(mgr, gangSchedulingSetupFunc, controllerThreads); err != nil {
setupLog.Error(errors.New(errMsg), "unable to create controller", "scheme", s)
os.Exit(1)
}
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}

0 comments on commit fdf6b83

Please sign in to comment.