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

auto-pause: restart service after configuration #19900

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 13 additions & 1 deletion cmd/minikube/cmd/config/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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 {
Expand All @@ -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})
Expand Down
13 changes: 9 additions & 4 deletions cmd/minikube/cmd/config/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,28 @@ 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.")
}
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) {
Expand Down