Skip to content

Commit

Permalink
Merge pull request #277 from FabianKramm/v0.5
Browse files Browse the repository at this point in the history
refactor: wait for server before starting controllers
  • Loading branch information
FabianKramm authored Jan 6, 2022
2 parents 990faad + 2d5b9f3 commit dab0403
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 dab0403

Please sign in to comment.