mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
chore: activate the context of a newly initialised cluster
This commit is contained in:
@@ -82,8 +82,8 @@ func NewInitCommand() *cobra.Command {
|
|||||||
"Path to SSH private key for SSH remote login. (default ~/.ssh/id_*)",
|
"Path to SSH private key for SSH remote login. (default ~/.ssh/id_*)",
|
||||||
)
|
)
|
||||||
cmd.Flags().StringVarP(
|
cmd.Flags().StringVarP(
|
||||||
&opts.context, "context", "c", "",
|
&opts.context, "context", "c", "default",
|
||||||
"Name of the cluster context in the local config.",
|
"Name of the created context for the initialised cluster in the Uncloud config.",
|
||||||
)
|
)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
+2
-4
@@ -173,7 +173,7 @@ func (cli *CLI) initRemoteMachine(
|
|||||||
contextName = defaultContextName
|
contextName = defaultContextName
|
||||||
}
|
}
|
||||||
if _, ok := cli.Config.Contexts[contextName]; ok {
|
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)
|
machineClient, err := cli.provisionRemoteMachine(ctx, remoteMachine)
|
||||||
@@ -220,12 +220,10 @@ func (cli *CLI) initRemoteMachine(
|
|||||||
if err = cli.CreateContext(contextName); err != nil {
|
if err = cli.CreateContext(contextName); err != nil {
|
||||||
return nil, fmt.Errorf("save cluster context to config: %w", err)
|
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 {
|
if err = cli.SetCurrentContext(contextName); err != nil {
|
||||||
return nil, fmt.Errorf("set current cluster context: %w", err)
|
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.
|
// Save the machine's SSH connection details in the context config.
|
||||||
connCfg := config.MachineConnection{
|
connCfg := config.MachineConnection{
|
||||||
|
|||||||
Reference in New Issue
Block a user