Skip to content

Commit

Permalink
CLI feedback messages (#153)
Browse files Browse the repository at this point in the history
* minor tweaks

* spruce up bootstrap/join output

* ST1005 fixes for k8s cli; make error messages consistent
  • Loading branch information
kwmonroe authored Feb 26, 2024
1 parent db69113 commit 26906ea
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/src/explanation/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Snaps are self-contained, simple to install, secure, cross-platform, and
dependency-free. They can be installed on any Linux system which supports the
`snapd` service (see the [snapd documentation] for more information). Security
and robustness are their key features, alongside being easy to install, easy to
maintain and easy to upgrade.
maintain and easy to upgrade.

## What else comes with it?

Expand Down Expand Up @@ -64,4 +64,4 @@ visit the [Ubuntu support] page.
[snapd documentation]: https://snapcraft.io/docs/installing-snapd
[Community page]: ../reference/community
[Ubuntu Pro]: https://ubuntu.com/pro
[Ubuntu support]: https://ubuntu.com/support
[Ubuntu support]: https://ubuntu.com/support
4 changes: 2 additions & 2 deletions docs/src/howto/install/snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ Installing the snap sets up all the parts required to run Kubernetes. The next s
sudo k8s bootstrap
```

This command will output a message confirming the services have been started.
This command will output a message confirming local cluster services have been started.

## Confirm the services are running
## Confirm the cluster is ready

It is recommended to ensure that the cluster initialises properly and is running with no issues. Run the command:

Expand Down
2 changes: 1 addition & 1 deletion src/k8s/cmd/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewRootCmd() *cobra.Command {
return fmt.Errorf("failed to check if command runs as root: %w", err)
}
if !withRoot {
return fmt.Errorf("You do not have enough permissions. Please run the command with sudo.")
return fmt.Errorf("insufficient permissions: run the command with sudo")
}
return nil
},
Expand Down
4 changes: 2 additions & 2 deletions src/k8s/cmd/k8s/k8s_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func newAddNodeCmd() *cobra.Command {
PersistentPreRunE: chainPreRunHooks(hookSetupClient),
RunE: func(cmd *cobra.Command, args []string) (err error) {
if len(args) > 1 {
return fmt.Errorf("Too many arguments. Please, only provide the node name to add.")
return fmt.Errorf("too many arguments: provide only the node name to add")
}
if len(args) < 1 {
return fmt.Errorf("Not enough arguments. Please, provide the node name to add.")
return fmt.Errorf("missing argument: provide the node name to add")
}

defer errors.Transform(&err, addNodeCmdErrorMsgs)
Expand Down
4 changes: 2 additions & 2 deletions src/k8s/cmd/k8s/k8s_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func newBootstrapCmd() *cobra.Command {
config.SetDefaults()
}

fmt.Println("Bootstrapping the cluster. This may take some seconds...")
fmt.Println("Bootstrapping the cluster. This may take some time, please wait.")
cluster, err := k8sdClient.Bootstrap(cmd.Context(), config)
if err != nil {
return fmt.Errorf("failed to bootstrap cluster: %w", err)
}

fmt.Printf("Bootstrapped k8s cluster on %q (%s).\n", cluster.Name, cluster.Address)
fmt.Printf("Cluster services have started on %q.\nPlease allow some time for initial Kubernetes node registration.\n", cluster.Name)
return nil
},
}
Expand Down
6 changes: 3 additions & 3 deletions src/k8s/cmd/k8s/k8s_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ func newDisableCmd() *cobra.Command {
Long: fmt.Sprintf("Disable one of the specific components: %s.", strings.Join(componentList, ",")),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
return fmt.Errorf("Too many arguments. Please, only provide the name of the component that should be disabled.")
return fmt.Errorf("too many arguments: provide only the name of the component that should be disabled")
}
if len(args) < 1 {
return fmt.Errorf("Not enough arguments. Please, provide the name of the component that should be disabled.")
return fmt.Errorf("missing argument: provide the name of the component that should be disabled")
}
if !slices.Contains(componentList, args[0]) {
return fmt.Errorf("Unknown component %q. Needs to be one of: %s", args[0], strings.Join(componentList, ", "))
return fmt.Errorf("unknown component %q; needs to be one of: %s", args[0], strings.Join(componentList, ", "))
}
return nil
},
Expand Down
6 changes: 3 additions & 3 deletions src/k8s/cmd/k8s/k8s_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func newEnableCmd() *cobra.Command {
Long: fmt.Sprintf("Enable one of the specific components: %s.", strings.Join(componentList, ", ")),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
return fmt.Errorf("Too many arguments. Please, only provide the name of the component that should be enabled.")
return fmt.Errorf("too many arguments: provide only the name of the component that should be enabled")
}
if len(args) < 1 {
return fmt.Errorf("Not enough arguments. Please, provide the name of the component that should be enabled.")
return fmt.Errorf("missing argument: provide the name of the component that should be enabled")
}
if !slices.Contains(componentList, args[0]) {
return fmt.Errorf("Unknown component %q. Needs to be one of: %s", args[0], strings.Join(componentList, ", "))
return fmt.Errorf("unknown component %q; needs to be one of: %s", args[0], strings.Join(componentList, ", "))
}
return nil
},
Expand Down
8 changes: 4 additions & 4 deletions src/k8s/cmd/k8s/k8s_join_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ func newJoinNodeCmd() *cobra.Command {
PersistentPreRunE: chainPreRunHooks(hookSetupClient),
RunE: func(cmd *cobra.Command, args []string) (err error) {
if len(args) > 1 {
return fmt.Errorf("Too many arguments. Please, only provide the token that was generated with `sudo k8s add-node <node-name>`.")
return fmt.Errorf("too many arguments: provide only the token that was generated with `sudo k8s add-node <node-name>`")
}
if len(args) < 1 {
return fmt.Errorf("Not enough arguments. Please, provide the token that was generated with `sudo k8s add-node <node-name>`.")
return fmt.Errorf("missing argument: provide the token that was generated with `sudo k8s add-node <node-name>`")
}

defer errors.Transform(&err, joinNodeCmdErrorMsgs)
Expand Down Expand Up @@ -73,12 +73,12 @@ func newJoinNodeCmd() *cobra.Command {
timeoutCtx, cancel := context.WithTimeout(cmd.Context(), joinNodeCmdOpts.timeout)
defer cancel()

fmt.Println("Joining the cluster. This may take some seconds...")
fmt.Println("Joining the cluster. This may take some time, please wait.")
if err := k8sdClient.JoinCluster(timeoutCtx, joinNodeCmdOpts.name, joinNodeCmdOpts.address, token); err != nil {
return fmt.Errorf("failed to join cluster: %w", err)
}

fmt.Println("Joined the cluster.")
fmt.Printf("Joined the cluster as %q.\nPlease allow some time for Kubernetes node registration.\n", joinNodeCmdOpts.name)
return nil
},
}
Expand Down
4 changes: 2 additions & 2 deletions src/k8s/cmd/k8s/k8s_remove_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func newRemoveNodeCmd() *cobra.Command {
PersistentPreRunE: chainPreRunHooks(hookSetupClient),
RunE: func(cmd *cobra.Command, args []string) (err error) {
if len(args) > 1 {
return fmt.Errorf("Too many arguments. Please, only provide the name of the node to remove.")
return fmt.Errorf("too many arguments: provide only the name of the node to remove")
}
if len(args) < 1 {
return fmt.Errorf("Not enough arguments. Please, provide the name of the node to remove.")
return fmt.Errorf("missing argument: provide the name of the node to remove")
}

defer errors.Transform(&err, nil)
Expand Down

0 comments on commit 26906ea

Please sign in to comment.