From b27c6c718c0d353d1f33b0852d341bc8ce5e203a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=94=A6=E5=8D=97=E8=B7=AF=E4=B9=8B=E8=8A=B1?= Date: Fri, 1 Nov 2024 23:21:54 +0100 Subject: [PATCH] auto-pause: restart service after configuration --- cmd/minikube/cmd/config/configure.go | 14 +++++++++++++- cmd/minikube/cmd/config/profile_list.go | 13 +++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cmd/minikube/cmd/config/configure.go b/cmd/minikube/cmd/config/configure.go index 2ae84602ea06..2b44375cd94c 100644 --- a/cmd/minikube/cmd/config/configure.go +++ b/cmd/minikube/cmd/config/configure.go @@ -32,6 +32,7 @@ import ( "k8s.io/minikube/pkg/minikube/reason" "k8s.io/minikube/pkg/minikube/service" "k8s.io/minikube/pkg/minikube/style" + "k8s.io/minikube/pkg/minikube/sysinit" ) var posResponses = []string{"yes", "y"} @@ -255,7 +256,7 @@ var addonsConfigureCmd = &cobra.Command{ } } case "auto-pause": - _, cfg := mustload.Partial(profile) + lapi, cfg := mustload.Partial(profile) intervalInput := AskForStaticValue("-- Enter interval time of auto-pause-interval (ex. 1m0s): ") intervalTime, err := time.ParseDuration(intervalInput) if err != nil { @@ -274,6 +275,17 @@ var addonsConfigureCmd = &cobra.Command{ if err := addons.EnableOrDisableAddon(cfg, "auto-pause", "true"); err != nil { out.ErrT(style.Fatal, "Failed to configure auto-pause {{.profile}}", out.V{"profile": profile}) } + // see #17945: restart auto-pause service + p, err := config.LoadProfile(profile) + if err != nil { + out.ErrT(style.Fatal, "failed to load profile: {{.error}}", out.V{"error": err}) + } + if profileStatus(p, lapi).StatusCode/100 == 2 { // 2xx code + co := mustload.Running(profile) + if err := sysinit.New(co.CP.Runner).Restart("auto-pause"); err != nil { + out.ErrT(style.Fatal, "failed to restart auto-pause: {{.error}}", out.V{"error": err}) + } + } } default: out.FailureT("{{.name}} has no available configuration options", out.V{"name": addon}) diff --git a/cmd/minikube/cmd/config/profile_list.go b/cmd/minikube/cmd/config/profile_list.go index fd34543f4792..081b02699523 100644 --- a/cmd/minikube/cmd/config/profile_list.go +++ b/cmd/minikube/cmd/config/profile_list.go @@ -104,11 +104,11 @@ func updateProfilesStatus(profiles []*config.Profile) { defer api.Close() for _, p := range profiles { - p.Status = profileStatus(p, api) + p.Status = profileStatus(p, api).StatusName } } -func profileStatus(p *config.Profile, api libmachine.API) string { +func profileStatus(p *config.Profile, api libmachine.API) cluster.State { cps := config.ControlPlanes(*p.Config) if len(cps) == 0 { exit.Message(reason.GuestCpConfig, "No control-plane nodes found.") @@ -116,11 +116,16 @@ func profileStatus(p *config.Profile, api libmachine.API) string { statuses, err := cluster.GetStatus(api, p.Config) if err != nil { klog.Errorf("error getting statuses: %v", err) - return "Unknown" + return cluster.State{ + BaseState: cluster.BaseState{ + Name: "Unknown", + StatusCode: 520, + }, + } } clusterStatus := cluster.GetState(statuses, ClusterFlagValue(), p.Config) - return clusterStatus.StatusName + return clusterStatus } func renderProfilesTable(ps [][]string) {