Skip to content

Commit

Permalink
refactor: wait for server before starting controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Jan 6, 2022
1 parent 00e7b1b commit 2d5b9f3
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions cmd/vcluster/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,36 +260,38 @@ func ExecuteStart(options *context2.VirtualClusterOptions) error {
return errors.Wrap(err, "create controller context")
}

// start leader election for controllers
rawConfig, err := clientConfig.RawConfig()
// start the proxy
proxyServer, err := server.NewServer(ctx, options.RequestHeaderCaCert, options.ClientCaCert)
if err != nil {
return err
}

// start the proxy server in secure mode
go func() {
if ctx.Options.LeaderElect {
err = leaderelection.StartLeaderElection(ctx, scheme, func() error {
return startControllers(ctx, &rawConfig, serverVersion)
})
} else {
err = startControllers(ctx, &rawConfig, serverVersion)
}
err = proxyServer.ServeOnListenerTLS(options.BindAddress, options.Port, ctx.StopChan)
if err != nil {
klog.Fatalf("Error starting leader election: %v", err)
klog.Fatalf("Error serving: %v", err)
}
}()

// start the proxy
proxyServer, err := server.NewServer(ctx, options.RequestHeaderCaCert, options.ClientCaCert)
// start leader election for controllers
rawConfig, err := clientConfig.RawConfig()
if err != nil {
return err
}

// start the proxy server in secure mode
err = proxyServer.ServeOnListenerTLS(options.BindAddress, options.Port, ctx.StopChan)
if ctx.Options.LeaderElect {
err = leaderelection.StartLeaderElection(ctx, scheme, func() error {
return startControllers(ctx, &rawConfig, serverVersion)
})
} else {
err = startControllers(ctx, &rawConfig, serverVersion)
}
if err != nil {
return err
return errors.Wrap(err, "start controllers")
}

<-ctx.StopChan
return nil
}

Expand Down

0 comments on commit 2d5b9f3

Please sign in to comment.