Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mustload: Replace DriverIP with Forwarded(IP|Port) #7310

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/docker-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var dockerEnvCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cname := ClusterFlagValue()
co := mustload.Running(cname)
driverName := co.CPHost.DriverName
driverName := co.CP.Host.DriverName

if driverName == driver.None {
exit.UsageT(`'none' driver does not support 'minikube docker-env' command`)
Expand All @@ -140,7 +140,7 @@ var dockerEnvCmd = &cobra.Command{
out.V{"runtime": co.Config.KubernetesConfig.ContainerRuntime})
}

if ok := isDockerActive(co.CPRunner); !ok {
if ok := isDockerActive(co.CP.Runner); !ok {
exit.WithCodeT(exit.Unavailable, `The docker service within '{{.name}}' is not active`, out.V{"name": cname})
}

Expand All @@ -161,7 +161,7 @@ var dockerEnvCmd = &cobra.Command{
EnvConfig: sh,
profile: cname,
driver: driverName,
hostIP: co.DriverIP.String(),
hostIP: co.CP.ForwardedIP.String(),
port: port,
certsDir: localpath.MakeMiniPath("certs"),
noProxy: noProxy,
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ var ipCmd = &cobra.Command{
Long: `Retrieves the IP address of the running cluster, and writes it to STDOUT.`,
Run: func(cmd *cobra.Command, args []string) {
co := mustload.Running(ClusterFlagValue())
out.Ln(co.DriverIP.String())
out.Ln(co.CP.ForwardedIP.String())
},
}
10 changes: 5 additions & 5 deletions cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,28 @@ var logsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
co := mustload.Running(ClusterFlagValue())

bs, err := cluster.Bootstrapper(co.API, viper.GetString(cmdcfg.Bootstrapper), *co.Config, *co.CPNode)
bs, err := cluster.Bootstrapper(co.API, viper.GetString(cmdcfg.Bootstrapper), *co.Config, *co.CP.Node)
if err != nil {
exit.WithError("Error getting cluster bootstrapper", err)
}

cr, err := cruntime.New(cruntime.Config{Type: co.Config.KubernetesConfig.ContainerRuntime, Runner: co.CPRunner})
cr, err := cruntime.New(cruntime.Config{Type: co.Config.KubernetesConfig.ContainerRuntime, Runner: co.CP.Runner})
if err != nil {
exit.WithError("Unable to get runtime", err)
}
if followLogs {
err := logs.Follow(cr, bs, *co.Config, co.CPRunner)
err := logs.Follow(cr, bs, *co.Config, co.CP.Runner)
if err != nil {
exit.WithError("Follow", err)
}
return
}
if showProblems {
problems := logs.FindProblems(cr, bs, *co.Config, co.CPRunner)
problems := logs.FindProblems(cr, bs, *co.Config, co.CP.Runner)
logs.OutputProblems(problems, numberOfProblems)
return
}
err = logs.Output(cr, bs, *co.Config, co.CPRunner, numberOfLines)
err = logs.Output(cr, bs, *co.Config, co.CP.Runner, numberOfLines)
if err != nil {
out.Ln("")
// Avoid exit.WithError, since it outputs the issue URL
Expand Down
10 changes: 5 additions & 5 deletions cmd/minikube/cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ var mountCmd = &cobra.Command{
}

co := mustload.Running(ClusterFlagValue())
if co.CPHost.Driver.DriverName() == driver.None {
if co.CP.Host.Driver.DriverName() == driver.None {
exit.UsageT(`'none' driver does not support 'minikube mount' command`)
}

var ip net.IP
var err error
if mountIP == "" {
ip, err = cluster.GetVMHostIP(co.CPHost)
ip, err = cluster.GetVMHostIP(co.CP.Host)
if err != nil {
exit.WithError("Error getting the host IP address to use from within the VM", err)
}
Expand Down Expand Up @@ -147,7 +147,7 @@ var mountCmd = &cobra.Command{
}

bindIP := ip.String() // the ip to listen on the user's host machine
if driver.IsKIC(co.CPHost.Driver.DriverName()) && runtime.GOOS != "linux" {
if driver.IsKIC(co.CP.Host.Driver.DriverName()) && runtime.GOOS != "linux" {
bindIP = "127.0.0.1"
}
out.T(out.Mounting, "Mounting host path {{.sourcePath}} into VM as {{.destinationPath}} ...", out.V{"sourcePath": hostPath, "destinationPath": vmPath})
Expand Down Expand Up @@ -177,15 +177,15 @@ var mountCmd = &cobra.Command{
go func() {
for sig := range c {
out.T(out.Unmount, "Unmounting {{.path}} ...", out.V{"path": vmPath})
err := cluster.Unmount(co.CPRunner, vmPath)
err := cluster.Unmount(co.CP.Runner, vmPath)
if err != nil {
out.ErrT(out.FailureType, "Failed unmount: {{.error}}", out.V{"error": err})
}
exit.WithCodeT(exit.Interrupted, "Received {{.name}} signal", out.V{"name": sig})
}
}()

err = cluster.Mount(co.CPRunner, ip.String(), vmPath, cfg)
err = cluster.Mount(co.CP.Runner, ip.String(), vmPath, cfg)
if err != nil {
exit.WithError("mount failed", err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/podman-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ var podmanEnvCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cname := ClusterFlagValue()
co := mustload.Running(cname)
driverName := co.CPHost.DriverName
driverName := co.CP.Host.DriverName

if driverName == driver.None {
exit.UsageT(`'none' driver does not support 'minikube podman-env' command`)
}

if ok := isPodmanAvailable(co.CPRunner); !ok {
if ok := isPodmanAvailable(co.CP.Runner); !ok {
exit.WithCodeT(exit.Unavailable, `The podman service within '{{.cluster}}' is not active`, out.V{"cluster": cname})
}

client, err := createExternalSSHClient(co.CPHost.Driver)
client, err := createExternalSSHClient(co.CP.Host.Driver)
if err != nil {
exit.WithError("Error getting ssh client", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ var sshCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cname := ClusterFlagValue()
co := mustload.Running(cname)
if co.CPHost.DriverName == driver.None {
if co.CP.Host.DriverName == driver.None {
exit.UsageT("'none' driver does not support 'minikube ssh' command")
}

var err error
var n *config.Node
if nodeName == "" {
n = co.CPNode
n = co.CP.Node
} else {
n, _, err = node.Retrieve(co.Config, nodeName)
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions cmd/minikube/cmd/update-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ var updateContextCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cname := ClusterFlagValue()
co := mustload.Running(cname)
updated, err := kubeconfig.UpdateIP(co.DriverIP, cname, kubeconfig.PathFromEnv())
ip := co.CP.ForwardedIP

// ??? For KIC, should we also update the port ???
tstromberg marked this conversation as resolved.
Show resolved Hide resolved
updated, err := kubeconfig.UpdateIP(ip, cname, kubeconfig.PathFromEnv())
if err != nil {
exit.WithError("update config", err)
}
if updated {
out.T(out.Celebrate, "{{.cluster}} IP has been updated to point at {{.ip}}", out.V{"cluster": cname, "ip": co.DriverIP})
out.T(out.Celebrate, "{{.cluster}} IP has been updated to point at {{.ip}}", out.V{"cluster": cname, "ip": ip})
} else {
out.T(out.Meh, "{{.cluster}} IP was already correctly configured for {{.ip}}", out.V{"cluster": cname, "ip": co.DriverIP})
out.T(out.Meh, "{{.cluster}} IP was already correctly configured for {{.ip}}", out.V{"cluster": cname, "ip": ip})
}

},
Expand Down
54 changes: 34 additions & 20 deletions pkg/minikube/mustload/mustload.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ import (

// ClusterController holds all the needed information for a minikube cluster
type ClusterController struct {
Config *config.ClusterConfig
API libmachine.API
CPHost *host.Host
CPNode *config.Node
CPRunner command.Runner
DriverIP net.IP
Config *config.ClusterConfig
API libmachine.API
CP ControlPlane
}

type ControlPlane struct {
Host *host.Host
Node *config.Node
Runner command.Runner
ForwardedIP net.IP
ForwardedPort int
}

// Partial is a cmd-friendly way to load a cluster which may or may not be running
Expand Down Expand Up @@ -107,35 +112,44 @@ func Running(name string) ClusterController {
exit.WithError("Unable to get command runner", err)
}

ips, err := host.Driver.GetIP()
ipStr, err := host.Driver.GetIP()
if err != nil {
exit.WithError("Unable to get driver IP", err)
}

if driver.IsKIC(host.DriverName) {
ips = oci.DefaultBindIPV4
ip := net.ParseIP(ipStr)
if ip == nil {
exit.WithCodeT(exit.Software, fmt.Sprintf("Unable to parse driver IP: %q", ipStr))
}

ip := net.ParseIP(ips)
if ip == nil {
exit.WithCodeT(exit.Software, fmt.Sprintf("Unable to parse driver IP: %q", ips))
cpIP := cp.IP
cpPort := cp.Port
if driver.IsKIC(host.DriverName) {
cpIP = oci.DefaultBindIPV4
cpPort, err = oci.ForwardedPort(cc.Driver, cc.Name, cp.Port)
if err != nil {
exit.WithError("Unable to get forwarded port", err)
}
}

return ClusterController{
API: api,
Config: cc,
CPRunner: cr,
CPHost: host,
CPNode: &cp,
DriverIP: ip,
API: api,
Config: cc,
CP: ControlPlane{
Runner: cr,
Host: host,
Node: &cp,
ForwardedIP: net.ParseIP(cpIP),
ForwardedPort: cpPort,
},
}
}

// Healthy is a cmd-friendly way to load a healthy cluster
func Healthy(name string) ClusterController {
co := Running(name)

as, err := kverify.APIServerStatus(co.CPRunner, net.ParseIP(co.CPNode.IP), co.CPNode.Port)
as, err := kverify.APIServerStatus(co.CP.Runner, co.CP.ForwardedIP, co.CP.ForwardedPort)
if err != nil {
out.T(out.FailureType, `Unable to get control plane status: {{.error}}`, out.V{"error": err})
exitTip("delete", name, exit.Unavailable)
Expand Down Expand Up @@ -165,6 +179,6 @@ func ExampleCmd(cname string, action string) string {
// exitTip returns an action tip and exits
func exitTip(action string, profile string, code int) {
command := ExampleCmd(profile, action)
out.T(out.Workaround, "To fix this, run: {{.command}}", out.V{"command": command})
out.T(out.Workaround, `To fix this, run: "{{.command}}"`, out.V{"command": command})
os.Exit(code)
}