diff --git a/cmd/minikube/cmd/node.go b/cmd/minikube/cmd/node.go index 39dbac6c7c60..6dac2ca409bb 100644 --- a/cmd/minikube/cmd/node.go +++ b/cmd/minikube/cmd/node.go @@ -27,6 +27,6 @@ var nodeCmd = &cobra.Command{ Short: "Node operations", Long: "Operations on nodes", Run: func(cmd *cobra.Command, args []string) { - exit.UsageT("Usage: minikube node [add|start|stop|delete]") + exit.UsageT("Usage: minikube node [add|start|stop|delete|list]") }, } diff --git a/cmd/minikube/cmd/node_list.go b/cmd/minikube/cmd/node_list.go new file mode 100644 index 000000000000..0295837ceb1f --- /dev/null +++ b/cmd/minikube/cmd/node_list.go @@ -0,0 +1,58 @@ +/* +Copyright 2020 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "fmt" + "os" + + "github.com/golang/glog" + "github.com/spf13/cobra" + "k8s.io/minikube/pkg/minikube/driver" + "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/mustload" +) + +var nodeListCmd = &cobra.Command{ + Use: "list", + Short: "List nodes.", + Long: "List existing Minikube nodes.", + Run: func(cmd *cobra.Command, args []string) { + if len(args) != 0 { + exit.UsageT("Usage: minikube node list") + } + + cname := ClusterFlagValue() + _, cc := mustload.Partial(cname) + + if len(cc.Nodes) < 1 { + glog.Warningf("Did not found any Minikube node.") + } else { + glog.Infof("%v", cc.Nodes) + } + + for _, n := range cc.Nodes { + machineName := driver.MachineName(*cc, n) + fmt.Printf("%s\t%s\n", machineName, n.IP) + } + os.Exit(0) + }, +} + +func init() { + nodeCmd.AddCommand(nodeListCmd) +} diff --git a/site/content/en/docs/commands/node.md b/site/content/en/docs/commands/node.md index fae5a2ed6bc3..9ae17c92b961 100644 --- a/site/content/en/docs/commands/node.md +++ b/site/content/en/docs/commands/node.md @@ -138,6 +138,38 @@ minikube node help [command] [flags] --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging ``` +## minikube node list + +List nodes. + +### Synopsis + +List existing Minikube nodes. + +``` +minikube node list [flags] +``` + +### Options + +``` + -h, --help help for list +``` + +### Options inherited from parent commands + +``` + --alsologtostderr log to standard error as well as files + -b, --bootstrapper string The name of the cluster bootstrapper that will set up the kubernetes cluster. (default "kubeadm") + --log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0) + --log_dir string If non-empty, write log files in this directory + --logtostderr log to standard error instead of files + -p, --profile string The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently. (default "minikube") + --stderrthreshold severity logs at or above this threshold go to stderr (default 2) + -v, --v Level log level for V logs + --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging +``` + ## minikube node start Starts a node.