File: pod_exit_policy.go

package info (click to toggle)
golang-github-containers-common 0.64.2%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,528 kB
  • sloc: makefile: 130; sh: 102
file content (36 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)
	}
}