Skip to content

Commit d9adcd6

Browse files
auto-pause: restart service after configuration
1 parent 4957e70 commit d9adcd6

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

cmd/minikube/cmd/config/configure.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/minikube/pkg/minikube/reason"
3333
"k8s.io/minikube/pkg/minikube/service"
3434
"k8s.io/minikube/pkg/minikube/style"
35+
"k8s.io/minikube/pkg/minikube/sysinit"
3536
)
3637

3738
var posResponses = []string{"yes", "y"}
@@ -255,7 +256,7 @@ var addonsConfigureCmd = &cobra.Command{
255256
}
256257
}
257258
case "auto-pause":
258-
_, cfg := mustload.Partial(profile)
259+
lapi, cfg := mustload.Partial(profile)
259260
intervalInput := AskForStaticValue("-- Enter interval time of auto-pause-interval (ex. 1m0s): ")
260261
intervalTime, err := time.ParseDuration(intervalInput)
261262
if err != nil {
@@ -274,6 +275,15 @@ var addonsConfigureCmd = &cobra.Command{
274275
if err := addons.EnableOrDisableAddon(cfg, "auto-pause", "true"); err != nil {
275276
out.ErrT(style.Fatal, "Failed to configure auto-pause {{.profile}}", out.V{"profile": profile})
276277
}
278+
// see #17945: restart auto-pause service
279+
p, err := config.LoadProfile(profile)
280+
if err != nil {
281+
out.ErrT(style.Fatal, "failed to load profile: {{.error}}", out.V{"error": err})
282+
}
283+
if profileStatus(p, lapi).StatusCode/100 == 2 { //2xx code
284+
co := mustload.Running(profile)
285+
sysinit.New(co.CP.Runner).Restart("auto-pause")
286+
}
277287
}
278288
default:
279289
out.FailureT("{{.name}} has no available configuration options", out.V{"name": addon})

cmd/minikube/cmd/config/profile_list.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,28 @@ func updateProfilesStatus(profiles []*config.Profile) {
104104
defer api.Close()
105105

106106
for _, p := range profiles {
107-
p.Status = profileStatus(p, api)
107+
p.Status = profileStatus(p, api).StatusName
108108
}
109109
}
110110

111-
func profileStatus(p *config.Profile, api libmachine.API) string {
111+
func profileStatus(p *config.Profile, api libmachine.API) cluster.State {
112112
cps := config.ControlPlanes(*p.Config)
113113
if len(cps) == 0 {
114114
exit.Message(reason.GuestCpConfig, "No control-plane nodes found.")
115115
}
116116
statuses, err := cluster.GetStatus(api, p.Config)
117117
if err != nil {
118118
klog.Errorf("error getting statuses: %v", err)
119-
return "Unknown"
119+
return cluster.State{
120+
BaseState: cluster.BaseState{
121+
Name: "Unknown",
122+
StatusCode: 520,
123+
},
124+
}
120125
}
121126
clusterStatus := cluster.GetState(statuses, ClusterFlagValue(), p.Config)
122127

123-
return clusterStatus.StatusName
128+
return clusterStatus
124129
}
125130

126131
func renderProfilesTable(ps [][]string) {

0 commit comments

Comments
 (0)