diff --git a/deploy/addons/auto-pause/auto-pause.yaml.tmpl b/deploy/addons/auto-pause/auto-pause.yaml.tmpl index 672925bef2..5bdafce3d5 100644 --- a/deploy/addons/auto-pause/auto-pause.yaml.tmpl +++ b/deploy/addons/auto-pause/auto-pause.yaml.tmpl @@ -44,5 +44,4 @@ spec: mountPath: /usr/local/etc/haproxy/haproxy.cfg readOnly: true - name: lua-script - mountPath: /etc/haproxy/unpause.lua ---- \ No newline at end of file + mountPath: /etc/haproxy/unpause.lua \ No newline at end of file diff --git a/pkg/addons/addons.go b/pkg/addons/addons.go index 5b03e6a2fc..6f548892df 100644 --- a/pkg/addons/addons.go +++ b/pkg/addons/addons.go @@ -18,7 +18,6 @@ package addons import ( "fmt" - "os/exec" "path" "runtime" "sort" @@ -47,6 +46,7 @@ import ( "k8s.io/minikube/pkg/minikube/reason" "k8s.io/minikube/pkg/minikube/storageclass" "k8s.io/minikube/pkg/minikube/style" + "k8s.io/minikube/pkg/minikube/sysinit" "k8s.io/minikube/pkg/util/retry" ) @@ -210,8 +210,7 @@ https://github.com/kubernetes/minikube/issues/7332`, out.V{"driver_name": cc.Dri } if name == "auto-pause" && !enable { // needs to be disabled before deleting the service file in the internal disable - cmd := exec.Command("sudo", "systemctl", "disable", "--now", "auto-pause") - if _, err := runner.RunCmd(cmd); err != nil { + if err := sysinit.New(runner).DisableNow("auto-pause"); err != nil { klog.ErrorS(err, "failed to disable", "service", "auto-pause") } } @@ -453,12 +452,9 @@ func enableOrDisableAutoPause(cc *config.ClusterConfig, name string, val string) return errors.Wrapf(err, "parsing bool: %s", name) } co := mustload.Running(cc.Name) - r := co.CP.Runner if enable { - cmd := exec.Command("sudo", "systemctl", "enable", "--now", "auto-pause") - if _, err := r.RunCmd(cmd); err != nil { + if err := sysinit.New(co.CP.Runner).EnableNow("auto-pause"); err != nil { klog.ErrorS(err, "failed to enable", "service", "auto-pause") - return err } } diff --git a/pkg/minikube/sysinit/openrc.go b/pkg/minikube/sysinit/openrc.go index 7570516d5a..8966260b92 100644 --- a/pkg/minikube/sysinit/openrc.go +++ b/pkg/minikube/sysinit/openrc.go @@ -117,11 +117,21 @@ func (s *OpenRC) Disable(svc string) error { return nil } +// DisableNow not implemented for openRC +func (s *OpenRC) DisableNow(svc string) error { + return fmt.Errorf("DisableNow not implemented for OpenRC! PRs to fix are welcomed.") +} + // Enable does nothing func (s *OpenRC) Enable(svc string) error { return nil } +// EnableNow not implemented for openRC +func (s *OpenRC) EnableNow(svc string) error { + return fmt.Errorf("EnableNow not implemented for OpenRC! PRs to fix are welcomed.") +} + // Restart restarts a service func (s *OpenRC) Restart(svc string) error { rr, err := s.r.RunCmd(exec.Command("sudo", "service", svc, "restart")) diff --git a/pkg/minikube/sysinit/sysinit.go b/pkg/minikube/sysinit/sysinit.go index 122d53fd6e..5f19aed9e0 100644 --- a/pkg/minikube/sysinit/sysinit.go +++ b/pkg/minikube/sysinit/sysinit.go @@ -41,9 +41,15 @@ type Manager interface { // Disable disables a service Disable(string) error + // Disable disables a service and stops it right after. + DisableNow(string) error + // Enable enables a service Enable(string) error + // EnableNow enables a service and starts it right after. + EnableNow(string) error + // Start starts a service idempotently Start(string) error diff --git a/pkg/minikube/sysinit/systemd.go b/pkg/minikube/sysinit/systemd.go index bd36bcc770..77de6d9679 100644 --- a/pkg/minikube/sysinit/systemd.go +++ b/pkg/minikube/sysinit/systemd.go @@ -52,6 +52,12 @@ func (s *Systemd) Disable(svc string) error { return err } +// DisableNow disables a service and stops it too (not waiting for next restart) +func (s *Systemd) DisableNow(svc string) error { + _, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "disable", "--now", svc)) + return err +} + // Enable enables a service func (s *Systemd) Enable(svc string) error { if svc == "kubelet" { @@ -61,6 +67,15 @@ func (s *Systemd) Enable(svc string) error { return err } +// Enable enables a service and then activates it too (not waiting for next start) +func (s *Systemd) EnableNow(svc string) error { + if svc == "kubelet" { + return errors.New("please don't enable kubelet as it creates a race condition; if it starts on systemd boot it will pick up /etc/hosts before we have time to configure /etc/hosts") + } + _, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "enable", "--now", svc)) + return err +} + // Start starts a service func (s *Systemd) Start(svc string) error { if err := s.daemonReload(); err != nil {