Skip to content

Commit

Permalink
KEP-2170: Initialize runtimes before the manager starts (kubeflow#2306)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Iwai <[email protected]>
  • Loading branch information
tenzen-y authored Oct 24, 2024
1 parent a655a90 commit 9ed4112
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cmd/training-operator.v2alpha1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package main

import (
"context"
"crypto/tls"
"errors"
"flag"
Expand All @@ -40,6 +39,7 @@ import (
kubeflowv2 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v2alpha1"
"github.com/kubeflow/training-operator/pkg/cert"
controllerv2 "github.com/kubeflow/training-operator/pkg/controller.v2"
runtime "github.com/kubeflow/training-operator/pkg/runtime.v2"
runtimecore "github.com/kubeflow/training-operator/pkg/runtime.v2/core"
webhookv2 "github.com/kubeflow/training-operator/pkg/webhook.v2"
)
Expand Down Expand Up @@ -139,8 +139,13 @@ func main() {
ctx := ctrl.SetupSignalHandler()

setupProbeEndpoints(mgr, certsReady)
runtimes, err := runtimecore.New(ctx, mgr.GetClient(), mgr.GetFieldIndexer())
if err != nil {
setupLog.Error(err, "Could not initialize runtimes")
os.Exit(1)
}
// Set up controllers using goroutines to start the manager quickly.
go setupControllers(ctx, mgr, certsReady)
go setupControllers(mgr, runtimes, certsReady)

setupLog.Info("Starting manager")
if err = mgr.Start(ctx); err != nil {
Expand All @@ -149,16 +154,11 @@ func main() {
}
}

func setupControllers(ctx context.Context, mgr ctrl.Manager, certsReady <-chan struct{}) {
func setupControllers(mgr ctrl.Manager, runtimes map[string]runtime.Runtime, certsReady <-chan struct{}) {
setupLog.Info("Waiting for certificate generation to complete")
<-certsReady
setupLog.Info("Certs ready")

runtimes, err := runtimecore.New(ctx, mgr.GetClient(), mgr.GetFieldIndexer())
if err != nil {
setupLog.Error(err, "Could not initialize runtimes")
os.Exit(1)
}
if failedCtrlName, err := controllerv2.SetupControllers(mgr, runtimes); err != nil {
setupLog.Error(err, "Could not create controller", "controller", failedCtrlName)
os.Exit(1)
Expand Down

0 comments on commit 9ed4112

Please sign in to comment.