allow minikube status to display for one node
parent
25045cfc87
commit
a7c49e47c1
|
|
@ -40,7 +40,7 @@ var nodeStartCmd = &cobra.Command{
|
|||
api, cc := mustload.Partial(ClusterFlagValue())
|
||||
name := args[0]
|
||||
|
||||
n, _, err := node.Retrieve(cc, name)
|
||||
n, _, err := node.Retrieve(*cc, name)
|
||||
if err != nil {
|
||||
exit.WithError("retrieving node", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ var nodeStopCmd = &cobra.Command{
|
|||
name := args[0]
|
||||
api, cc := mustload.Partial(ClusterFlagValue())
|
||||
|
||||
n, _, err := node.Retrieve(cc, name)
|
||||
n, _, err := node.Retrieve(*cc, name)
|
||||
if err != nil {
|
||||
exit.WithError("retrieving node", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ var sshCmd = &cobra.Command{
|
|||
if nodeName == "" {
|
||||
n = co.CP.Node
|
||||
} else {
|
||||
n, _, err = node.Retrieve(co.Config, nodeName)
|
||||
n, _, err = node.Retrieve(*co.Config, nodeName)
|
||||
if err != nil {
|
||||
exit.WithCodeT(exit.Unavailable, "Node {{.nodeName}} does not exist.", out.V{"nodeName": nodeName})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import (
|
|||
"k8s.io/minikube/pkg/minikube/kubeconfig"
|
||||
"k8s.io/minikube/pkg/minikube/machine"
|
||||
"k8s.io/minikube/pkg/minikube/mustload"
|
||||
"k8s.io/minikube/pkg/minikube/node"
|
||||
)
|
||||
|
||||
var statusFormat string
|
||||
|
|
@ -105,19 +106,33 @@ var statusCmd = &cobra.Command{
|
|||
api, cc := mustload.Partial(cname)
|
||||
|
||||
var statuses []*Status
|
||||
for _, n := range cc.Nodes {
|
||||
glog.Infof("checking status of %s ...", n.Name)
|
||||
machineName := driver.MachineName(*cc, n)
|
||||
st, err := status(api, *cc, n)
|
||||
glog.Infof("%s status: %+v", machineName, st)
|
||||
|
||||
if nodeName != "" || statusFormat != defaultStatusFormat {
|
||||
n, _, err := node.Retrieve(*cc, nodeName)
|
||||
if err != nil {
|
||||
exit.WithError("retrieving node", err)
|
||||
}
|
||||
|
||||
st, err := status(api, *cc, *n)
|
||||
if err != nil {
|
||||
glog.Errorf("status error: %v", err)
|
||||
}
|
||||
if st.Host == Nonexistent {
|
||||
glog.Errorf("The %q host does not exist!", machineName)
|
||||
}
|
||||
statuses = append(statuses, st)
|
||||
} else {
|
||||
for _, n := range cc.Nodes {
|
||||
glog.Infof("checking status of %s ...", n.Name)
|
||||
machineName := driver.MachineName(*cc, n)
|
||||
st, err := status(api, *cc, n)
|
||||
glog.Infof("%s status: %+v", machineName, st)
|
||||
|
||||
if err != nil {
|
||||
glog.Errorf("status error: %v", err)
|
||||
}
|
||||
if st.Host == Nonexistent {
|
||||
glog.Errorf("The %q host does not exist!", machineName)
|
||||
}
|
||||
statuses = append(statuses, st)
|
||||
}
|
||||
}
|
||||
|
||||
switch strings.ToLower(output) {
|
||||
|
|
@ -253,6 +268,7 @@ func init() {
|
|||
For the list accessible variables for the template, see the struct values here: https://godoc.org/k8s.io/minikube/cmd/minikube/cmd#Status`)
|
||||
statusCmd.Flags().StringVarP(&output, "output", "o", "text",
|
||||
`minikube status --output OUTPUT. json, text`)
|
||||
statusCmd.Flags().StringVarP(&nodeName, "node", "n", "", "The node to check status for. Defaults to control plane. Leave blank with default format for status on all nodes.")
|
||||
}
|
||||
|
||||
func statusText(st *Status, w io.Writer) error {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func Add(cc *config.ClusterConfig, n config.Node) error {
|
|||
|
||||
// Delete stops and deletes the given node from the given cluster
|
||||
func Delete(cc config.ClusterConfig, name string) (*config.Node, error) {
|
||||
n, index, err := Retrieve(&cc, name)
|
||||
n, index, err := Retrieve(cc, name)
|
||||
if err != nil {
|
||||
return n, errors.Wrap(err, "retrieve")
|
||||
}
|
||||
|
|
@ -79,11 +79,17 @@ func Delete(cc config.ClusterConfig, name string) (*config.Node, error) {
|
|||
}
|
||||
|
||||
// Retrieve finds the node by name in the given cluster
|
||||
func Retrieve(cc *config.ClusterConfig, name string) (*config.Node, int, error) {
|
||||
func Retrieve(cc config.ClusterConfig, name string) (*config.Node, int, error) {
|
||||
|
||||
for i, n := range cc.Nodes {
|
||||
if n.Name == name {
|
||||
return &n, i, nil
|
||||
}
|
||||
|
||||
// Accept full machine name as well as just node name
|
||||
if driver.MachineName(cc, n) == name {
|
||||
return &n, i, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, -1, errors.New("Could not find node " + name)
|
||||
|
|
|
|||
|
|
@ -191,13 +191,14 @@ func CleanupWithLogs(t *testing.T, profile string, cancel context.CancelFunc) {
|
|||
}
|
||||
|
||||
// PostMortemLogs shows logs for debugging a failed cluster
|
||||
func PostMortemLogs(t *testing.T, profile string) {
|
||||
func PostMortemLogs(t *testing.T, profile string, node ...string) {
|
||||
if !t.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
if !*postMortemLogs {
|
||||
t.Logf("post-mortem logs disabled, oh-well!")
|
||||
t.Logf("post-mortem logs disabled, oh well!")
|
||||
return
|
||||
}
|
||||
|
||||
t.Logf("-----------------------post-mortem--------------------------------")
|
||||
|
|
@ -355,7 +356,7 @@ func PodWait(ctx context.Context, t *testing.T, profile string, ns string, selec
|
|||
}
|
||||
|
||||
// Status returns a minikube component status as a string
|
||||
func Status(ctx context.Context, t *testing.T, path string, profile string, key string) string {
|
||||
func Status(ctx context.Context, t *testing.T, path string, profile string, key string, node ...string) string {
|
||||
t.Helper()
|
||||
// Reminder of useful keys: "Host", "Kubelet", "APIServer"
|
||||
rr, err := Run(t, exec.CommandContext(ctx, path, "status", fmt.Sprintf("--format={{.%s}}", key), "-p", profile))
|
||||
|
|
|
|||
Loading…
Reference in New Issue