Merge pull request #10958 from azhao155/yzhao/feature/AddAutoPauseInitiliazedStatus
auto-pause: initialize the pause state from the current statepull/10995/head
commit
18dacff70f
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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})
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
||||
|
|
Loading…
Reference in New Issue