Skip to content

Commit 5b4b685

Browse files
authored
Merge pull request #15077 from spowelljr/fixPause
Fix status taking a long time on docker driver
2 parents 691cc40 + 6d00b3e commit 5b4b685

File tree

4 files changed

+87
-4
lines changed

4 files changed

+87
-4
lines changed

cmd/minikube/cmd/start.go

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import (
6868
"k8s.io/minikube/pkg/minikube/notify"
6969
"k8s.io/minikube/pkg/minikube/out"
7070
"k8s.io/minikube/pkg/minikube/out/register"
71+
"k8s.io/minikube/pkg/minikube/pause"
7172
"k8s.io/minikube/pkg/minikube/reason"
7273
"k8s.io/minikube/pkg/minikube/style"
7374
pkgtrace "k8s.io/minikube/pkg/trace"
@@ -408,6 +409,8 @@ func startWithDriver(cmd *cobra.Command, starter node.Starter, existing *config.
408409
}
409410
}
410411

412+
pause.RemovePausedFile(starter.Runner)
413+
411414
return kubeconfig, nil
412415
}
413416

pkg/minikube/bootstrapper/bsutil/kverify/api_server.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ func APIServerStatus(cr command.Runner, hostname string, port int) (state.State,
174174
rr, err := cr.RunCmd(exec.Command("sudo", "egrep", "^[0-9]+:freezer:", fmt.Sprintf("/proc/%d/cgroup", pid)))
175175
if err != nil {
176176
klog.Warningf("unable to find freezer cgroup: %v", err)
177-
return apiServerHealthz(hostname, port)
177+
return nonFreezerServerStatus(cr, hostname, port)
178178

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

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

199-
return apiServerHealthz(hostname, port)
199+
return nonFreezerServerStatus(cr, hostname, port)
200200
}
201201

202202
fs := strings.TrimSpace(rr.Stdout.String())
@@ -207,6 +207,18 @@ func APIServerStatus(cr command.Runner, hostname string, port int) (state.State,
207207
return apiServerHealthz(hostname, port)
208208
}
209209

210+
// nonFreezerServerStatus is the alternative flow if the guest does not have the freezer cgroup so different methods to detect the apiserver status are used
211+
func nonFreezerServerStatus(cr command.Runner, hostname string, port int) (state.State, error) {
212+
rr, err := cr.RunCmd(exec.Command("ls"))
213+
if err != nil {
214+
return state.None, err
215+
}
216+
if strings.Contains(rr.Stdout.String(), "paused") {
217+
return state.Paused, nil
218+
}
219+
return apiServerHealthz(hostname, port)
220+
}
221+
210222
// apiServerHealthz checks apiserver in a patient and tolerant manner
211223
func apiServerHealthz(hostname string, port int) (state.State, error) {
212224
var st state.State

pkg/minikube/cluster/pause.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"k8s.io/klog/v2"
2424
"k8s.io/minikube/pkg/minikube/command"
2525
"k8s.io/minikube/pkg/minikube/cruntime"
26+
pkgpause "k8s.io/minikube/pkg/minikube/pause"
2627
"k8s.io/minikube/pkg/minikube/sysinit"
2728
"k8s.io/minikube/pkg/util/retry"
2829
)
@@ -63,7 +64,15 @@ func pause(cr cruntime.Manager, r command.Runner, namespaces []string) ([]string
6364
return ids, nil
6465
}
6566

66-
return ids, cr.PauseContainers(ids)
67+
if err := cr.PauseContainers(ids); err != nil {
68+
return ids, errors.Wrap(err, "pausing containers")
69+
}
70+
71+
if doesNamespaceContainKubeSystem(namespaces) {
72+
pkgpause.CreatePausedFile(r)
73+
}
74+
75+
return ids, nil
6776
}
6877

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

111+
if doesNamespaceContainKubeSystem(namespaces) {
112+
pkgpause.RemovePausedFile(r)
113+
}
114+
102115
return ids, nil
103116
}
104117

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

116129
return false, nil
117130
}
131+
132+
// doesNamespaceContainKubeSystem returns true if kube-system is contained in the namespace list
133+
// This is used to only mark the apiserver as paused/unpaused when the kube-system namespace is specified
134+
func doesNamespaceContainKubeSystem(namespaces []string) bool {
135+
// nil slice indicates all namespaces
136+
if namespaces == nil {
137+
return true
138+
}
139+
for _, ns := range namespaces {
140+
if ns == "kube-system" {
141+
return true
142+
}
143+
}
144+
return false
145+
}

pkg/minikube/pause/pause.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package pause
18+
19+
import (
20+
"os/exec"
21+
22+
"k8s.io/klog/v2"
23+
"k8s.io/minikube/pkg/minikube/command"
24+
)
25+
26+
const pausedFile = "paused"
27+
28+
// CreatePausedFile creates a file in the minikube cluster to indicate that the apiserver is paused
29+
func CreatePausedFile(r command.Runner) {
30+
if _, err := r.RunCmd(exec.Command("touch", pausedFile)); err != nil {
31+
klog.Errorf("failed to create paused file, apiserver may display incorrect status")
32+
}
33+
}
34+
35+
// RemovePausedFile removes a file in minikube cluster to indicate that the apiserver is unpaused
36+
func RemovePausedFile(r command.Runner) {
37+
if _, err := r.RunCmd(exec.Command("rm", "-f", pausedFile)); err != nil {
38+
klog.Errorf("failed to remove paused file, apiserver may display incorrect status")
39+
}
40+
}

0 commit comments

Comments
 (0)