mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #691 from dchen1107/restart
Add RestartPolicy to Pod and PodTemplate
This commit is contained in:
commit
21513b1e08
@ -208,6 +208,21 @@ const (
|
|||||||
// PodInfo contains one entry for every container with available info.
|
// PodInfo contains one entry for every container with available info.
|
||||||
type PodInfo map[string]docker.Container
|
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)
|
// PodState is the state of a pod, used as either input (desired state) or output (current state)
|
||||||
type PodState struct {
|
type PodState struct {
|
||||||
Manifest ContainerManifest `json:"manifest,omitempty" yaml:"manifest,omitempty"`
|
Manifest ContainerManifest `json:"manifest,omitempty" yaml:"manifest,omitempty"`
|
||||||
@ -223,6 +238,7 @@ type PodState struct {
|
|||||||
// TODO: Make real decisions about what our info should look like. Re-enable fuzz test
|
// TODO: Make real decisions about what our info should look like. Re-enable fuzz test
|
||||||
// when we have done this.
|
// 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.
|
// PodList is a list of Pods.
|
||||||
|
@ -211,6 +211,21 @@ const (
|
|||||||
// PodInfo contains one entry for every container with available info.
|
// PodInfo contains one entry for every container with available info.
|
||||||
type PodInfo map[string]docker.Container
|
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)
|
// PodState is the state of a pod, used as either input (desired state) or output (current state)
|
||||||
type PodState struct {
|
type PodState struct {
|
||||||
Manifest ContainerManifest `json:"manifest,omitempty" yaml:"manifest,omitempty"`
|
Manifest ContainerManifest `json:"manifest,omitempty" yaml:"manifest,omitempty"`
|
||||||
@ -225,6 +240,7 @@ type PodState struct {
|
|||||||
// upon.
|
// upon.
|
||||||
// TODO: Make real decisions about what our info should look like.
|
// 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.
|
// PodList is a list of Pods.
|
||||||
|
@ -274,13 +274,26 @@ func ValidateManifest(manifest *ContainerManifest) []error {
|
|||||||
return []error(allErrs)
|
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.
|
// Pod tests if required fields in the pod are set.
|
||||||
func ValidatePod(pod *Pod) []error {
|
func ValidatePod(pod *Pod) []error {
|
||||||
allErrs := errorList{}
|
allErrs := errorList{}
|
||||||
if pod.ID == "" {
|
if pod.ID == "" {
|
||||||
allErrs.Append(makeInvalidError("Pod.ID", pod.ID))
|
allErrs.Append(makeInvalidError("Pod.ID", pod.ID))
|
||||||
}
|
}
|
||||||
allErrs.Append(ValidateManifest(&pod.DesiredState.Manifest)...)
|
allErrs.Append(ValidatePodState(&pod.DesiredState)...)
|
||||||
return []error(allErrs)
|
return []error(allErrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,6 +290,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) {
|
func TestValidateService(t *testing.T) {
|
||||||
errs := ValidateService(&Service{
|
errs := ValidateService(&Service{
|
||||||
JSONBase: JSONBase{ID: "foo"},
|
JSONBase: JSONBase{ID: "foo"},
|
||||||
|
Loading…
Reference in New Issue
Block a user