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
f4cffdc7
Commit
f4cffdc7
authored
Nov 05, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2179 from markturansky/v1beta3_refactor_podcontants
Refactor PodStatus to PodCondition in internal API for v1beta3
parents
0420005a
119f654a
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
139 additions
and
46 deletions
+139
-46
latest_test.go
pkg/api/latest/latest_test.go
+6
-2
serialization_test.go
pkg/api/serialization_test.go
+6
-2
types.go
pkg/api/types.go
+16
-9
conversion.go
pkg/api/v1beta1/conversion.go
+38
-0
conversion.go
pkg/api/v1beta2/conversion.go
+38
-1
types.go
pkg/api/v1beta3/types.go
+2
-2
client_test.go
pkg/client/client_test.go
+5
-5
replication_controller.go
pkg/controller/replication_controller.go
+2
-1
describe.go
pkg/kubectl/describe.go
+8
-6
etcd.go
pkg/registry/etcd/etcd.go
+1
-1
rest.go
pkg/registry/pod/rest.go
+7
-7
rest_test.go
pkg/registry/pod/rest_test.go
+7
-7
scheduler.go
plugin/pkg/scheduler/scheduler.go
+3
-3
No files found.
pkg/api/latest/latest_test.go
View file @
f4cffdc7
...
...
@@ -26,8 +26,8 @@ import (
_
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
_
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/fsouza/go-dockerclient"
"github.com/google/gofuzz"
docker
"github.com/fsouza/go-dockerclient"
fuzz
"github.com/google/gofuzz"
)
// apiObjectFuzzer can randomly populate api objects.
...
...
@@ -71,6 +71,10 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
j
.
ResourceVersion
=
strconv
.
FormatUint
(
c
.
RandUint64
()
>>
8
,
10
)
j
.
FieldPath
=
c
.
RandString
()
},
func
(
j
*
internal
.
PodCondition
,
c
fuzz
.
Continue
)
{
statuses
:=
[]
internal
.
PodCondition
{
internal
.
PodPending
,
internal
.
PodRunning
,
internal
.
PodFailed
}
*
j
=
statuses
[
c
.
Rand
.
Intn
(
len
(
statuses
))]
},
func
(
intstr
*
util
.
IntOrString
,
c
fuzz
.
Continue
)
{
// util.IntOrString will panic if its kind is set wrong.
if
c
.
RandBool
()
{
...
...
pkg/api/serialization_test.go
View file @
f4cffdc7
...
...
@@ -31,8 +31,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta2"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/fsouza/go-dockerclient"
"github.com/google/gofuzz"
docker
"github.com/fsouza/go-dockerclient"
fuzz
"github.com/google/gofuzz"
)
var
fuzzIters
=
flag
.
Int
(
"fuzz_iters"
,
40
,
"How many fuzzing iterations to do."
)
...
...
@@ -86,6 +86,10 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
j
.
ResourceVersion
=
strconv
.
FormatUint
(
c
.
RandUint64
()
>>
8
,
10
)
j
.
SelfLink
=
c
.
RandString
()
},
func
(
j
*
api
.
PodCondition
,
c
fuzz
.
Continue
)
{
statuses
:=
[]
api
.
PodCondition
{
api
.
PodPending
,
api
.
PodRunning
,
api
.
PodFailed
}
*
j
=
statuses
[
c
.
Rand
.
Intn
(
len
(
statuses
))]
},
func
(
intstr
*
util
.
IntOrString
,
c
fuzz
.
Continue
)
{
// util.IntOrString will panic if its kind is set wrong.
if
c
.
RandBool
()
{
...
...
pkg/api/types.go
View file @
f4cffdc7
...
...
@@ -331,17 +331,24 @@ type Lifecycle struct {
// The below types are used by kube_client and api_server.
// Pod
Status represents a status of a pod
.
type
Pod
Status
string
// Pod
Condition is a label for the condition of a pod at the current time
.
type
Pod
Condition
string
// These are the valid statuses of pods.
const
(
// PodWaiting means that we're waiting for the pod to begin running.
PodWaiting
PodStatus
=
"Waiting"
// PodRunning means that the pod is up and running.
PodRunning
PodStatus
=
"Running"
// PodTerminated means that the pod has stopped.
PodTerminated
PodStatus
=
"Terminated"
// PodPending means the pod has been accepted by the system, but one or more of the containers
// has not been started. This includes time before being bound to a node, as well as time spent
// pulling images onto the host.
PodPending
PodCondition
=
"Pending"
// PodRunning means the pod has been bound to a node and all of the containers have been started.
// At least one container is still running or is in the process of being restarted.
PodRunning
PodCondition
=
"Running"
// PodSucceeded means that all containers in the pod have voluntarily terminated
// with a container exit code of 0, and the system is not going to restart any of these containers.
PodSucceeded
PodCondition
=
"Succeeded"
// PodFailed means that all containers in the pod have terminated, and at least one container has
// terminated in a failure (exited with a non-zero exit code or was stopped by the system).
PodFailed
PodCondition
=
"Failed"
)
type
ContainerStateWaiting
struct
{
...
...
@@ -408,7 +415,7 @@ type RestartPolicy struct {
// 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"`
Status
Pod
Status
`json:"status,omitempty" yaml:"status,omitempty"`
Status
Pod
Condition
`json:"status,omitempty" yaml:"status,omitempty"`
Host
string
`json:"host,omitempty" yaml:"host,omitempty"`
HostIP
string
`json:"hostIP,omitempty" yaml:"hostIP,omitempty"`
PodIP
string
`json:"podIP,omitempty" yaml:"podIP,omitempty"`
...
...
pkg/api/v1beta1/conversion.go
View file @
f4cffdc7
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
v1beta1
import
(
"errors"
"strconv"
newer
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
...
@@ -159,6 +160,43 @@ func init() {
return
nil
},
// Convert all to the new PodCondition constants
func
(
in
*
newer
.
PodCondition
,
out
*
PodStatus
,
s
conversion
.
Scope
)
error
{
switch
*
in
{
case
""
:
*
out
=
""
case
newer
.
PodPending
:
*
out
=
PodWaiting
case
newer
.
PodRunning
:
*
out
=
PodRunning
case
newer
.
PodSucceeded
:
*
out
=
PodTerminated
case
newer
.
PodFailed
:
*
out
=
PodTerminated
default
:
return
errors
.
New
(
"The string provided is not a valid PodCondition constant value"
)
}
return
nil
},
func
(
in
*
PodStatus
,
out
*
newer
.
PodCondition
,
s
conversion
.
Scope
)
error
{
switch
*
in
{
case
""
:
*
out
=
""
case
PodWaiting
:
*
out
=
newer
.
PodPending
case
PodRunning
:
*
out
=
newer
.
PodRunning
case
PodTerminated
:
// Older API versions did not contain enough info to map to PodFailed
*
out
=
newer
.
PodFailed
default
:
return
errors
.
New
(
"The string provided is not a valid PodCondition constant value"
)
}
return
nil
},
// Convert all the standard objects
func
(
in
*
newer
.
Pod
,
out
*
Pod
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
...
...
pkg/api/v1beta2/conversion.go
View file @
f4cffdc7
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
v1beta2
import
(
"errors"
"strconv"
newer
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
...
@@ -89,7 +90,43 @@ func init() {
return
s
.
Convert
(
&
in
.
Annotations
,
&
out
.
Annotations
,
0
)
},
// Convert all the standard objects
// Convert all to the new PodCondition constants
func
(
in
*
newer
.
PodCondition
,
out
*
PodStatus
,
s
conversion
.
Scope
)
error
{
switch
*
in
{
case
""
:
*
out
=
""
case
newer
.
PodPending
:
*
out
=
PodWaiting
case
newer
.
PodRunning
:
*
out
=
PodRunning
case
newer
.
PodSucceeded
:
*
out
=
PodTerminated
case
newer
.
PodFailed
:
*
out
=
PodTerminated
default
:
return
errors
.
New
(
"The string provided is not a valid PodCondition constant value"
)
}
return
nil
},
func
(
in
*
PodStatus
,
out
*
newer
.
PodCondition
,
s
conversion
.
Scope
)
error
{
switch
*
in
{
case
""
:
*
out
=
""
case
PodWaiting
:
*
out
=
newer
.
PodPending
case
PodRunning
:
*
out
=
newer
.
PodRunning
case
PodTerminated
:
// Older API versions did not contain enough info to map to PodFailed
*
out
=
newer
.
PodFailed
default
:
return
errors
.
New
(
"The string provided is not a valid PodCondition constant value"
)
}
return
nil
},
// Convert all the standard objects
func
(
in
*
newer
.
Pod
,
out
*
Pod
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
...
...
pkg/api/v1beta3/types.go
View file @
f4cffdc7
...
...
@@ -374,8 +374,8 @@ const (
// PodRunning means the pod has been bound to a node and all of the containers have been started.
// At least one container is still running or is in the process of being restarted.
PodRunning
PodCondition
=
"Running"
// PodSucceeded means that all containers in the pod have voluntarily terminated
with a container
//
exit code of 0
.
// PodSucceeded means that all containers in the pod have voluntarily terminated
//
with a container exit code of 0, and the system is not going to restart any of these containers
.
PodSucceeded
PodCondition
=
"Succeeded"
// PodFailed means that all containers in the pod have terminated, and at least one container has
// terminated in a failure (exited with a non-zero exit code or was stopped by the system).
...
...
pkg/client/client_test.go
View file @
f4cffdc7
...
...
@@ -165,7 +165,7 @@ func TestListPods(t *testing.T) {
Items
:
[]
api
.
Pod
{
{
CurrentState
:
api
.
PodState
{
Status
:
"Foobar"
,
Status
:
api
.
PodRunning
,
},
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
...
...
@@ -198,7 +198,7 @@ func TestListPodsLabels(t *testing.T) {
Items
:
[]
api
.
Pod
{
{
CurrentState
:
api
.
PodState
{
Status
:
"Foobar"
,
Status
:
api
.
PodRunning
,
},
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
...
...
@@ -226,7 +226,7 @@ func TestGetPod(t *testing.T) {
StatusCode
:
200
,
Body
:
&
api
.
Pod
{
CurrentState
:
api
.
PodState
{
Status
:
"Foobar"
,
Status
:
api
.
PodRunning
,
},
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
...
...
@@ -253,7 +253,7 @@ func TestDeletePod(t *testing.T) {
func
TestCreatePod
(
t
*
testing
.
T
)
{
requestPod
:=
&
api
.
Pod
{
CurrentState
:
api
.
PodState
{
Status
:
"Foobar"
,
Status
:
api
.
PodRunning
,
},
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
...
...
@@ -284,7 +284,7 @@ func TestUpdatePod(t *testing.T) {
},
},
CurrentState
:
api
.
PodState
{
Status
:
"Foobar"
,
Status
:
api
.
PodRunning
,
},
}
c
:=
&
testClient
{
...
...
pkg/controller/replication_controller.go
View file @
f4cffdc7
...
...
@@ -134,7 +134,8 @@ func (rm *ReplicationManager) watchControllers(resourceVersion *string) {
func
(
rm
*
ReplicationManager
)
filterActivePods
(
pods
[]
api
.
Pod
)
[]
api
.
Pod
{
var
result
[]
api
.
Pod
for
_
,
value
:=
range
pods
{
if
api
.
PodTerminated
!=
value
.
CurrentState
.
Status
{
if
api
.
PodSucceeded
!=
value
.
CurrentState
.
Status
&&
api
.
PodFailed
!=
value
.
CurrentState
.
Status
{
result
=
append
(
result
,
value
)
}
}
...
...
pkg/kubectl/describe.go
View file @
f4cffdc7
...
...
@@ -120,7 +120,7 @@ func (d *ReplicationControllerDescriber) Describe(namespace, name string) (strin
return
""
,
err
}
running
,
waiting
,
terminat
ed
,
err
:=
getPodStatusForReplicationController
(
pc
,
controller
)
running
,
waiting
,
succeeded
,
fail
ed
,
err
:=
getPodStatusForReplicationController
(
pc
,
controller
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -131,7 +131,7 @@ func (d *ReplicationControllerDescriber) Describe(namespace, name string) (strin
fmt
.
Fprintf
(
out
,
"Selector:
\t
%s
\n
"
,
formatLabels
(
controller
.
DesiredState
.
ReplicaSelector
))
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
formatLabels
(
controller
.
Labels
))
fmt
.
Fprintf
(
out
,
"Replicas:
\t
%d current / %d desired
\n
"
,
controller
.
CurrentState
.
Replicas
,
controller
.
DesiredState
.
Replicas
)
fmt
.
Fprintf
(
out
,
"Pods Status:
\t
%d Running / %d Waiting / %d
Terminated
\n
"
,
running
,
waiting
,
terminat
ed
)
fmt
.
Fprintf
(
out
,
"Pods Status:
\t
%d Running / %d Waiting / %d
Succeeded / %d Failed
\n
"
,
running
,
waiting
,
succeeded
,
fail
ed
)
return
nil
})
}
...
...
@@ -216,7 +216,7 @@ func getReplicationControllersForLabels(c client.ReplicationControllerInterface,
return
list
}
func
getPodStatusForReplicationController
(
c
client
.
PodInterface
,
controller
*
api
.
ReplicationController
)
(
running
,
waiting
,
terminat
ed
int
,
err
error
)
{
func
getPodStatusForReplicationController
(
c
client
.
PodInterface
,
controller
*
api
.
ReplicationController
)
(
running
,
waiting
,
succeeded
,
fail
ed
int
,
err
error
)
{
rcPods
,
err
:=
c
.
List
(
labels
.
SelectorFromSet
(
controller
.
DesiredState
.
ReplicaSelector
))
if
err
!=
nil
{
return
...
...
@@ -224,10 +224,12 @@ func getPodStatusForReplicationController(c client.PodInterface, controller *api
for
_
,
pod
:=
range
rcPods
.
Items
{
if
pod
.
CurrentState
.
Status
==
api
.
PodRunning
{
running
++
}
else
if
pod
.
CurrentState
.
Status
==
api
.
Pod
Wait
ing
{
}
else
if
pod
.
CurrentState
.
Status
==
api
.
Pod
Pend
ing
{
waiting
++
}
else
if
pod
.
CurrentState
.
Status
==
api
.
PodTerminated
{
terminated
++
}
else
if
pod
.
CurrentState
.
Status
==
api
.
PodSucceeded
{
succeeded
++
}
else
if
pod
.
CurrentState
.
Status
==
api
.
PodFailed
{
failed
++
}
}
return
...
...
pkg/registry/etcd/etcd.go
View file @
f4cffdc7
...
...
@@ -183,7 +183,7 @@ func makeContainerKey(machine string) string {
// CreatePod creates a pod based on a specification.
func
(
r
*
Registry
)
CreatePod
(
ctx
api
.
Context
,
pod
*
api
.
Pod
)
error
{
// Set current status to "Waiting".
pod
.
CurrentState
.
Status
=
api
.
Pod
Wait
ing
pod
.
CurrentState
.
Status
=
api
.
Pod
Pend
ing
pod
.
CurrentState
.
Host
=
""
// DesiredState.Host == "" is a signal to the scheduler that this pod needs scheduling.
pod
.
DesiredState
.
Status
=
api
.
PodRunning
...
...
pkg/registry/pod/rest.go
View file @
f4cffdc7
...
...
@@ -267,9 +267,9 @@ func getInstanceIPFromCloud(cloud cloudprovider.Interface, host string) string {
return
addr
.
String
()
}
func
getPodStatus
(
pod
*
api
.
Pod
,
minions
client
.
MinionInterface
)
(
api
.
Pod
Status
,
error
)
{
func
getPodStatus
(
pod
*
api
.
Pod
,
minions
client
.
MinionInterface
)
(
api
.
Pod
Condition
,
error
)
{
if
pod
.
CurrentState
.
Host
==
""
{
return
api
.
Pod
Wait
ing
,
nil
return
api
.
Pod
Pend
ing
,
nil
}
if
minions
!=
nil
{
res
,
err
:=
minions
.
List
()
...
...
@@ -285,13 +285,13 @@ func getPodStatus(pod *api.Pod, minions client.MinionInterface) (api.PodStatus,
}
}
if
!
found
{
return
api
.
Pod
Terminat
ed
,
nil
return
api
.
Pod
Fail
ed
,
nil
}
}
else
{
glog
.
Errorf
(
"Unexpected missing minion interface, status may be in-accurate"
)
}
if
pod
.
CurrentState
.
Info
==
nil
{
return
api
.
Pod
Wait
ing
,
nil
return
api
.
Pod
Pend
ing
,
nil
}
running
:=
0
stopped
:=
0
...
...
@@ -313,10 +313,10 @@ func getPodStatus(pod *api.Pod, minions client.MinionInterface) (api.PodStatus,
case
running
>
0
&&
unknown
==
0
:
return
api
.
PodRunning
,
nil
case
running
==
0
&&
stopped
>
0
&&
unknown
==
0
:
return
api
.
Pod
Terminat
ed
,
nil
return
api
.
Pod
Fail
ed
,
nil
case
running
==
0
&&
stopped
==
0
&&
unknown
>
0
:
return
api
.
Pod
Wait
ing
,
nil
return
api
.
Pod
Pend
ing
,
nil
default
:
return
api
.
Pod
Wait
ing
,
nil
return
api
.
Pod
Pend
ing
,
nil
}
}
pkg/registry/pod/rest_test.go
View file @
f4cffdc7
...
...
@@ -418,10 +418,10 @@ func TestMakePodStatus(t *testing.T) {
tests
:=
[]
struct
{
pod
*
api
.
Pod
status
api
.
Pod
Status
status
api
.
Pod
Condition
test
string
}{
{
&
api
.
Pod
{
DesiredState
:
desiredState
,
CurrentState
:
currentState
},
api
.
Pod
Wait
ing
,
"waiting"
},
{
&
api
.
Pod
{
DesiredState
:
desiredState
,
CurrentState
:
currentState
},
api
.
Pod
Pend
ing
,
"waiting"
},
{
&
api
.
Pod
{
DesiredState
:
desiredState
,
...
...
@@ -429,7 +429,7 @@ func TestMakePodStatus(t *testing.T) {
Host
:
"machine-2"
,
},
},
api
.
Pod
Terminat
ed
,
api
.
Pod
Fail
ed
,
"no info, but bad machine"
,
},
{
...
...
@@ -457,7 +457,7 @@ func TestMakePodStatus(t *testing.T) {
Host
:
"machine-two"
,
},
},
api
.
Pod
Terminat
ed
,
api
.
Pod
Fail
ed
,
"all running but minion is missing"
,
},
{
...
...
@@ -471,7 +471,7 @@ func TestMakePodStatus(t *testing.T) {
Host
:
"machine"
,
},
},
api
.
Pod
Terminat
ed
,
api
.
Pod
Fail
ed
,
"all stopped"
,
},
{
...
...
@@ -485,7 +485,7 @@ func TestMakePodStatus(t *testing.T) {
Host
:
"machine-two"
,
},
},
api
.
Pod
Terminat
ed
,
api
.
Pod
Fail
ed
,
"all stopped but minion missing"
,
},
{
...
...
@@ -512,7 +512,7 @@ func TestMakePodStatus(t *testing.T) {
Host
:
"machine"
,
},
},
api
.
Pod
Wait
ing
,
api
.
Pod
Pend
ing
,
"mixed state #2"
,
},
}
...
...
plugin/pkg/scheduler/scheduler.go
View file @
f4cffdc7
...
...
@@ -68,7 +68,7 @@ func (s *Scheduler) scheduleOne() {
pod
:=
s
.
config
.
NextPod
()
dest
,
err
:=
s
.
config
.
Algorithm
.
Schedule
(
*
pod
,
s
.
config
.
MinionLister
)
if
err
!=
nil
{
record
.
Eventf
(
pod
,
""
,
string
(
api
.
Pod
Wait
ing
),
"failedScheduling"
,
"Error scheduling: %v"
,
err
)
record
.
Eventf
(
pod
,
""
,
string
(
api
.
Pod
Pend
ing
),
"failedScheduling"
,
"Error scheduling: %v"
,
err
)
s
.
config
.
Error
(
pod
,
err
)
return
}
...
...
@@ -78,9 +78,9 @@ func (s *Scheduler) scheduleOne() {
Host
:
dest
,
}
if
err
:=
s
.
config
.
Binder
.
Bind
(
b
);
err
!=
nil
{
record
.
Eventf
(
pod
,
""
,
string
(
api
.
Pod
Wait
ing
),
"failedScheduling"
,
"Binding rejected: %v"
,
err
)
record
.
Eventf
(
pod
,
""
,
string
(
api
.
Pod
Pend
ing
),
"failedScheduling"
,
"Binding rejected: %v"
,
err
)
s
.
config
.
Error
(
pod
,
err
)
return
}
record
.
Eventf
(
pod
,
""
,
string
(
api
.
Pod
Wait
ing
),
"scheduled"
,
"Successfully assigned %v to %v"
,
pod
.
Name
,
dest
)
record
.
Eventf
(
pod
,
""
,
string
(
api
.
Pod
Pend
ing
),
"scheduled"
,
"Successfully assigned %v to %v"
,
pod
.
Name
,
dest
)
}
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