mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Add RestartPolicy to Pod and PodTemplate
This commit is contained in:
parent
cf1f17957a
commit
2740fb0abf
@ -211,6 +211,21 @@ const (
|
||||
// PodInfo contains one entry for every container with available info.
|
||||
type PodInfo map[string]docker.Container
|
||||
|
||||
// RestartPolicyType represents a restart policy for a pod.
|
||||
type RestartPolicyType string
|
||||
|
||||
// Valid restart policies defined for a PodState.RestartPolicy.
|
||||
const (
|
||||
RestartAlways RestartPolicyType = "RestartAlways"
|
||||
RestartOnFailure RestartPolicyType = "RestartOnFailure"
|
||||
RestartNever RestartPolicyType = "RestartNever"
|
||||
)
|
||||
|
||||
type RestartPolicy struct {
|
||||
// Optional: Defaults to "RestartAlways".
|
||||
Type RestartPolicyType `yaml:"type,omitempty" json:"type,omitempty"`
|
||||
}
|
||||
|
||||
// PodState is the state of a pod, used as either input (desired state) or output (current state)
|
||||
type PodState struct {
|
||||
Manifest ContainerManifest `json:"manifest,omitempty" yaml:"manifest,omitempty"`
|
||||
@ -225,7 +240,8 @@ type PodState struct {
|
||||
// upon.
|
||||
// TODO: Make real decisions about what our info should look like. Re-enable fuzz test
|
||||
// when we have done this.
|
||||
Info PodInfo `json:"info,omitempty" yaml:"info,omitempty"`
|
||||
Info PodInfo `json:"info,omitempty" yaml:"info,omitempty"`
|
||||
RestartPolicy RestartPolicy `json:"restartpolicy,omitempty" yaml:"restartpolicy,omitempty"`
|
||||
}
|
||||
|
||||
// PodList is a list of Pods.
|
||||
|
@ -211,6 +211,21 @@ const (
|
||||
// PodInfo contains one entry for every container with available info.
|
||||
type PodInfo map[string]docker.Container
|
||||
|
||||
// RestartPolicyType represents a restart policy for a pod.
|
||||
type RestartPolicyType string
|
||||
|
||||
// Valid restart policies defined for a PodState.RestartPolicy.
|
||||
const (
|
||||
RestartAlways RestartPolicyType = "RestartAlways"
|
||||
RestartOnFailure RestartPolicyType = "RestartOnFailure"
|
||||
RestartNever RestartPolicyType = "RestartNever"
|
||||
)
|
||||
|
||||
type RestartPolicy struct {
|
||||
// Optional: Defaults to "RestartAlways".
|
||||
Type RestartPolicyType `yaml:"type,omitempty" json:"type,omitempty"`
|
||||
}
|
||||
|
||||
// PodState is the state of a pod, used as either input (desired state) or output (current state)
|
||||
type PodState struct {
|
||||
Manifest ContainerManifest `json:"manifest,omitempty" yaml:"manifest,omitempty"`
|
||||
@ -224,7 +239,8 @@ type PodState struct {
|
||||
// of `docker inspect`. This output format is *not* final and should not be relied
|
||||
// upon.
|
||||
// TODO: Make real decisions about what our info should look like.
|
||||
Info PodInfo `json:"info,omitempty" yaml:"info,omitempty"`
|
||||
Info PodInfo `json:"info,omitempty" yaml:"info,omitempty"`
|
||||
RestartPolicy RestartPolicy `json:"restartpolicy,omitempty" yaml:"restartpolicy,omitempty"`
|
||||
}
|
||||
|
||||
// PodList is a list of Pods.
|
||||
|
@ -281,13 +281,26 @@ func ValidateManifest(manifest *ContainerManifest) []error {
|
||||
return []error(allErrs)
|
||||
}
|
||||
|
||||
func ValidatePodState(podState *PodState) []error {
|
||||
allErrs := errorList(ValidateManifest(&podState.Manifest))
|
||||
if podState.RestartPolicy.Type == "" {
|
||||
podState.RestartPolicy.Type = RestartAlways
|
||||
} else if podState.RestartPolicy.Type != RestartAlways &&
|
||||
podState.RestartPolicy.Type != RestartOnFailure &&
|
||||
podState.RestartPolicy.Type != RestartNever {
|
||||
allErrs.Append(makeNotSupportedError("PodState.RestartPolicy.Type", podState.RestartPolicy.Type))
|
||||
}
|
||||
|
||||
return []error(allErrs)
|
||||
}
|
||||
|
||||
// Pod tests if required fields in the pod are set.
|
||||
func ValidatePod(pod *Pod) []error {
|
||||
allErrs := errorList{}
|
||||
if pod.ID == "" {
|
||||
allErrs.Append(makeInvalidError("Pod.ID", pod.ID))
|
||||
}
|
||||
allErrs.Append(ValidateManifest(&pod.DesiredState.Manifest)...)
|
||||
allErrs.Append(ValidatePodState(&pod.DesiredState)...)
|
||||
return []error(allErrs)
|
||||
}
|
||||
|
||||
|
@ -262,6 +262,48 @@ func TestValidateManifest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatePod(t *testing.T) {
|
||||
errs := ValidatePod(&Pod{
|
||||
JSONBase: JSONBase{ID: "foo"},
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
DesiredState: PodState{
|
||||
Manifest: ContainerManifest{Version: "v1beta1", ID: "abc"},
|
||||
RestartPolicy: RestartPolicy{Type: "RestartAlways"},
|
||||
},
|
||||
})
|
||||
if len(errs) != 0 {
|
||||
t.Errorf("Unexpected non-zero error list: %#v", errs)
|
||||
}
|
||||
errs = ValidatePod(&Pod{
|
||||
JSONBase: JSONBase{ID: "foo"},
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
DesiredState: PodState{
|
||||
Manifest: ContainerManifest{Version: "v1beta1", ID: "abc"},
|
||||
},
|
||||
})
|
||||
if len(errs) != 0 {
|
||||
t.Errorf("Unexpected non-zero error list: %#v", errs)
|
||||
}
|
||||
|
||||
errs = ValidatePod(&Pod{
|
||||
JSONBase: JSONBase{ID: "foo"},
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
DesiredState: PodState{
|
||||
Manifest: ContainerManifest{Version: "v1beta1", ID: "abc"},
|
||||
RestartPolicy: RestartPolicy{Type: "WhatEver"},
|
||||
},
|
||||
})
|
||||
if len(errs) != 1 {
|
||||
t.Errorf("Unexpected error list: %#v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateService(t *testing.T) {
|
||||
errs := ValidateService(&Service{
|
||||
JSONBase: JSONBase{ID: "foo"},
|
||||
|
Loading…
Reference in New Issue
Block a user