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

Fix status taking a long time on docker driver #15077

Merged
merged 2 commits into from
Oct 7, 2022
Merged
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
3 changes: 3 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import (
"k8s.io/minikube/pkg/minikube/notify"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/out/register"
"k8s.io/minikube/pkg/minikube/pause"
"k8s.io/minikube/pkg/minikube/reason"
"k8s.io/minikube/pkg/minikube/style"
pkgtrace "k8s.io/minikube/pkg/trace"
Expand Down Expand Up @@ -408,6 +409,8 @@ func startWithDriver(cmd *cobra.Command, starter node.Starter, existing *config.
}
}

pause.RemovePausedFile(starter.Runner)

return kubeconfig, nil
}

Expand Down
18 changes: 15 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,18 @@ func APIServerStatus(cr command.Runner, hostname string, port int) (state.State,
return apiServerHealthz(hostname, port)
}

// nonFreezerServerStatus is the alternative flow if the guest does not have the freezer cgroup so different methods to detect the apiserver status are used
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
30 changes: 29 additions & 1 deletion pkg/minikube/cluster/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/cruntime"
pkgpause "k8s.io/minikube/pkg/minikube/pause"
"k8s.io/minikube/pkg/minikube/sysinit"
"k8s.io/minikube/pkg/util/retry"
)
Expand Down Expand Up @@ -63,7 +64,15 @@ 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 doesNamespaceContainKubeSystem(namespaces) {
pkgpause.CreatePausedFile(r)
}

return ids, nil
}

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

if doesNamespaceContainKubeSystem(namespaces) {
pkgpause.RemovePausedFile(r)
}

return ids, nil
}

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

return false, nil
}

// doesNamespaceContainKubeSystem returns true if kube-system is contained in the namespace list
// This is used to only mark the apiserver as paused/unpaused when the kube-system namespace is specified
func doesNamespaceContainKubeSystem(namespaces []string) bool {
// nil slice indicates all namespaces
if namespaces == nil {
return true
}
for _, ns := range namespaces {
if ns == "kube-system" {
return true
}
}
return false
}
40 changes: 40 additions & 0 deletions pkg/minikube/pause/pause.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2022 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package pause

import (
"os/exec"

"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/command"
)

const pausedFile = "paused"

// CreatePausedFile creates a file in the minikube cluster to indicate that the apiserver is paused
func CreatePausedFile(r command.Runner) {
if _, err := r.RunCmd(exec.Command("touch", pausedFile)); err != nil {
klog.Errorf("failed to create paused file, apiserver may display incorrect status")
}
}

// RemovePausedFile removes a file in minikube cluster to indicate that the apiserver is unpaused
func RemovePausedFile(r command.Runner) {
if _, err := r.RunCmd(exec.Command("rm", "-f", pausedFile)); err != nil {
klog.Errorf("failed to remove paused file, apiserver may display incorrect status")
}
}