Merge pull request #9873 from lingsamuel/node-param-for-ip-and-ssh-key

Add --node option for command `ip` and `ssh-key`
pull/9978/head
Thomas Strömberg 2020-12-16 08:17:24 -08:00 committed by GitHub
commit fdab252f4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 12 deletions

View File

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

View File

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

View File

@ -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
```

View File

@ -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
```