Skip to content

Commit

Permalink
Add -n, --node option for ip and ssh-key
Browse files Browse the repository at this point in the history
  • Loading branch information
lingsamuel committed Dec 7, 2020
1 parent b2e6f21 commit b9eedce
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
18 changes: 15 additions & 3 deletions cmd/minikube/cmd/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,29 @@ package cmd

import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/mustload"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/reason"
)

// ipCmd represents the ip command
var ipCmd = &cobra.Command{
Use: "ip",
Short: "Retrieves the IP address of the running cluster",
Long: `Retrieves the IP address of the running cluster, and writes it to STDOUT.`,
Short: "Retrieves the IP address of the specified node",
Long: `Retrieves the IP address of the specified node, and writes it to STDOUT.`,
Run: func(cmd *cobra.Command, args []string) {
co := mustload.Running(ClusterFlagValue())
out.Ln(co.CP.IP.String())
n, _, err := node.Retrieve(*co.Config, nodeName)
if err != nil {
exit.Error(reason.GuestNodeRetrieve, "retrieving node", err)
}

out.Ln(n.IP)
},
}

func init() {
ipCmd.Flags().StringVarP(&nodeName, "node", "n", "", "The node to get IP. Defaults to the primary control plane.")
}
19 changes: 16 additions & 3 deletions cmd/minikube/cmd/ssh-key.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,31 @@ import (
"path/filepath"

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/mustload"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/reason"
)

// sshKeyCmd represents the sshKey command
var sshKeyCmd = &cobra.Command{
Use: "ssh-key",
Short: "Retrieve the ssh identity key path of the specified cluster",
Long: "Retrieve the ssh identity key path of the specified cluster.",
Short: "Retrieve the ssh identity key path of the specified node",
Long: "Retrieve the ssh identity key path of the specified node, and writes it to STDOUT.",
Run: func(cmd *cobra.Command, args []string) {
_, cc := mustload.Partial(ClusterFlagValue())
out.Ln(filepath.Join(localpath.MiniPath(), "machines", cc.Name, "id_rsa"))
n, _, err := node.Retrieve(*cc, nodeName)
if err != nil {
exit.Error(reason.GuestNodeRetrieve, "retrieving node", err)
}

out.Ln(filepath.Join(localpath.MiniPath(), "machines", driver.MachineName(*cc, *n), "id_rsa"))
},
}

func init() {
sshKeyCmd.Flags().StringVarP(&nodeName, "node", "n", "", "The node to get ssh-key path. Defaults to the primary control plane.")
}
12 changes: 9 additions & 3 deletions site/content/en/docs/commands/ip.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
---
title: "ip"
description: >
Retrieves the IP address of the running cluster
Retrieves the IP address of the specified node
---


## minikube ip

Retrieves the IP address of the running cluster
Retrieves the IP address of the specified node

### Synopsis

Retrieves the IP address of the running cluster, and writes it to STDOUT.
Retrieves the IP address of the specified node, and writes it to STDOUT.

```shell
minikube ip [flags]
```

### Options

```
-n, --node string The node to get IP. Defaults to the primary control plane.
```

### Options inherited from parent commands

```
Expand Down
12 changes: 9 additions & 3 deletions site/content/en/docs/commands/ssh-key.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
---
title: "ssh-key"
description: >
Retrieve the ssh identity key path of the specified cluster
Retrieve the ssh identity key path of the specified node
---


## minikube ssh-key

Retrieve the ssh identity key path of the specified cluster
Retrieve the ssh identity key path of the specified node

### Synopsis

Retrieve the ssh identity key path of the specified cluster.
Retrieve the ssh identity key path of the specified node, and writes it to STDOUT.

```shell
minikube ssh-key [flags]
```

### Options

```
-n, --node string The node to get ssh-key path. Defaults to the primary control plane.
```

### Options inherited from parent commands

```
Expand Down

0 comments on commit b9eedce

Please sign in to comment.