-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the notion of an "exit policy" to a pod. This policy controls the behaviour when the last container of pod exits. Initially, there are two policies: - "continue" : the pod continues running. This is the default policy when creating a pod. - "stop" : stop the pod when the last container exits. This is the default behaviour for `play kube`. In order to implement the deferred stop of a pod, add a worker queue to the libpod runtime. The queue will pick up work items and in this case helps resolve dead locks that would otherwise occur if we attempted to stop a pod during container cleanup. Note that the default restart policy of `play kube` is "Always". Hence, in order to really solve #13464, the YAML files must set a custom restart policy; the tests use "OnFailure". Fixes: #13464 Signed-off-by: Valentin Rothberg <[email protected]>
- Loading branch information
Showing
16 changed files
with
285 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package define | ||
|
||
import "fmt" | ||
|
||
// PodExitPolicies includes the supported pod exit policies. | ||
var PodExitPolicies = []string{"continue", "stop"} | ||
|
||
// PodExitPolicy determines a pod's exit and stop behaviour. | ||
type PodExitPolicy string | ||
|
||
const ( | ||
// PodExitPolicyContinue instructs the pod to continue running when the | ||
// last container has exited. | ||
PodExitPolicyContinue PodExitPolicy = "continue" | ||
// PodExitPolicyStop instructs the pod to stop when the last container | ||
// has exited. | ||
PodExitPolicyStop = "stop" | ||
// PodExitPolicyUnsupported implies an internal error. | ||
// Negative for backwards compat. | ||
PodExitPolicyUnsupported = "invalid" | ||
) | ||
|
||
// ParsePodExitPolicy parsrs the specified policy and returns an error if it is | ||
// invalid. | ||
func ParsePodExitPolicy(policy string) (PodExitPolicy, error) { | ||
switch policy { | ||
case "", "continue": | ||
return PodExitPolicyContinue, nil | ||
case "stop": | ||
return PodExitPolicyStop, nil | ||
default: | ||
return PodExitPolicyUnsupported, fmt.Errorf("invalid pod exit policy: %q", policy) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package libpod | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
func (r *Runtime) startWorker() { | ||
if r.workerChannel == nil { | ||
r.workerChannel = make(chan func(), 1) | ||
r.workerShutdown = make(chan bool) | ||
} | ||
go func() { | ||
for { | ||
// Make sure to read all workers before | ||
// checking if we're about to shutdown. | ||
for len(r.workerChannel) > 0 { | ||
w := <-r.workerChannel | ||
w() | ||
} | ||
|
||
select { | ||
case <-r.workerShutdown: | ||
return | ||
|
||
default: | ||
time.Sleep(100 * time.Millisecond) | ||
} | ||
} | ||
}() | ||
} | ||
|
||
func (r *Runtime) queueWork(f func()) { | ||
go func() { | ||
r.workerChannel <- f | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.