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
af175cc0
Commit
af175cc0
authored
Jun 22, 2015
by
Prashanth Balasubramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a pod status equality method to the status manager.
parent
5f61392e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
4 deletions
+51
-4
runtime.go
pkg/kubelet/container/runtime.go
+2
-1
manager.go
pkg/kubelet/dockertools/manager.go
+3
-2
status_manager.go
pkg/kubelet/status_manager.go
+13
-1
status_manager_test.go
pkg/kubelet/status_manager_test.go
+33
-0
No files found.
pkg/kubelet/container/runtime.go
View file @
af175cc0
...
...
@@ -57,7 +57,8 @@ type Runtime interface {
// KillPod kills all the containers of a pod.
KillPod
(
pod
Pod
)
error
// GetPodStatus retrieves the status of the pod, including the information of
// all containers in the pod.
// all containers in the pod. Clients of this interface assume the containers
// statuses in a pod always have a deterministic ordering (eg: sorted by name).
GetPodStatus
(
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
// PullImage pulls an image from the network to local storage using the supplied
// secrets if necessary.
...
...
pkg/kubelet/dockertools/manager.go
View file @
af175cc0
...
...
@@ -471,8 +471,9 @@ func (dm *DockerManager) GetPodStatus(pod *api.Pod) (*api.PodStatus, error) {
}
podStatus
.
ContainerStatuses
=
append
(
podStatus
.
ContainerStatuses
,
*
status
)
}
// TODO: Move this to a custom equals method on the pod status. A container manager
// shouldn't have to guarantee order.
// Sort the container statuses since clients of this interface expect the list
// of containers in a pod to behave like the output of `docker list`, which has a
// deterministic order.
sort
.
Sort
(
kubeletTypes
.
SortedContainerStatuses
(
podStatus
.
ContainerStatuses
))
return
&
podStatus
,
nil
}
...
...
pkg/kubelet/status_manager.go
View file @
af175cc0
...
...
@@ -19,11 +19,13 @@ package kubelet
import
(
"fmt"
"reflect"
"sort"
"sync"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
kubecontainer
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
kubeletTypes
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/golang/glog"
)
...
...
@@ -51,6 +53,16 @@ func newStatusManager(kubeClient client.Interface) *statusManager {
}
}
// isStatusEqual returns true if the given pod statuses are equal, false otherwise.
// This method sorts container statuses so order does not affect equality.
func
isStatusEqual
(
oldStatus
,
status
*
api
.
PodStatus
)
bool
{
sort
.
Sort
(
kubeletTypes
.
SortedContainerStatuses
(
status
.
ContainerStatuses
))
sort
.
Sort
(
kubeletTypes
.
SortedContainerStatuses
(
oldStatus
.
ContainerStatuses
))
// TODO: More sophisticated equality checking.
return
reflect
.
DeepEqual
(
status
,
oldStatus
)
}
func
(
s
*
statusManager
)
Start
()
{
// syncBatch blocks when no updates are available, we can run it in a tight loop.
glog
.
Info
(
"Starting to sync pod status with apiserver"
)
...
...
@@ -102,7 +114,7 @@ func (s *statusManager) SetPodStatus(pod *api.Pod, status api.PodStatus) {
// Currently this routine is not called for the same pod from multiple
// workers and/or the kubelet but dropping the lock before sending the
// status down the channel feels like an easy way to get a bullet in foot.
if
!
found
||
!
reflect
.
DeepEqual
(
oldStatus
,
status
)
{
if
!
found
||
!
isStatusEqual
(
&
oldStatus
,
&
status
)
{
s
.
podStatuses
[
podFullName
]
=
status
s
.
podStatusChannel
<-
podStatusSyncRequest
{
pod
,
status
}
}
else
{
...
...
pkg/kubelet/status_manager_test.go
View file @
af175cc0
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
kubelet
import
(
"fmt"
"math/rand"
"strconv"
"testing"
...
...
@@ -159,3 +160,35 @@ func TestSyncBatch(t *testing.T) {
}
verifyActions
(
t
,
syncer
.
kubeClient
,
[]
string
{
"get-pod"
,
"update-status-pod"
})
}
// shuffle returns a new shuffled list of container statuses.
func
shuffle
(
statuses
[]
api
.
ContainerStatus
)
[]
api
.
ContainerStatus
{
numStatuses
:=
len
(
statuses
)
randIndexes
:=
rand
.
Perm
(
numStatuses
)
shuffled
:=
make
([]
api
.
ContainerStatus
,
numStatuses
)
for
i
:=
0
;
i
<
numStatuses
;
i
++
{
shuffled
[
i
]
=
statuses
[
randIndexes
[
i
]]
}
return
shuffled
}
func
TestStatusEquality
(
t
*
testing
.
T
)
{
containerStatus
:=
[]
api
.
ContainerStatus
{}
for
i
:=
0
;
i
<
10
;
i
++
{
s
:=
api
.
ContainerStatus
{
Name
:
fmt
.
Sprintf
(
"container%d"
,
i
),
}
containerStatus
=
append
(
containerStatus
,
s
)
}
podStatus
:=
api
.
PodStatus
{
ContainerStatuses
:
containerStatus
,
}
for
i
:=
0
;
i
<
10
;
i
++
{
oldPodStatus
:=
api
.
PodStatus
{
ContainerStatuses
:
shuffle
(
podStatus
.
ContainerStatuses
),
}
if
!
isStatusEqual
(
&
oldPodStatus
,
&
podStatus
)
{
t
.
Fatalf
(
"Order of container statuses should not affect equality."
)
}
}
}
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