Skip to content

Fix status taking a long time on docker driver #15077

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

Merged
merged 2 commits into from
Oct 7, 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
17 changes: 14 additions & 3 deletions pkg/minikube/bootstrapper/bsutil/kverify/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ func APIServerStatus(cr command.Runner, hostname string, port int) (state.State,
rr, err := cr.RunCmd(exec.Command("sudo", "egrep", "^[0-9]+:freezer:", fmt.Sprintf("/proc/%d/cgroup", pid)))
if err != nil {
klog.Warningf("unable to find freezer cgroup: %v", err)
return apiServerHealthz(hostname, port)
return nonFreezerServerStatus(cr, hostname, port)

}
freezer := strings.TrimSpace(rr.Stdout.String())
klog.Infof("apiserver freezer: %q", freezer)
fparts := strings.Split(freezer, ":")
if len(fparts) != 3 {
klog.Warningf("unable to parse freezer - found %d parts: %s", len(fparts), freezer)
return apiServerHealthz(hostname, port)
return nonFreezerServerStatus(cr, hostname, port)
}

rr, err = cr.RunCmd(exec.Command("sudo", "cat", path.Join("/sys/fs/cgroup/freezer", fparts[2], "freezer.state")))
Expand All @@ -196,7 +196,7 @@ func APIServerStatus(cr command.Runner, hostname string, port int) (state.State,
klog.Warningf("unable to get freezer state: %s", rr.Stderr.String())
}

return apiServerHealthz(hostname, port)
return nonFreezerServerStatus(cr, hostname, port)
}

fs := strings.TrimSpace(rr.Stdout.String())
Expand All @@ -207,6 +207,17 @@ func APIServerStatus(cr command.Runner, hostname string, port int) (state.State,
return apiServerHealthz(hostname, port)
}

func nonFreezerServerStatus(cr command.Runner, hostname string, port int) (state.State, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add detailed comment for this function. the name is not self-explantory

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment

rr, err := cr.RunCmd(exec.Command("ls"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this running in home folder?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

if err != nil {
return state.None, err
}
if strings.Contains(rr.Stdout.String(), "paused") {
return state.Paused, nil
}
return apiServerHealthz(hostname, port)
}

// apiServerHealthz checks apiserver in a patient and tolerant manner
func apiServerHealthz(hostname string, port int) (state.State, error) {
var st state.State
Expand Down
32 changes: 31 additions & 1 deletion pkg/minikube/cluster/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package cluster

import (
"os/exec"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -63,7 +64,17 @@ func pause(cr cruntime.Manager, r command.Runner, namespaces []string) ([]string
return ids, nil
}

return ids, cr.PauseContainers(ids)
if err := cr.PauseContainers(ids); err != nil {
return ids, errors.Wrap(err, "pausing containers")
}

if isTouchingKubeSystem(namespaces) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious if it is better to have the "paused" file to be in the /tmp ? in case minikube VM gets restarted to be auto-cleaned ?

the question is, when minikube is paused, and user restarts minikube VM (not through minikube interface but by shutting down the laptop) would minikube still be paused ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried moving the file to /tmp, it did auto-remove the file on minikube stop. However, running minikube start when the cluster was paused resulted in the apiserver still being marked as Paused. So the paused file has to be removed on a start which nullifies the benefit to moving it to /tmp.

When the user manually restarts the container (as this only affects kicbase, not ISO) the kubelet and apiserver are stopped and a minikube start has to be run.

if _, err := r.RunCmd(exec.Command("touch", "paused")); err != nil {
klog.Errorf("failed to create paused file, apiserver may display incorrect status")
}
}

return ids, nil
}

// Unpause unpauses a Kubernetes cluster, retrying if necessary
Expand Down Expand Up @@ -99,6 +110,12 @@ func unpause(cr cruntime.Manager, r command.Runner, namespaces []string) ([]stri
return ids, errors.Wrap(err, "kubelet start")
}

if isTouchingKubeSystem(namespaces) {
if _, err := r.RunCmd(exec.Command("rm", "-f", "paused")); err != nil {
klog.Errorf("failed to remove paused file, apiserver may display incorrect status")
}
}

return ids, nil
}

Expand All @@ -115,3 +132,16 @@ func CheckIfPaused(cr cruntime.Manager, namespaces []string) (bool, error) {

return false, nil
}

// isTouchingKubeSystem returns if the user is pausing or unpausing the kube-system namespace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this function return "-ing" state ? does it mean if it returns true then another function is Touch-ing the file ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function name was vague, renamed and improved the comment

func isTouchingKubeSystem(namespaces []string) bool {
if namespaces == nil {
return true
}
for _, ns := range namespaces {
if ns == "kube-system" {
return true
}
}
return false
}