github.com/containers/podman/v4@v4.9.4/libpod/define/exit_code_propagation.go (about)

     1  package define
     2  
     3  import "fmt"
     4  
     5  // KubeExitCodePropagation defines an exit policy of kube workloads.
     6  type KubeExitCodePropagation int
     7  
     8  const (
     9  	// Invalid exit policy for a proper type system.
    10  	KubeExitCodePropagationInvalid KubeExitCodePropagation = iota
    11  	// Exit 0 regardless of any failed containers.
    12  	KubeExitCodePropagationNone
    13  	// Exit non-zero if all containers failed.
    14  	KubeExitCodePropagationAll
    15  	// Exit non-zero if any container failed.
    16  	KubeExitCodePropagationAny
    17  
    18  	// String representations.
    19  	strKubeECPInvalid = "invalid"
    20  	strKubeECPNone    = "none"
    21  	strKubeECPAll     = "all"
    22  	strKubeECPAny     = "any"
    23  )
    24  
    25  // Parse the specified kube exit-code propagation. Return an error if an
    26  // unsupported value is specified.
    27  func ParseKubeExitCodePropagation(value string) (KubeExitCodePropagation, error) {
    28  	switch value {
    29  	case strKubeECPNone, "":
    30  		return KubeExitCodePropagationNone, nil
    31  	case strKubeECPAll:
    32  		return KubeExitCodePropagationAll, nil
    33  	case strKubeECPAny:
    34  		return KubeExitCodePropagationAny, nil
    35  	default:
    36  		return KubeExitCodePropagationInvalid, fmt.Errorf("unsupported exit-code propagation %q", value)
    37  	}
    38  }
    39  
    40  // Return the string representation of the KubeExitCodePropagation.
    41  func (k KubeExitCodePropagation) String() string {
    42  	switch k {
    43  	case KubeExitCodePropagationNone:
    44  		return strKubeECPNone
    45  	case KubeExitCodePropagationAll:
    46  		return strKubeECPAll
    47  	case KubeExitCodePropagationAny:
    48  		return strKubeECPAny
    49  	case KubeExitCodePropagationInvalid:
    50  		return strKubeECPInvalid
    51  	default:
    52  		return "unknown value"
    53  	}
    54  }