From b3885b08889da47e450e18fee3feb67bd8b7b5bb Mon Sep 17 00:00:00 2001 From: Pavel Sviderski Date: Thu, 3 Apr 2025 13:38:48 +1000 Subject: [PATCH] chore: activate the context of a newly initialised cluster --- cmd/uncloud/machine/init.go | 4 ++-- internal/cli/cli.go | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/uncloud/machine/init.go b/cmd/uncloud/machine/init.go index a5cb6807..dc21e1e3 100644 --- a/cmd/uncloud/machine/init.go +++ b/cmd/uncloud/machine/init.go @@ -82,8 +82,8 @@ func NewInitCommand() *cobra.Command { "Path to SSH private key for SSH remote login. (default ~/.ssh/id_*)", ) cmd.Flags().StringVarP( - &opts.context, "context", "c", "", - "Name of the cluster context in the local config.", + &opts.context, "context", "c", "default", + "Name of the created context for the initialised cluster in the Uncloud config.", ) return cmd diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 30daa98e..632aa51d 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -173,7 +173,7 @@ func (cli *CLI) initRemoteMachine( contextName = defaultContextName } if _, ok := cli.Config.Contexts[contextName]; ok { - return nil, fmt.Errorf("cluster %q already exists", contextName) + return nil, fmt.Errorf("cluster context '%s' already exists", contextName) } machineClient, err := cli.provisionRemoteMachine(ctx, remoteMachine) @@ -220,12 +220,10 @@ func (cli *CLI) initRemoteMachine( if err = cli.CreateContext(contextName); err != nil { return nil, fmt.Errorf("save cluster context to config: %w", err) } - // Set the current cluster to the just created one if it is the only cluster in the config. - if len(cli.Config.Contexts) == 1 { - if err = cli.SetCurrentContext(contextName); err != nil { - return nil, fmt.Errorf("set current cluster context: %w", err) - } + if err = cli.SetCurrentContext(contextName); err != nil { + return nil, fmt.Errorf("set current cluster context: %w", err) } + fmt.Printf("Current cluster context is now '%s'.\n", contextName) // Save the machine's SSH connection details in the context config. connCfg := config.MachineConnection{