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 bd922be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 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. Defaults to the primary control plane.")
}

0 comments on commit bd922be

Please sign in to comment.