Add list option for "minikube node" command

Add option to list the nodes.
So far there was no "minikube node list" command.
pull/7851/head
Radoslaw Smigielski 2020-04-22 17:08:44 +01:00
parent d09f75bfd0
commit bf618d6632
2 changed files with 59 additions and 1 deletions

View File

@ -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]")
},
}

View File

@ -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 (
"os"
"fmt"
"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\n", machineName)
}
os.Exit(0)
},
}
func init() {
nodeCmd.AddCommand(nodeListCmd)
}