Skip to content

Commit

Permalink
cmd: lazily create client
Browse files Browse the repository at this point in the history
to avoid to break the render flow, create the client
lazily, not eagerly.

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Jul 31, 2024
1 parent 14a53f5 commit 7b8e051
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 0 additions & 8 deletions cmd/deployer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"k8s.io/klog/v2/klogr"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/k8stopologyawareschedwg/deployer/pkg/clientutil"
"github.com/k8stopologyawareschedwg/deployer/pkg/commands"
"github.com/k8stopologyawareschedwg/deployer/pkg/deployer"
"github.com/k8stopologyawareschedwg/deployer/pkg/options"
Expand Down Expand Up @@ -65,14 +64,7 @@ func NewVersionCommand(env *deployer.Environment, commonOpts *options.Options) *
func main() {
ctrllog.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)))

cli, err := clientutil.New()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}

env := deployer.Environment{
Cli: cli,
Ctx: context.Background(),
Log: stdr.New(log.New(os.Stderr, "", log.LstdFlags)),
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func PostSetupOptions(env *deployer.Environment, commonOpts *options.Options, in
wait.SetBaseValues(commonOpts.WaitInterval, commonOpts.WaitTimeout)

if internalOpts.replicas < 0 {
err := env.EnsureClient()
if err != nil {
return err
}

env.Log.V(4).Info("autodetecting replicas from control plane")
info, err := detect.ControlPlaneFromLister(env.Ctx, env.Cli)
if err != nil {
Expand Down

0 comments on commit 7b8e051

Please sign in to comment.