From 2d5b9f3193ef7a350820fd0d8982cad363b4dd8a Mon Sep 17 00:00:00 2001 From: fabiankramm Date: Thu, 6 Jan 2022 14:56:27 +0100 Subject: [PATCH] refactor: wait for server before starting controllers --- cmd/vcluster/cmd/start.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/cmd/vcluster/cmd/start.go b/cmd/vcluster/cmd/start.go index 2a6e55ff2..ccce71083 100644 --- a/cmd/vcluster/cmd/start.go +++ b/cmd/vcluster/cmd/start.go @@ -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 }