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
52af7928
Commit
52af7928
authored
May 08, 2015
by
Yifan Gu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubelet: Fix racy kubelet tests.
Add fakePodWorkders to run syncPod() in serial for testing.
parent
5fcf5911
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
1 deletion
+52
-1
fake_pod_workers.go
pkg/kubelet/fake_pod_workers.go
+45
-0
kubelet.go
pkg/kubelet/kubelet.go
+1
-1
kubelet_test.go
pkg/kubelet/kubelet_test.go
+0
-0
pod_workers.go
pkg/kubelet/pod_workers.go
+6
-0
No files found.
pkg/kubelet/fake_pod_workers.go
0 → 100644
View file @
52af7928
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
kubelet
import
(
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kubecontainer
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
)
// fakePodWorkers runs sync pod function in serial, so we can have
// deterministic behaviour in testing.
type
fakePodWorkers
struct
{
syncPodFn
syncPodFnType
runtimeCache
kubecontainer
.
RuntimeCache
t
*
testing
.
T
}
func
(
f
*
fakePodWorkers
)
UpdatePod
(
pod
*
api
.
Pod
,
mirrorPod
*
api
.
Pod
,
updateComplete
func
())
{
pods
,
err
:=
f
.
runtimeCache
.
GetPods
()
if
err
!=
nil
{
f
.
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
if
err
:=
f
.
syncPodFn
(
pod
,
mirrorPod
,
kubecontainer
.
Pods
(
pods
)
.
FindPodByID
(
pod
.
UID
));
err
!=
nil
{
f
.
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
}
func
(
f
*
fakePodWorkers
)
ForgetNonExistingPodWorkers
(
desiredPods
map
[
types
.
UID
]
empty
)
{}
pkg/kubelet/kubelet.go
View file @
52af7928
...
@@ -332,7 +332,7 @@ type Kubelet struct {
...
@@ -332,7 +332,7 @@ type Kubelet struct {
runtimeCache
kubecontainer
.
RuntimeCache
runtimeCache
kubecontainer
.
RuntimeCache
kubeClient
client
.
Interface
kubeClient
client
.
Interface
rootDirectory
string
rootDirectory
string
podWorkers
*
p
odWorkers
podWorkers
P
odWorkers
resyncInterval
time
.
Duration
resyncInterval
time
.
Duration
sourcesReady
SourcesReadyFn
sourcesReady
SourcesReadyFn
...
...
pkg/kubelet/kubelet_test.go
View file @
52af7928
This diff is collapsed.
Click to expand it.
pkg/kubelet/pod_workers.go
View file @
52af7928
...
@@ -28,6 +28,12 @@ import (
...
@@ -28,6 +28,12 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
)
)
// PodWorkers is an abstract interface for testability.
type
PodWorkers
interface
{
UpdatePod
(
pod
*
api
.
Pod
,
mirrorPod
*
api
.
Pod
,
updateComplete
func
())
ForgetNonExistingPodWorkers
(
desiredPods
map
[
types
.
UID
]
empty
)
}
type
syncPodFnType
func
(
*
api
.
Pod
,
*
api
.
Pod
,
kubecontainer
.
Pod
)
error
type
syncPodFnType
func
(
*
api
.
Pod
,
*
api
.
Pod
,
kubecontainer
.
Pod
)
error
type
podWorkers
struct
{
type
podWorkers
struct
{
...
...
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