Skip to content

Commit

Permalink
Make sure to set up apiserver tunnel on restart
Browse files Browse the repository at this point in the history
  • Loading branch information
afbjorklund committed Apr 5, 2022
1 parent e894c88 commit e7495ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
9 changes: 9 additions & 0 deletions pkg/minikube/machine/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ func fixHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*hos
return h, nil
}

// Tunnel apiserver to guest, if needed
if cc.APIServerPort != 0 {
args := []string{"-f", "-NTL", fmt.Sprintf("%d:localhost:8443", cc.APIServerPort)}
err := CreateSSHShell(api, *cc, *n, args, false)
if err != nil {
klog.Warningf("apiserver tunnel failed: %v", err)
}
}

if err := postStartSetup(h, *cc); err != nil {
return h, errors.Wrap(err, "post-start")
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/minikube/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) (
showHostInfo(h, *cfg)
}

// Tunnel apiserver to guest, if needed
if cfg.APIServerPort != 0 {
args := []string{"-f", "-NTL", fmt.Sprintf("%d:localhost:8443", cfg.APIServerPort)}
err := CreateSSHShell(api, *cfg, *n, args, false)
if err != nil {
klog.Warningf("apiserver tunnel failed: %v", err)
}
}

if err := postStartSetup(h, *cfg); err != nil {
return h, errors.Wrap(err, "post-start")
}
Expand Down
11 changes: 1 addition & 10 deletions pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,6 @@ func handleAPIServer(starter Starter, cr cruntime.Manager, hostIP net.IP) (*kube
return nil, bs, err
}

// Tunnel apiserver to guest, if needed
if starter.Cfg.APIServerPort != 0 {
args := []string{"-f", "-NTL", fmt.Sprintf("%d:localhost:8443", starter.Cfg.APIServerPort)}
err := machine.CreateSSHShell(starter.MachineAPI, *starter.Cfg, *starter.Node, args, false)
if err != nil {
klog.Warningf("apiserver tunnel failed: %v", err)
}
}

// Write the kubeconfig to the file system after everything required (like certs) are created by the bootstrapper.
if err := kubeconfig.Update(kcs); err != nil {
return nil, bs, errors.Wrap(err, "Failed kubeconfig update")
Expand Down Expand Up @@ -561,7 +552,7 @@ func startMachine(cfg *config.ClusterConfig, node *config.Node, delOnFail bool)
return runner, preExists, m, host, errors.Wrap(err, "Failed to validate network")
}

if driver.IsQEMU(host.Driver.DriverName()) {
if driver.IsQEMU(host.Driver.DriverName()) && cfg.APIServerPort == 0 {
apiServerPort, err := getPort()
if err != nil {
return runner, preExists, m, host, errors.Wrap(err, "Failed to find apiserver port")
Expand Down

0 comments on commit e7495ab

Please sign in to comment.