-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
containers.conf: add pod_exit_policy
Add a new `pod_exit_policy` field to the containers.conf's engine table. A pod's exit policy determines the behaviour when the last container of a pod exits. Required-in: containers/podman/pull/13859 Signed-off-by: Valentin Rothberg <[email protected]>
- Loading branch information
Showing
8 changed files
with
89 additions
and
0 deletions.
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
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 config | ||
|
||
import "fmt" | ||
|
||
// PodExitPolicies includes the supported pod exit policies. | ||
var PodExitPolicies = []string{string(PodExitPolicyContinue), string(PodExitPolicyStop)} | ||
|
||
// 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" | ||
|
||
defaultPodExitPolicy = PodExitPolicyContinue | ||
) | ||
|
||
// ParsePodExitPolicy parses the specified policy and returns an error if it is | ||
// invalid. | ||
func ParsePodExitPolicy(policy string) (PodExitPolicy, error) { | ||
switch policy { | ||
case "", string(PodExitPolicyContinue): | ||
return PodExitPolicyContinue, nil | ||
case string(PodExitPolicyStop): | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParsePodExitPolicy(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected PodExitPolicy | ||
mustFail bool | ||
}{ | ||
{"", PodExitPolicyContinue, false}, | ||
{"continue", PodExitPolicyContinue, false}, | ||
{"stop", PodExitPolicyStop, false}, | ||
{"-", PodExitPolicyUnsupported, true}, | ||
{" stop", PodExitPolicyUnsupported, true}, | ||
{"continue ", PodExitPolicyUnsupported, true}, | ||
{"invalid", PodExitPolicyUnsupported, true}, | ||
} | ||
|
||
for _, test := range tests { | ||
parsed, err := ParsePodExitPolicy(test.input) | ||
require.Equal(t, test.expected, parsed, "%v", test) | ||
if test.mustFail { | ||
require.Error(t, err, "%v", test) | ||
} else { | ||
require.NoError(t, err, "%v", test) | ||
} | ||
} | ||
} |
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