From 3410094c460a74127fd069097a9b805edc3decf1 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Wed, 31 Jul 2024 11:08:20 +0200 Subject: [PATCH 1/5] deployer: allow to set the tool verbosity because an amazing series of coincidence, and lack of real need, the tool itself lacked a way to set its own verbosity. Fixed with this patch, adding the ubiquitous `-v` option. Fixing excessive logging along the way, which was gone unnoticed because the default level was zero. Signed-off-by: Francesco Romani (cherry picked from commit 0b65fcbf7860449aa6b8e111176822584ea566f0) --- cmd/deployer/main.go | 18 +++++++++++++++++- pkg/commands/deploy.go | 6 +++--- pkg/commands/detect.go | 2 +- pkg/commands/remove.go | 8 ++++---- pkg/commands/root.go | 4 ++++ pkg/deploy/cluster.go | 2 +- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/cmd/deployer/main.go b/cmd/deployer/main.go index 41be0259..23c76aec 100644 --- a/cmd/deployer/main.go +++ b/cmd/deployer/main.go @@ -17,14 +17,18 @@ package main import ( + "context" "fmt" + "log" "os" + "github.com/go-logr/stdr" "github.com/spf13/cobra" "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" @@ -61,7 +65,19 @@ func NewVersionCommand(env *deployer.Environment, commonOpts *options.Options) * func main() { ctrllog.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog))) - root := commands.NewRootCommand(NewVersionCommand) + 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)), + } + + root := commands.NewRootCommand(&env, NewVersionCommand) if err := root.Execute(); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) diff --git a/pkg/commands/deploy.go b/pkg/commands/deploy.go index 89ccac69..ef7e7299 100644 --- a/pkg/commands/deploy.go +++ b/pkg/commands/deploy.go @@ -67,7 +67,7 @@ func NewDeployAPICommand(env *deployer.Environment, commonOpts *options.Options) return fmt.Errorf("cannot autodetect the platform version, and no version given") } - env.Log.Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) + env.Log.V(3).Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) if err := api.Deploy(env, options.API{Platform: commonOpts.ClusterPlatform}); err != nil { return err } @@ -100,7 +100,7 @@ func NewDeploySchedulerPluginCommand(env *deployer.Environment, commonOpts *opti return fmt.Errorf("cannot autodetect the platform version, and no version given") } - env.Log.Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) + env.Log.V(3).Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) return sched.Deploy(env, options.Scheduler{ Platform: commonOpts.ClusterPlatform, WaitCompletion: commonOpts.WaitCompletion, @@ -143,7 +143,7 @@ func NewDeployTopologyUpdaterCommand(env *deployer.Environment, commonOpts *opti return fmt.Errorf("cannot autodetect the platform version, and no version given") } - env.Log.Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) + env.Log.V(3).Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) return updaters.Deploy(env, commonOpts.UpdaterType, options.Updater{ Platform: commonOpts.ClusterPlatform, PlatformVersion: commonOpts.ClusterVersion, diff --git a/pkg/commands/detect.go b/pkg/commands/detect.go index f9c4b758..95829fb8 100644 --- a/pkg/commands/detect.go +++ b/pkg/commands/detect.go @@ -45,7 +45,7 @@ func NewDetectCommand(env *deployer.Environment, commonOpts *options.Options) *c platKind, kindReason, _ := detect.FindPlatform(env.Ctx, commonOpts.UserPlatform) platVer, verReason, _ := detect.FindVersion(env.Ctx, platKind.Discovered, commonOpts.UserPlatformVersion) - env.Log.Info("detection", "platform", platKind, "reason", kindReason, "version", platVer, "source", verReason) + env.Log.V(3).Info("detection", "platform", platKind, "reason", kindReason, "version", platVer, "source", verReason) cluster := detect.ClusterInfo{ Platform: platKind, diff --git a/pkg/commands/remove.go b/pkg/commands/remove.go index 5181dd38..49e8e258 100644 --- a/pkg/commands/remove.go +++ b/pkg/commands/remove.go @@ -51,7 +51,7 @@ func NewRemoveCommand(env *deployer.Environment, commonOpts *options.Options) *c if commonOpts.ClusterVersion == platform.MissingVersion { return fmt.Errorf("cannot autodetect the platform version, and no version given") } - env.Log.Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) + env.Log.V(3).Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) err = sched.Remove(env, options.Scheduler{ Platform: commonOpts.ClusterPlatform, @@ -123,7 +123,7 @@ func NewRemoveAPICommand(env *deployer.Environment, commonOpts *options.Options) return fmt.Errorf("cannot autodetect the platform version, and no version given") } - env.Log.Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) + env.Log.V(3).Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) if err := api.Remove(env, options.API{Platform: commonOpts.ClusterPlatform}); err != nil { return err } @@ -156,7 +156,7 @@ func NewRemoveSchedulerPluginCommand(env *deployer.Environment, commonOpts *opti return fmt.Errorf("cannot autodetect the platform version, and no version given") } - env.Log.Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) + env.Log.V(3).Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) return sched.Remove(env, options.Scheduler{ Platform: commonOpts.ClusterPlatform, WaitCompletion: commonOpts.WaitCompletion, @@ -199,7 +199,7 @@ func NewRemoveTopologyUpdaterCommand(env *deployer.Environment, commonOpts *opti return fmt.Errorf("cannot autodetect the platform version, and no version given") } - env.Log.Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) + env.Log.V(3).Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) return updaters.Remove(env, commonOpts.UpdaterType, options.Updater{ Platform: commonOpts.ClusterPlatform, PlatformVersion: commonOpts.ClusterVersion, diff --git a/pkg/commands/root.go b/pkg/commands/root.go index b6ea4d6e..e8df1c9b 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -38,6 +38,7 @@ import ( ) type internalOptions struct { + verbose int rteConfigFile string schedScoringStratConfigFile string schedCacheParamsConfigFile string @@ -93,6 +94,7 @@ func NewRootCommand(extraCmds ...NewCommandFunc) *cobra.Command { } func InitFlags(flags *pflag.FlagSet, commonOpts *options.Options, internalOpts *internalOptions) { + flags.IntVarP(&internalOpts.verbose, "verbose", "v", 1, "set the tool verbosity.") flags.StringVarP(&internalOpts.plat, "platform", "P", "", "platform kind:version to deploy on (example kubernetes:v1.22)") flags.StringVar(&internalOpts.rteConfigFile, "rte-config-file", "", "inject rte configuration reading from this file.") flags.StringVar(&internalOpts.schedScoringStratConfigFile, "sched-scoring-strat-config-file", "", "inject scheduler scoring strategy configuration reading from this file.") @@ -116,6 +118,8 @@ func InitFlags(flags *pflag.FlagSet, commonOpts *options.Options, internalOpts * } func PostSetupOptions(env *deployer.Environment, commonOpts *options.Options, internalOpts *internalOptions) error { + stdr.SetVerbosity(internalOpts.verbose) // MUST be the very first thing + env.Log.V(3).Info("global polling interval=%v timeout=%v", commonOpts.WaitInterval, commonOpts.WaitTimeout) wait.SetBaseValues(commonOpts.WaitInterval, commonOpts.WaitTimeout) diff --git a/pkg/deploy/cluster.go b/pkg/deploy/cluster.go index 2ae58fe0..1d8a0e9c 100644 --- a/pkg/deploy/cluster.go +++ b/pkg/deploy/cluster.go @@ -44,7 +44,7 @@ func OnCluster(env *deployer.Environment, commonOpts *options.Options) error { return fmt.Errorf("cannot autodetect the platform version, and no version given") } - env.Log.Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) + env.Log.V(3).Info("detection", "platform", commonOpts.ClusterPlatform, "reason", reason, "version", commonOpts.ClusterVersion, "source", source) if err := api.Deploy(env, options.API{ Platform: commonOpts.ClusterPlatform, }); err != nil { From f2f745afbce95f1d798f7171242de16d7f61c8fe Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Wed, 31 Jul 2024 10:49:20 +0200 Subject: [PATCH 2/5] main: move env into the executable bubble up into executable (from the root command) the deployer.Environment management, to make room to discover the control plane info. Signed-off-by: Francesco Romani (cherry picked from commit da17968db3d79a66258b109b44221d7b7523229e) --- pkg/commands/root.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/pkg/commands/root.go b/pkg/commands/root.go index e8df1c9b..c9deb81d 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -53,11 +53,7 @@ func ShowHelp(cmd *cobra.Command, args []string) error { type NewCommandFunc func(ev *deployer.Environment, ko *options.Options) *cobra.Command // NewRootCommand returns entrypoint command to interact with all other commands -func NewRootCommand(extraCmds ...NewCommandFunc) *cobra.Command { - env := deployer.Environment{ - Ctx: context.Background(), - Log: stdr.New(log.New(os.Stderr, "", log.LstdFlags)), - } +func NewRootCommand(env *deployer.Environment, extraCmds ...NewCommandFunc) *cobra.Command { internalOpts := internalOptions{} commonOpts := options.Options{} @@ -66,7 +62,7 @@ func NewRootCommand(extraCmds ...NewCommandFunc) *cobra.Command { Short: "deployer helps setting up all the topology-aware-scheduling components on a kubernetes cluster", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - return PostSetupOptions(&env, &commonOpts, &internalOpts) + return PostSetupOptions(env, &commonOpts, &internalOpts) }, RunE: func(cmd *cobra.Command, args []string) error { return ShowHelp(cmd, args) @@ -78,16 +74,16 @@ func NewRootCommand(extraCmds ...NewCommandFunc) *cobra.Command { InitFlags(root.PersistentFlags(), &commonOpts, &internalOpts) root.AddCommand( - NewRenderCommand(&env, &commonOpts), - NewValidateCommand(&env, &commonOpts), - NewDeployCommand(&env, &commonOpts), - NewRemoveCommand(&env, &commonOpts), - NewSetupCommand(&env, &commonOpts), - NewDetectCommand(&env, &commonOpts), - NewImagesCommand(&env, &commonOpts), + NewRenderCommand(env, &commonOpts), + NewValidateCommand(env, &commonOpts), + NewDeployCommand(env, &commonOpts), + NewRemoveCommand(env, &commonOpts), + NewSetupCommand(env, &commonOpts), + NewDetectCommand(env, &commonOpts), + NewImagesCommand(env, &commonOpts), ) for _, extraCmd := range extraCmds { - root.AddCommand(extraCmd(&env, &commonOpts)) + root.AddCommand(extraCmd(env, &commonOpts)) } return root From 12683097576b44b970d28aff9e829dfd488cf58b Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Wed, 31 Jul 2024 10:49:51 +0200 Subject: [PATCH 3/5] clientutil: add func to find control plane nodes add utilities to getch all the controlplane nodes, similarly to worker node which we support since forever. Signed-off-by: Francesco Romani (cherry picked from commit c5094bba1ee3f8ee1f4c70d902b68bf1d7f5a02a) --- pkg/clientutil/nodes/nodes.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/clientutil/nodes/nodes.go b/pkg/clientutil/nodes/nodes.go index ef4d2413..d25f3c1a 100644 --- a/pkg/clientutil/nodes/nodes.go +++ b/pkg/clientutil/nodes/nodes.go @@ -28,8 +28,8 @@ import ( ) const ( - // RoleWorker contains the worker role - RoleWorker = "worker" + RoleControlPlane = "control-plane" + RoleWorker = "worker" ) const ( @@ -37,6 +37,10 @@ const ( LabelRole = "node-role.kubernetes.io" ) +func GetControlPlane(env *deployer.Environment) ([]corev1.Node, error) { + return GetByRole(env, RoleControlPlane) +} + func GetWorkers(env *deployer.Environment) ([]corev1.Node, error) { return GetByRole(env, RoleWorker) } From 90891099943d841783c33736f1385bfce70ac8ce Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Wed, 31 Jul 2024 10:50:18 +0200 Subject: [PATCH 4/5] add and use controlplane detection expose control plane detection Signed-off-by: Francesco Romani (cherry picked from commit 14a53f56b62639e82d12baff33eeeddb7f2340d4) --- pkg/commands/detect.go | 34 ++++++++++++++----- pkg/commands/root.go | 20 ++++++++--- pkg/deployer/platform/detect/autoselection.go | 16 +++++++++ pkg/deployer/platform/detect/detect.go | 29 ++++++++++++++++ 4 files changed, 87 insertions(+), 12 deletions(-) diff --git a/pkg/commands/detect.go b/pkg/commands/detect.go index 95829fb8..8560d030 100644 --- a/pkg/commands/detect.go +++ b/pkg/commands/detect.go @@ -27,7 +27,8 @@ import ( ) type detectOptions struct { - jsonOutput bool + controlPlane bool + jsonOutput bool } func NewDetectCommand(env *deployer.Environment, commonOpts *options.Options) *cobra.Command { @@ -42,6 +43,13 @@ func NewDetectCommand(env *deployer.Environment, commonOpts *options.Options) *c return err } + if opts.controlPlane { + info, _ := detect.ControlPlaneFromLister(env.Ctx, env.Cli) + serialize(opts, info) + return nil + + } + platKind, kindReason, _ := detect.FindPlatform(env.Ctx, commonOpts.UserPlatform) platVer, verReason, _ := detect.FindVersion(env.Ctx, platKind.Discovered, commonOpts.UserPlatformVersion) @@ -51,17 +59,27 @@ func NewDetectCommand(env *deployer.Environment, commonOpts *options.Options) *c Platform: platKind, Version: platVer, } - var out string - if opts.jsonOutput { - out = cluster.ToJSON() - } else { - out = cluster.String() - } - fmt.Printf("%s\n", out) + serialize(opts, cluster) return nil }, Args: cobra.NoArgs, } detect.Flags().BoolVarP(&opts.jsonOutput, "json", "J", false, "output JSON, not text.") + detect.Flags().BoolVar(&opts.controlPlane, "control-plane", false, "detect control plane info, not cluster info") return detect } + +type serializer interface { + ToJSON() string + String() string +} + +func serialize(opts *detectOptions, sr serializer) { + var out string + if opts.jsonOutput { + out = sr.ToJSON() + } else { + out = sr.String() + } + fmt.Printf("%s\n", out) +} diff --git a/pkg/commands/root.go b/pkg/commands/root.go index c9deb81d..be0cff03 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -17,9 +17,7 @@ package commands import ( - "context" "fmt" - "log" "os" "strings" "time" @@ -30,6 +28,7 @@ import ( "github.com/k8stopologyawareschedwg/deployer/pkg/deployer" "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform" + "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform/detect" "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/updaters" "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/wait" "github.com/k8stopologyawareschedwg/deployer/pkg/manifests" @@ -39,6 +38,7 @@ import ( type internalOptions struct { verbose int + replicas int rteConfigFile string schedScoringStratConfigFile string schedCacheParamsConfigFile string @@ -95,8 +95,8 @@ func InitFlags(flags *pflag.FlagSet, commonOpts *options.Options, internalOpts * flags.StringVar(&internalOpts.rteConfigFile, "rte-config-file", "", "inject rte configuration reading from this file.") flags.StringVar(&internalOpts.schedScoringStratConfigFile, "sched-scoring-strat-config-file", "", "inject scheduler scoring strategy configuration reading from this file.") flags.StringVar(&internalOpts.schedCacheParamsConfigFile, "sched-cache-params-config-file", "", "inject scheduler fine cache params configuration reading from this file.") + flags.IntVarP(&internalOpts.replicas, "replicas", "R", 1, "set the replica value - where relevant.") - flags.IntVarP(&commonOpts.Replicas, "replicas", "R", 1, "set the replica value - where relevant.") flags.DurationVarP(&commonOpts.WaitInterval, "wait-interval", "E", 2*time.Second, "wait interval.") flags.DurationVarP(&commonOpts.WaitTimeout, "wait-timeout", "T", 2*time.Minute, "wait timeout.") flags.BoolVar(&commonOpts.PullIfNotPresent, "pull-if-not-present", false, "force pull policies to IfNotPresent.") @@ -116,9 +116,21 @@ func InitFlags(flags *pflag.FlagSet, commonOpts *options.Options, internalOpts * func PostSetupOptions(env *deployer.Environment, commonOpts *options.Options, internalOpts *internalOptions) error { stdr.SetVerbosity(internalOpts.verbose) // MUST be the very first thing - env.Log.V(3).Info("global polling interval=%v timeout=%v", commonOpts.WaitInterval, commonOpts.WaitTimeout) + env.Log.V(3).Info("global polling settings", "interval", commonOpts.WaitInterval, "timeout", commonOpts.WaitTimeout) wait.SetBaseValues(commonOpts.WaitInterval, commonOpts.WaitTimeout) + if internalOpts.replicas < 0 { + env.Log.V(4).Info("autodetecting replicas from control plane") + info, err := detect.ControlPlaneFromLister(env.Ctx, env.Cli) + if err != nil { + return err + } + commonOpts.Replicas = info.NodeCount + env.Log.V(3).Info("autodetected control plane nodes, set replicas accordingly", "controlPlaneNodes", info.NodeCount) + } else { + commonOpts.Replicas = internalOpts.replicas + } + // if it is unknown, it's fine if internalOpts.plat == "" { commonOpts.UserPlatform = platform.Unknown diff --git a/pkg/deployer/platform/detect/autoselection.go b/pkg/deployer/platform/detect/autoselection.go index c470e9dd..c3ca54a5 100644 --- a/pkg/deployer/platform/detect/autoselection.go +++ b/pkg/deployer/platform/detect/autoselection.go @@ -41,6 +41,22 @@ type ClusterInfo struct { Version VersionInfo `json:"version"` } +type ControlPlaneInfo struct { + NodeCount int `json:"nodeCount"` +} + +func (cpi ControlPlaneInfo) String() string { + return fmt.Sprintf("nodes=%d", cpi.NodeCount) +} + +func (cpi ControlPlaneInfo) ToJSON() string { + data, err := json.Marshal(cpi) + if err != nil { + return `{"error":` + fmt.Sprintf("%q", err) + `}` + } + return string(data) +} + func (ci ClusterInfo) String() string { return fmt.Sprintf("%s:%s", ci.Platform.Discovered, ci.Version.Discovered) } diff --git a/pkg/deployer/platform/detect/detect.go b/pkg/deployer/platform/detect/detect.go index 3ed844aa..4519e6ad 100644 --- a/pkg/deployer/platform/detect/detect.go +++ b/pkg/deployer/platform/detect/detect.go @@ -20,16 +20,45 @@ import ( "context" "fmt" + "github.com/go-logr/logr" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/discovery" + "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/k8stopologyawareschedwg/deployer/pkg/clientutil" + "github.com/k8stopologyawareschedwg/deployer/pkg/clientutil/nodes" + "github.com/k8stopologyawareschedwg/deployer/pkg/deployer" "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform" ocpconfigv1 "github.com/openshift/api/config/v1" ) +func ControlPlane(ctx context.Context) (ControlPlaneInfo, error) { + cli, err := clientutil.New() + if err != nil { + return ControlPlaneInfo{}, err + } + return ControlPlaneFromLister(ctx, cli) +} + +func ControlPlaneFromLister(ctx context.Context, cli client.Client) (ControlPlaneInfo, error) { + info := ControlPlaneInfo{} + env := deployer.Environment{ + Ctx: ctx, + Cli: cli, + Log: logr.Discard(), // TODO + } + nodes, err := nodes.GetControlPlane(&env) + if err != nil { + return info, err + } + info.NodeCount = len(nodes) + return info, nil +} + func Platform(ctx context.Context) (platform.Platform, error) { ocpCli, err := clientutil.NewOCPClientSet() if err != nil { From b0b2d35b2619041e2b0189a7ffa9ae4dda7db76f Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Wed, 31 Jul 2024 12:06:32 +0200 Subject: [PATCH 5/5] cmd: lazily create client to avoid to break the render flow, create the client lazily, not eagerly. Signed-off-by: Francesco Romani (cherry picked from commit 7b8e051877c71550347b66ee4f156b2aba5688a0) --- cmd/deployer/main.go | 8 -------- pkg/commands/root.go | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cmd/deployer/main.go b/cmd/deployer/main.go index 23c76aec..556af745 100644 --- a/cmd/deployer/main.go +++ b/cmd/deployer/main.go @@ -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" @@ -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)), } diff --git a/pkg/commands/root.go b/pkg/commands/root.go index be0cff03..de57e3a8 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -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 {