Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
21513b1e
Commit
21513b1e
authored
Jul 30, 2014
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #691 from dchen1107/restart
Add RestartPolicy to Pod and PodTemplate
parents
c5ca0322
2740fb0a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
3 deletions
+90
-3
types.go
pkg/api/types.go
+17
-1
types.go
pkg/api/v1beta1/types.go
+17
-1
validation.go
pkg/api/validation.go
+14
-1
validation_test.go
pkg/api/validation_test.go
+42
-0
No files found.
pkg/api/types.go
View file @
21513b1e
...
@@ -208,6 +208,21 @@ const (
...
@@ -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"`
...
@@ -222,7 +237,8 @@ type PodState struct {
...
@@ -222,7 +237,8 @@ type PodState struct {
// upon.
// upon.
// 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.
...
...
pkg/api/v1beta1/types.go
View file @
21513b1e
...
@@ -211,6 +211,21 @@ const (
...
@@ -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"`
...
@@ -224,7 +239,8 @@ type PodState struct {
...
@@ -224,7 +239,8 @@ type PodState struct {
// of `docker inspect`. This output format is *not* final and should not be relied
// of `docker inspect`. This output format is *not* final and should not be relied
// 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.
...
...
pkg/api/validation.go
View file @
21513b1e
...
@@ -274,13 +274,26 @@ func ValidateManifest(manifest *ContainerManifest) []error {
...
@@ -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
(
Validate
Manifest
(
&
pod
.
DesiredState
.
Manifest
)
...
)
allErrs
.
Append
(
Validate
PodState
(
&
pod
.
DesiredState
)
...
)
return
[]
error
(
allErrs
)
return
[]
error
(
allErrs
)
}
}
...
...
pkg/api/validation_test.go
View file @
21513b1e
...
@@ -290,6 +290,48 @@ func TestValidateManifest(t *testing.T) {
...
@@ -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"
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment