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

re-establish apiserver tunnel on restart #14183

Merged
merged 4 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
re-establish apiserver tunnel on restart
  • Loading branch information
sharifelgamal committed May 17, 2022
commit f02e97754447c6d9e8848fb3755c6248e435e121
6 changes: 3 additions & 3 deletions pkg/drivers/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,17 +494,17 @@ func (d *Driver) Stop() error {
func (d *Driver) Remove() error {
s, err := d.GetState()
if err != nil {
return err
return errors.Wrap(err, "get state")
}
if s == state.Running {
if err := d.Kill(); err != nil {
return err
return errors.Wrap(err, "kill")
}
}
if s != state.Stopped {
_, err = d.RunQMPCommand("quit")
if err != nil {
return err
return errors.Wrap(err, "quit")
}
}
return nil
Expand Down
24 changes: 24 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error {
}()

wg.Wait()
if cfg.APIServerPort != 0 {
k.tunnelToAPIServer(cfg)
}
return nil
}

Expand Down Expand Up @@ -399,6 +402,10 @@ func (k *Bootstrapper) StartCluster(cfg config.ClusterConfig) error {
}

if err := bsutil.ExistingConfig(k.c); err == nil {
// Tunnel apiserver to guest, if needed
if cfg.APIServerPort != 0 {
k.tunnelToAPIServer(cfg)
}
klog.Infof("found existing configuration files, will attempt cluster restart")
rerr := k.restartControlPlane(cfg)
if rerr == nil {
Expand Down Expand Up @@ -433,6 +440,22 @@ func (k *Bootstrapper) StartCluster(cfg config.ClusterConfig) error {
return err
}

func (k *Bootstrapper) tunnelToAPIServer(cfg config.ClusterConfig) {
m, err := machine.NewAPIClient()
if err != nil {
klog.Warningf("libmachine API failed: %v", err)
}
cp, err := config.PrimaryControlPlane(&cfg)
if err != nil {
klog.Warningf("finding control plane failed: %v", err)
}
args := []string{"-f", "-NTL", fmt.Sprintf("%d:localhost:8443", cfg.APIServerPort)}
err = machine.CreateSSHShell(m, cfg, cp, args, false)
if err != nil {
klog.Warningf("apiserver tunnel failed: %v", err)
}
}

// client sets and returns a Kubernetes client to use to speak to a kubeadm launched apiserver
func (k *Bootstrapper) client(ip string, port int) (*kubernetes.Clientset, error) {
if k.k8sClient != nil {
Expand Down Expand Up @@ -569,6 +592,7 @@ func (k *Bootstrapper) needsReconfigure(conf string, hostname string, port int,
klog.Infof("needs reconfigure: configs differ:\n%s", rr.Output())
return true
}

// cruntime.Enable() may restart kube-apiserver but does not wait for it to return back
apiStatusTimeout := 3000 * time.Millisecond
st, err := kverify.WaitForAPIServerStatus(k.c, apiStatusTimeout, hostname, port)
Expand Down
9 changes: 0 additions & 9 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