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: initialize the pause state from the current state #10958

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
24 changes: 22 additions & 2 deletions cmd/auto-pause/auto-pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ var unpauseRequests = make(chan struct{})
var done = make(chan struct{})
var mu sync.Mutex

// TODO: initialize with current state (handle the case that user enables auto-pause after it is already paused)
var runtimePaused = false
var runtimePaused bool
var version = "0.0.1"

// TODO: #10597 make this configurable to support containerd/cri-o
Expand All @@ -46,6 +45,10 @@ var runtime = "docker"
func main() {
// TODO: #10595 make this configurable
const interval = time.Minute * 1

// Check current state
alreadyPaused()

// channel for incoming messages
go func() {
for {
Expand Down Expand Up @@ -121,3 +124,20 @@ func runUnpause() {

out.Step(style.Unpause, "Unpaused {{.count}} containers", out.V{"count": len(uids)})
}

func alreadyPaused() {
mu.Lock()
defer mu.Unlock()

r := command.NewExecRunner(true)
cr, err := cruntime.New(cruntime.Config{Type: runtime, Runner: r})
if err != nil {
exit.Error(reason.InternalNewRuntime, "Failed runtime", err)
}

runtimePaused, err = cluster.CheckIfPaused(cr, []string{"kube-system"})
if err != nil {
exit.Error(reason.GuestCheckPaused, "Fail check if container paused", err)
}
out.Step(style.Check, "containers paused status: {{.paused}}", out.V{"paused": runtimePaused})
}
13 changes: 13 additions & 0 deletions pkg/minikube/cluster/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,16 @@ func unpause(cr cruntime.Manager, r command.Runner, namespaces []string) ([]stri

return ids, nil
}

func CheckIfPaused(cr cruntime.Manager, namespaces []string) (bool, error) {
ids, err := cr.ListContainers(cruntime.ListOptions{State: cruntime.Paused, Namespaces: namespaces})
if err != nil {
return true, errors.Wrap(err, "list paused")
}

if len(ids) > 0 {
return true, nil
}

return false, nil
}
1 change: 1 addition & 0 deletions pkg/minikube/reason/reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ var (
GuestStatus = Kind{ID: "GUEST_STATUS", ExitCode: ExGuestError}
GuestStopTimeout = Kind{ID: "GUEST_STOP_TIMEOUT", ExitCode: ExGuestTimeout}
GuestUnpause = Kind{ID: "GUEST_UNPAUSE", ExitCode: ExGuestError}
GuestCheckPaused = Kind{ID: "GUEST_CHECK_PAUSED", ExitCode: ExGuestError}
GuestDrvMismatch = Kind{ID: "GUEST_DRIVER_MISMATCH", ExitCode: ExGuestConflict, Style: style.Conflict}
GuestMissingConntrack = Kind{ID: "GUEST_MISSING_CONNTRACK", ExitCode: ExGuestUnsupported}

Expand Down