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
4b990d12
Commit
4b990d12
authored
Jun 20, 2015
by
Prashanth Balasubramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't flood the status manager with updates from multi-container pods
parent
ff0546da
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
1 deletion
+76
-1
manager.go
pkg/kubelet/dockertools/manager.go
+4
-1
manager_test.go
pkg/kubelet/dockertools/manager_test.go
+58
-0
types.go
pkg/kubelet/types/types.go
+14
-0
No files found.
pkg/kubelet/dockertools/manager.go
View file @
4b990d12
...
...
@@ -25,6 +25,7 @@ import (
"os"
"os/exec"
"path"
"sort"
"strconv"
"strings"
"sync"
...
...
@@ -470,7 +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
.
Sort
(
kubeletTypes
.
SortedContainerStatuses
(
podStatus
.
ContainerStatuses
))
return
&
podStatus
,
nil
}
...
...
pkg/kubelet/dockertools/manager_test.go
View file @
4b990d12
...
...
@@ -1992,3 +1992,61 @@ func TestSyncPodWithTerminationLog(t *testing.T) {
t
.
Errorf
(
"Unexpected container path: %s"
,
parts
[
1
])
}
}
func
TestGetPodStatusSortedContainers
(
t
*
testing
.
T
)
{
dm
,
fakeDocker
:=
newTestDockerManager
()
dockerInspect
:=
map
[
string
]
*
docker
.
Container
{}
dockerList
:=
[]
docker
.
APIContainers
{}
specContainerList
:=
[]
api
.
Container
{}
expectedOrder
:=
[]
string
{}
numContainers
:=
10
podName
:=
"foo"
podNs
:=
"test"
podUID
:=
"uid1"
fakeConfig
:=
&
docker
.
Config
{
Image
:
"some:latest"
,
}
for
i
:=
0
;
i
<
numContainers
;
i
++
{
id
:=
fmt
.
Sprintf
(
"%v"
,
i
)
containerName
:=
fmt
.
Sprintf
(
"%vcontainer"
,
id
)
expectedOrder
=
append
(
expectedOrder
,
containerName
)
dockerInspect
[
id
]
=
&
docker
.
Container
{
ID
:
id
,
Name
:
containerName
,
Config
:
fakeConfig
,
Image
:
fmt
.
Sprintf
(
"%vimageid"
,
id
),
}
dockerList
=
append
(
dockerList
,
docker
.
APIContainers
{
ID
:
id
,
Names
:
[]
string
{
fmt
.
Sprintf
(
"/k8s_%v_%v_%v_%v_42"
,
containerName
,
podName
,
podNs
,
podUID
)},
})
specContainerList
=
append
(
specContainerList
,
api
.
Container
{
Name
:
containerName
})
}
fakeDocker
.
ContainerMap
=
dockerInspect
fakeDocker
.
ContainerList
=
dockerList
fakeDocker
.
ClearCalls
()
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
podUID
),
Name
:
podName
,
Namespace
:
podNs
,
},
Spec
:
api
.
PodSpec
{
Containers
:
specContainerList
,
},
}
for
i
:=
0
;
i
<
5
;
i
++
{
status
,
err
:=
dm
.
GetPodStatus
(
pod
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error %v"
,
err
)
}
for
i
,
c
:=
range
status
.
ContainerStatuses
{
if
expectedOrder
[
i
]
!=
c
.
Name
{
t
.
Fatalf
(
"Container status not sorted, expected %v at index %d, but found %v"
,
expectedOrder
[
i
],
i
,
c
.
Name
)
}
}
}
}
pkg/kubelet/types/types.go
View file @
4b990d12
...
...
@@ -19,8 +19,12 @@ package types
import
(
"net/http"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
// TODO: Reconcile custom types in kubelet/types and this subpackage
// DockerID is an ID of docker container. It is a type to make it clear when we're working with docker container Ids
type
DockerID
string
...
...
@@ -56,3 +60,13 @@ func (t *Timestamp) Get() time.Time {
func
(
t
*
Timestamp
)
GetString
()
string
{
return
t
.
time
.
Format
(
time
.
RFC3339Nano
)
}
// A type to help sort container statuses based on container names.
type
SortedContainerStatuses
[]
api
.
ContainerStatus
func
(
s
SortedContainerStatuses
)
Len
()
int
{
return
len
(
s
)
}
func
(
s
SortedContainerStatuses
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
func
(
s
SortedContainerStatuses
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
.
Name
<
s
[
j
]
.
Name
}
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