mirror of https://github.com/k3s-io/k3s
Move test-only files to test-only packages
parent
69f4ac3362
commit
7b6d843309
|
@ -46,9 +46,9 @@ import (
|
|||
endpointcontroller "k8s.io/kubernetes/pkg/controller/endpoint"
|
||||
nodecontroller "k8s.io/kubernetes/pkg/controller/node"
|
||||
replicationcontroller "k8s.io/kubernetes/pkg/controller/replication"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
|
@ -203,7 +203,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
|
|||
nodeController := nodecontroller.NewNodeController(nil, clientset, 5*time.Minute, util.NewFakeAlwaysRateLimiter(), util.NewFakeAlwaysRateLimiter(),
|
||||
40*time.Second, 60*time.Second, 5*time.Second, nil, false)
|
||||
nodeController.Run(5 * time.Second)
|
||||
cadvisorInterface := new(cadvisor.Fake)
|
||||
cadvisorInterface := new(cadvisortest.Fake)
|
||||
|
||||
// Kubelet (localhost)
|
||||
testRootDir := integration.MakeTempDirOrDie("kubelet_integ_1.", "")
|
||||
|
@ -225,7 +225,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
|
|||
cadvisorInterface,
|
||||
configFilePath,
|
||||
nil,
|
||||
kubecontainer.FakeOS{},
|
||||
containertest.FakeOS{},
|
||||
1*time.Second, /* FileCheckFrequency */
|
||||
1*time.Second, /* HTTPCheckFrequency */
|
||||
10*time.Second, /* MinimumGCAge */
|
||||
|
@ -257,7 +257,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
|
|||
cadvisorInterface,
|
||||
"",
|
||||
nil,
|
||||
kubecontainer.FakeOS{},
|
||||
containertest.FakeOS{},
|
||||
1*time.Second, /* FileCheckFrequency */
|
||||
1*time.Second, /* HTTPCheckFrequency */
|
||||
10*time.Second, /* MinimumGCAge */
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/client/record"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||
"k8s.io/kubernetes/pkg/kubemark"
|
||||
|
@ -95,7 +95,7 @@ func main() {
|
|||
}
|
||||
|
||||
if config.Morph == "kubelet" {
|
||||
cadvisorInterface := new(cadvisor.Fake)
|
||||
cadvisorInterface := new(cadvisortest.Fake)
|
||||
containerManager := cm.NewStubContainerManager()
|
||||
|
||||
fakeDockerClient := dockertools.NewFakeDockerClient()
|
||||
|
|
|
@ -14,19 +14,20 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cadvisor
|
||||
package testing
|
||||
|
||||
import (
|
||||
"github.com/google/cadvisor/events"
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
)
|
||||
|
||||
// Fake cAdvisor implementation.
|
||||
type Fake struct {
|
||||
}
|
||||
|
||||
var _ Interface = new(Fake)
|
||||
var _ cadvisor.Interface = new(Fake)
|
||||
|
||||
func (c *Fake) Start() error {
|
||||
return nil
|
|
@ -14,20 +14,21 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cadvisor
|
||||
package testing
|
||||
|
||||
import (
|
||||
"github.com/google/cadvisor/events"
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
)
|
||||
|
||||
type Mock struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
var _ Interface = new(Mock)
|
||||
var _ cadvisor.Interface = new(Mock)
|
||||
|
||||
func (c *Mock) Start() error {
|
||||
args := c.Called()
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
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 container
|
||||
|
||||
// TestRunTimeCache embeds runtimeCache with some additional methods for
|
||||
// testing.
|
||||
type TestRuntimeCache struct {
|
||||
runtimeCache
|
||||
}
|
||||
|
||||
func (r *TestRuntimeCache) UpdateCacheWithLock() error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return r.updateCache()
|
||||
}
|
||||
|
||||
func (r *TestRuntimeCache) GetCachedPods() []*Pod {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return r.pods
|
||||
}
|
||||
|
||||
func NewTestRuntimeCache(getter podsGetter) *TestRuntimeCache {
|
||||
c, _ := NewRuntimeCache(getter)
|
||||
return &TestRuntimeCache{*c.(*runtimeCache)}
|
||||
}
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package container
|
||||
package container_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -24,6 +24,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/record"
|
||||
. "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
ctest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
|
@ -101,7 +103,7 @@ func TestPuller(t *testing.T) {
|
|||
fakeClock := util.NewFakeClock(time.Now())
|
||||
backOff.Clock = fakeClock
|
||||
|
||||
fakeRuntime := &FakeRuntime{}
|
||||
fakeRuntime := &ctest.FakeRuntime{}
|
||||
fakeRecorder := &record.FakeRecorder{}
|
||||
puller := NewImagePuller(fakeRecorder, fakeRuntime, backOff)
|
||||
|
||||
|
|
|
@ -39,17 +39,3 @@ func (RealOS) Mkdir(path string, perm os.FileMode) error {
|
|||
func (RealOS) Symlink(oldname string, newname string) error {
|
||||
return os.Symlink(oldname, newname)
|
||||
}
|
||||
|
||||
// FakeOS mocks out certain OS calls to avoid perturbing the filesystem
|
||||
// on the test machine.
|
||||
type FakeOS struct{}
|
||||
|
||||
// MkDir is a fake call that just returns nil.
|
||||
func (FakeOS) Mkdir(path string, perm os.FileMode) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Symlink is a fake call that just returns nil.
|
||||
func (FakeOS) Symlink(oldname string, newname string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -14,42 +14,22 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package container
|
||||
package container_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
ctest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
)
|
||||
|
||||
// testRunTimeCache embeds runtimeCache with some additional methods for
|
||||
// testing.
|
||||
type testRuntimeCache struct {
|
||||
runtimeCache
|
||||
}
|
||||
|
||||
func (r *testRuntimeCache) updateCacheWithLock() error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return r.updateCache()
|
||||
}
|
||||
|
||||
func (r *testRuntimeCache) getCachedPods() []*Pod {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return r.pods
|
||||
}
|
||||
|
||||
func newTestRuntimeCache(getter podsGetter) *testRuntimeCache {
|
||||
c, _ := NewRuntimeCache(getter)
|
||||
return &testRuntimeCache{*c.(*runtimeCache)}
|
||||
}
|
||||
|
||||
func TestGetPods(t *testing.T) {
|
||||
runtime := &FakeRuntime{}
|
||||
runtime := &ctest.FakeRuntime{}
|
||||
expected := []*Pod{{ID: "1111"}, {ID: "2222"}, {ID: "3333"}}
|
||||
runtime.PodList = expected
|
||||
cache := newTestRuntimeCache(runtime)
|
||||
cache := NewTestRuntimeCache(runtime)
|
||||
actual, err := cache.GetPods()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
|
@ -60,13 +40,13 @@ func TestGetPods(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestForceUpdateIfOlder(t *testing.T) {
|
||||
runtime := &FakeRuntime{}
|
||||
cache := newTestRuntimeCache(runtime)
|
||||
runtime := &ctest.FakeRuntime{}
|
||||
cache := NewTestRuntimeCache(runtime)
|
||||
|
||||
// Cache old pods.
|
||||
oldpods := []*Pod{{ID: "1111"}}
|
||||
runtime.PodList = oldpods
|
||||
cache.updateCacheWithLock()
|
||||
cache.UpdateCacheWithLock()
|
||||
|
||||
// Update the runtime to new pods.
|
||||
newpods := []*Pod{{ID: "1111"}, {ID: "2222"}, {ID: "3333"}}
|
||||
|
@ -74,14 +54,14 @@ func TestForceUpdateIfOlder(t *testing.T) {
|
|||
|
||||
// An older timestamp should not force an update.
|
||||
cache.ForceUpdateIfOlder(time.Now().Add(-20 * time.Minute))
|
||||
actual := cache.getCachedPods()
|
||||
actual := cache.GetCachedPods()
|
||||
if !reflect.DeepEqual(oldpods, actual) {
|
||||
t.Errorf("expected %#v, got %#v", oldpods, actual)
|
||||
}
|
||||
|
||||
// A newer timestamp should force an update.
|
||||
cache.ForceUpdateIfOlder(time.Now().Add(20 * time.Second))
|
||||
actual = cache.getCachedPods()
|
||||
actual = cache.GetCachedPods()
|
||||
if !reflect.DeepEqual(newpods, actual) {
|
||||
t.Errorf("expected %#v, got %#v", newpods, actual)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package container
|
||||
package container_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -24,6 +24,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/record"
|
||||
. "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
ctest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
|
@ -101,7 +103,7 @@ func TestSerializedPuller(t *testing.T) {
|
|||
fakeClock := util.NewFakeClock(time.Now())
|
||||
backOff.Clock = fakeClock
|
||||
|
||||
fakeRuntime := &FakeRuntime{}
|
||||
fakeRuntime := &ctest.FakeRuntime{}
|
||||
fakeRecorder := &record.FakeRecorder{}
|
||||
puller := NewSerializedImagePuller(fakeRecorder, fakeRuntime, backOff)
|
||||
|
||||
|
|
|
@ -14,31 +14,32 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package container
|
||||
package testing
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
)
|
||||
|
||||
type fakeCache struct {
|
||||
runtime Runtime
|
||||
runtime container.Runtime
|
||||
}
|
||||
|
||||
func NewFakeCache(runtime Runtime) Cache {
|
||||
func NewFakeCache(runtime container.Runtime) container.Cache {
|
||||
return &fakeCache{runtime: runtime}
|
||||
}
|
||||
|
||||
func (c *fakeCache) Get(id types.UID) (*PodStatus, error) {
|
||||
func (c *fakeCache) Get(id types.UID) (*container.PodStatus, error) {
|
||||
return c.runtime.GetPodStatus(id, "", "")
|
||||
}
|
||||
|
||||
func (c *fakeCache) GetNewerThan(id types.UID, minTime time.Time) (*PodStatus, error) {
|
||||
func (c *fakeCache) GetNewerThan(id types.UID, minTime time.Time) (*container.PodStatus, error) {
|
||||
return c.Get(id)
|
||||
}
|
||||
|
||||
func (c *fakeCache) Set(id types.UID, status *PodStatus, err error, timestamp time.Time) {
|
||||
func (c *fakeCache) Set(id types.UID, status *container.PodStatus, err error, timestamp time.Time) {
|
||||
}
|
||||
|
||||
func (c *fakeCache) Delete(id types.UID) {
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package container
|
||||
package testing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -24,6 +24,7 @@ import (
|
|||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
. "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
|
@ -70,6 +71,10 @@ func (fv *FakeVersion) Compare(other string) (int, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
type podsGetter interface {
|
||||
GetPods(bool) ([]*Pod, error)
|
||||
}
|
||||
|
||||
type FakeRuntimeCache struct {
|
||||
getter podsGetter
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
Copyright 2016 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 testing
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// FakeOS mocks out certain OS calls to avoid perturbing the filesystem
|
||||
// on the test machine.
|
||||
type FakeOS struct{}
|
||||
|
||||
// Mkdir is a fake call that just returns nil.
|
||||
func (FakeOS) Mkdir(path string, perm os.FileMode) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Symlink is a fake call that just returns nil.
|
||||
func (FakeOS) Symlink(oldname string, newname string) error {
|
||||
return nil
|
||||
}
|
|
@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package container
|
||||
package testing
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/stretchr/testify/mock"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
. "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
|
@ -23,7 +23,7 @@ import (
|
|||
cadvisorapi "github.com/google/cadvisor/info/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
|
||||
)
|
||||
|
||||
func testPolicy() DiskSpacePolicy {
|
||||
|
@ -33,10 +33,10 @@ func testPolicy() DiskSpacePolicy {
|
|||
}
|
||||
}
|
||||
|
||||
func setUp(t *testing.T) (*assert.Assertions, DiskSpacePolicy, *cadvisor.Mock) {
|
||||
func setUp(t *testing.T) (*assert.Assertions, DiskSpacePolicy, *cadvisortest.Mock) {
|
||||
assert := assert.New(t)
|
||||
policy := testPolicy()
|
||||
c := new(cadvisor.Mock)
|
||||
c := new(cadvisortest.Mock)
|
||||
return assert, policy, c
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ func Test_getFsInfo(t *testing.T) {
|
|||
assert.NoError(err)
|
||||
|
||||
// Threshold case
|
||||
mockCadvisor = new(cadvisor.Mock)
|
||||
mockCadvisor = new(cadvisortest.Mock)
|
||||
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
|
||||
Usage: 9 * mb,
|
||||
Capacity: 100 * mb,
|
||||
|
@ -273,7 +273,7 @@ func Test_getFsInfo(t *testing.T) {
|
|||
assert.NoError(err)
|
||||
|
||||
// Capacity error case
|
||||
mockCadvisor = new(cadvisor.Mock)
|
||||
mockCadvisor = new(cadvisortest.Mock)
|
||||
mockCadvisor.On("RootFsInfo").Return(cadvisorapi.FsInfo{
|
||||
Usage: 9 * mb,
|
||||
Capacity: 0,
|
||||
|
|
|
@ -33,7 +33,9 @@ import (
|
|||
"k8s.io/kubernetes/pkg/client/record"
|
||||
"k8s.io/kubernetes/pkg/credentialprovider"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
nettest "k8s.io/kubernetes/pkg/kubelet/network/testing"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
hashutil "k8s.io/kubernetes/pkg/util/hash"
|
||||
|
@ -703,9 +705,9 @@ func TestFindContainersByPod(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fakeClient := &FakeDockerClient{}
|
||||
np, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
|
||||
np, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil))
|
||||
// image back-off is set to nil, this test should not pull images
|
||||
containerManager := NewFakeDockerManager(fakeClient, &record.FakeRecorder{}, nil, nil, &cadvisorapi.MachineInfo{}, kubetypes.PodInfraContainerImage, 0, 0, "", kubecontainer.FakeOS{}, np, nil, nil, nil)
|
||||
containerManager := NewFakeDockerManager(fakeClient, &record.FakeRecorder{}, nil, nil, &cadvisorapi.MachineInfo{}, kubetypes.PodInfraContainerImage, 0, 0, "", containertest.FakeOS{}, np, nil, nil, nil)
|
||||
for i, test := range tests {
|
||||
fakeClient.ContainerList = test.containerList
|
||||
fakeClient.ExitedContainerList = test.exitedContainerList
|
||||
|
|
|
@ -36,7 +36,9 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/client/record"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
nettest "k8s.io/kubernetes/pkg/kubelet/network/testing"
|
||||
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
|
@ -86,7 +88,7 @@ func newTestDockerManagerWithHTTPClient(fakeHTTPClient *fakeHTTP) (*DockerManage
|
|||
fakeDocker := NewFakeDockerClient()
|
||||
fakeRecorder := &record.FakeRecorder{}
|
||||
containerRefManager := kubecontainer.NewRefManager()
|
||||
networkPlugin, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
|
||||
networkPlugin, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil))
|
||||
dockerManager := NewFakeDockerManager(
|
||||
fakeDocker,
|
||||
fakeRecorder,
|
||||
|
@ -95,7 +97,7 @@ func newTestDockerManagerWithHTTPClient(fakeHTTPClient *fakeHTTP) (*DockerManage
|
|||
&cadvisorapi.MachineInfo{},
|
||||
kubetypes.PodInfraContainerImage,
|
||||
0, 0, "",
|
||||
kubecontainer.FakeOS{},
|
||||
containertest.FakeOS{},
|
||||
networkPlugin,
|
||||
&fakeRuntimeHelper{},
|
||||
fakeHTTPClient,
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
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 (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
)
|
||||
|
||||
// fakePodWorkers runs sync pod function in serial, so we can have
|
||||
// deterministic behaviour in testing.
|
||||
type fakePodWorkers struct {
|
||||
syncPodFn syncPodFnType
|
||||
cache kubecontainer.Cache
|
||||
t TestingInterface
|
||||
}
|
||||
|
||||
func (f *fakePodWorkers) UpdatePod(pod *api.Pod, mirrorPod *api.Pod, updateType kubetypes.SyncPodType, updateComplete func()) {
|
||||
status, err := f.cache.Get(pod.UID)
|
||||
if err != nil {
|
||||
f.t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
if err := f.syncPodFn(pod, mirrorPod, status, kubetypes.SyncPodUpdate); err != nil {
|
||||
f.t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fakePodWorkers) ForgetNonExistingPodWorkers(desiredPods map[types.UID]empty) {}
|
||||
|
||||
func (f *fakePodWorkers) ForgetWorker(uid types.UID) {}
|
||||
|
||||
type TestingInterface interface {
|
||||
Errorf(format string, args ...interface{})
|
||||
}
|
|
@ -25,16 +25,17 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/kubernetes/pkg/client/record"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
var zero time.Time
|
||||
|
||||
func newRealImageManager(policy ImageGCPolicy) (*realImageManager, *container.FakeRuntime, *cadvisor.Mock) {
|
||||
fakeRuntime := &container.FakeRuntime{}
|
||||
mockCadvisor := new(cadvisor.Mock)
|
||||
func newRealImageManager(policy ImageGCPolicy) (*realImageManager, *containertest.FakeRuntime, *cadvisortest.Mock) {
|
||||
fakeRuntime := &containertest.FakeRuntime{}
|
||||
mockCadvisor := new(cadvisortest.Mock)
|
||||
return &realImageManager{
|
||||
runtime: fakeRuntime,
|
||||
policy: policy,
|
||||
|
@ -407,8 +408,8 @@ func TestGarbageCollectImageNotOldEnough(t *testing.T) {
|
|||
LowThresholdPercent: 80,
|
||||
MinAge: time.Minute * 1,
|
||||
}
|
||||
fakeRuntime := &container.FakeRuntime{}
|
||||
mockCadvisor := new(cadvisor.Mock)
|
||||
fakeRuntime := &containertest.FakeRuntime{}
|
||||
mockCadvisor := new(cadvisortest.Mock)
|
||||
manager := &realImageManager{
|
||||
runtime: fakeRuntime,
|
||||
policy: policy,
|
||||
|
|
|
@ -43,15 +43,17 @@ import (
|
|||
"k8s.io/kubernetes/pkg/client/record"
|
||||
"k8s.io/kubernetes/pkg/client/testing/core"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
"k8s.io/kubernetes/pkg/kubelet/container"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
nettest "k8s.io/kubernetes/pkg/kubelet/network/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/pleg"
|
||||
kubepod "k8s.io/kubernetes/pkg/kubelet/pod"
|
||||
"k8s.io/kubernetes/pkg/kubelet/prober"
|
||||
podtest "k8s.io/kubernetes/pkg/kubelet/pod/testing"
|
||||
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
|
||||
probetest "k8s.io/kubernetes/pkg/kubelet/prober/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/status"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util/queue"
|
||||
|
@ -89,16 +91,16 @@ func (f *fakeHTTP) Get(url string) (*http.Response, error) {
|
|||
|
||||
type TestKubelet struct {
|
||||
kubelet *Kubelet
|
||||
fakeRuntime *kubecontainer.FakeRuntime
|
||||
fakeCadvisor *cadvisor.Mock
|
||||
fakeRuntime *containertest.FakeRuntime
|
||||
fakeCadvisor *cadvisortest.Mock
|
||||
fakeKubeClient *fake.Clientset
|
||||
fakeMirrorClient *kubepod.FakeMirrorClient
|
||||
fakeMirrorClient *podtest.FakeMirrorClient
|
||||
fakeClock *util.FakeClock
|
||||
mounter mount.Interface
|
||||
}
|
||||
|
||||
func newTestKubelet(t *testing.T) *TestKubelet {
|
||||
fakeRuntime := &kubecontainer.FakeRuntime{}
|
||||
fakeRuntime := &containertest.FakeRuntime{}
|
||||
fakeRuntime.VersionInfo = "1.15"
|
||||
fakeRuntime.ImageList = []kubecontainer.Image{
|
||||
{
|
||||
|
@ -116,12 +118,12 @@ func newTestKubelet(t *testing.T) *TestKubelet {
|
|||
fakeKubeClient := &fake.Clientset{}
|
||||
kubelet := &Kubelet{}
|
||||
kubelet.kubeClient = fakeKubeClient
|
||||
kubelet.os = kubecontainer.FakeOS{}
|
||||
kubelet.os = containertest.FakeOS{}
|
||||
|
||||
kubelet.hostname = testKubeletHostname
|
||||
kubelet.nodeName = testKubeletHostname
|
||||
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, false, func() error { return nil })
|
||||
kubelet.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
|
||||
kubelet.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil))
|
||||
if tempDir, err := ioutil.TempDir("/tmp", "kubelet_test."); err != nil {
|
||||
t.Fatalf("can't make a temp rootdir: %v", err)
|
||||
} else {
|
||||
|
@ -140,9 +142,9 @@ func newTestKubelet(t *testing.T) *TestKubelet {
|
|||
t.Fatalf("can't initialize kubelet data dirs: %v", err)
|
||||
}
|
||||
kubelet.daemonEndpoints = &api.NodeDaemonEndpoints{}
|
||||
mockCadvisor := &cadvisor.Mock{}
|
||||
mockCadvisor := &cadvisortest.Mock{}
|
||||
kubelet.cadvisor = mockCadvisor
|
||||
fakeMirrorClient := kubepod.NewFakeMirrorClient()
|
||||
fakeMirrorClient := podtest.NewFakeMirrorClient()
|
||||
kubelet.podManager = kubepod.NewBasicPodManager(fakeMirrorClient)
|
||||
kubelet.statusManager = status.NewManager(fakeKubeClient, kubelet.podManager)
|
||||
kubelet.containerRefManager = kubecontainer.NewRefManager()
|
||||
|
@ -153,16 +155,16 @@ func newTestKubelet(t *testing.T) *TestKubelet {
|
|||
kubelet.diskSpaceManager = diskSpaceManager
|
||||
|
||||
kubelet.containerRuntime = fakeRuntime
|
||||
kubelet.runtimeCache = kubecontainer.NewFakeRuntimeCache(kubelet.containerRuntime)
|
||||
kubelet.runtimeCache = containertest.NewFakeRuntimeCache(kubelet.containerRuntime)
|
||||
kubelet.reasonCache = NewReasonCache()
|
||||
kubelet.podCache = kubecontainer.NewFakeCache(kubelet.containerRuntime)
|
||||
kubelet.podCache = containertest.NewFakeCache(kubelet.containerRuntime)
|
||||
kubelet.podWorkers = &fakePodWorkers{
|
||||
syncPodFn: kubelet.syncPod,
|
||||
cache: kubelet.podCache,
|
||||
t: t,
|
||||
}
|
||||
|
||||
kubelet.probeManager = prober.FakeManager{}
|
||||
kubelet.probeManager = probetest.FakeManager{}
|
||||
kubelet.livenessManager = proberesults.NewManager()
|
||||
|
||||
kubelet.volumeManager = newVolumeManager()
|
||||
|
@ -2633,7 +2635,7 @@ func TestValidateContainerLogStatus(t *testing.T) {
|
|||
// with the mock FsInfo values added to Cadvisor should make the kubelet report that it has
|
||||
// sufficient disk space or it is out of disk, depending on the capacity, availability and
|
||||
// threshold values.
|
||||
func updateDiskSpacePolicy(kubelet *Kubelet, mockCadvisor *cadvisor.Mock, rootCap, dockerCap, rootAvail, dockerAvail uint64, rootThreshold, dockerThreshold int) error {
|
||||
func updateDiskSpacePolicy(kubelet *Kubelet, mockCadvisor *cadvisortest.Mock, rootCap, dockerCap, rootAvail, dockerAvail uint64, rootThreshold, dockerThreshold int) error {
|
||||
dockerimagesFsInfo := cadvisorapiv2.FsInfo{Capacity: rootCap * mb, Available: rootAvail * mb}
|
||||
rootFsInfo := cadvisorapiv2.FsInfo{Capacity: dockerCap * mb, Available: dockerAvail * mb}
|
||||
mockCadvisor.On("DockerImagesFsInfo").Return(dockerimagesFsInfo, nil)
|
||||
|
@ -3505,7 +3507,7 @@ func TestCreateMirrorPod(t *testing.T) {
|
|||
}
|
||||
pods := []*api.Pod{pod}
|
||||
kl.podManager.SetPods(pods)
|
||||
err := kl.syncPod(pod, nil, &container.PodStatus{}, updateType)
|
||||
err := kl.syncPod(pod, nil, &kubecontainer.PodStatus{}, updateType)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -3563,7 +3565,7 @@ func TestDeleteOutdatedMirrorPod(t *testing.T) {
|
|||
|
||||
pods := []*api.Pod{pod, mirrorPod}
|
||||
kl.podManager.SetPods(pods)
|
||||
err := kl.syncPod(pod, mirrorPod, &container.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
err := kl.syncPod(pod, mirrorPod, &kubecontainer.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -3729,7 +3731,7 @@ func TestHostNetworkAllowed(t *testing.T) {
|
|||
},
|
||||
}
|
||||
kubelet.podManager.SetPods([]*api.Pod{pod})
|
||||
err := kubelet.syncPod(pod, nil, &container.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
err := kubelet.syncPod(pod, nil, &kubecontainer.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
if err != nil {
|
||||
t.Errorf("expected pod infra creation to succeed: %v", err)
|
||||
}
|
||||
|
@ -3762,7 +3764,7 @@ func TestHostNetworkDisallowed(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := kubelet.syncPod(pod, nil, &container.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
err := kubelet.syncPod(pod, nil, &kubecontainer.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
if err == nil {
|
||||
t.Errorf("expected pod infra creation to fail")
|
||||
}
|
||||
|
@ -3789,7 +3791,7 @@ func TestPrivilegeContainerAllowed(t *testing.T) {
|
|||
},
|
||||
}
|
||||
kubelet.podManager.SetPods([]*api.Pod{pod})
|
||||
err := kubelet.syncPod(pod, nil, &container.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
err := kubelet.syncPod(pod, nil, &kubecontainer.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
if err != nil {
|
||||
t.Errorf("expected pod infra creation to succeed: %v", err)
|
||||
}
|
||||
|
@ -3815,7 +3817,7 @@ func TestPrivilegeContainerDisallowed(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := kubelet.syncPod(pod, nil, &container.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
err := kubelet.syncPod(pod, nil, &kubecontainer.PodStatus{}, kubetypes.SyncPodUpdate)
|
||||
if err == nil {
|
||||
t.Errorf("expected pod infra creation to fail")
|
||||
}
|
||||
|
|
|
@ -36,8 +36,10 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/record"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
nettest "k8s.io/kubernetes/pkg/kubelet/network/testing"
|
||||
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||
|
@ -143,7 +145,7 @@ func newTestDockerManager() (*dockertools.DockerManager, *dockertools.FakeDocker
|
|||
fakeDocker := dockertools.NewFakeDockerClient()
|
||||
fakeRecorder := &record.FakeRecorder{}
|
||||
containerRefManager := kubecontainer.NewRefManager()
|
||||
networkPlugin, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
|
||||
networkPlugin, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil))
|
||||
dockerManager := dockertools.NewFakeDockerManager(
|
||||
fakeDocker,
|
||||
fakeRecorder,
|
||||
|
@ -152,7 +154,7 @@ func newTestDockerManager() (*dockertools.DockerManager, *dockertools.FakeDocker
|
|||
&cadvisorapi.MachineInfo{},
|
||||
kubetypes.PodInfraContainerImage,
|
||||
0, 0, "",
|
||||
kubecontainer.FakeOS{},
|
||||
containertest.FakeOS{},
|
||||
networkPlugin,
|
||||
nil,
|
||||
nil,
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"text/template"
|
||||
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
nettest "k8s.io/kubernetes/pkg/kubelet/network/testing"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||
)
|
||||
|
@ -132,7 +133,7 @@ func TestSelectPlugin(t *testing.T) {
|
|||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))
|
||||
if err != nil {
|
||||
t.Errorf("Failed to select the desired plugin: %v", err)
|
||||
}
|
||||
|
@ -154,7 +155,7 @@ func TestSelectVendoredPlugin(t *testing.T) {
|
|||
installPluginUnderTest(t, vendor, testPluginPath, pluginName, nil)
|
||||
|
||||
vendoredPluginName := fmt.Sprintf("%s/%s", vendor, pluginName)
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), vendoredPluginName, network.NewFakeHost(nil))
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), vendoredPluginName, nettest.NewFakeHost(nil))
|
||||
if err != nil {
|
||||
t.Errorf("Failed to select the desired plugin: %v", err)
|
||||
}
|
||||
|
@ -175,7 +176,7 @@ func TestSelectWrongPlugin(t *testing.T) {
|
|||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
wrongPlugin := "abcd"
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), wrongPlugin, network.NewFakeHost(nil))
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), wrongPlugin, nettest.NewFakeHost(nil))
|
||||
if plug != nil || err == nil {
|
||||
t.Errorf("Expected to see an error. Wrong plugin selected.")
|
||||
}
|
||||
|
@ -203,7 +204,7 @@ func TestPluginValidation(t *testing.T) {
|
|||
}
|
||||
f.Close()
|
||||
|
||||
_, err = network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
|
||||
_, err = network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))
|
||||
if err == nil {
|
||||
// we expected an error here because validation would have failed
|
||||
t.Errorf("Expected non-nil value.")
|
||||
|
@ -221,7 +222,7 @@ func TestPluginSetupHook(t *testing.T) {
|
|||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))
|
||||
|
||||
err = plug.SetUpPod("podNamespace", "podName", "dockerid2345")
|
||||
if err != nil {
|
||||
|
@ -249,7 +250,7 @@ func TestPluginTearDownHook(t *testing.T) {
|
|||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))
|
||||
|
||||
err = plug.TearDownPod("podNamespace", "podName", "dockerid2345")
|
||||
if err != nil {
|
||||
|
@ -277,7 +278,7 @@ func TestPluginStatusHook(t *testing.T) {
|
|||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))
|
||||
|
||||
ip, err := plug.Status("namespace", "name", "dockerid2345")
|
||||
if err != nil {
|
||||
|
@ -313,7 +314,7 @@ func TestPluginStatusHookIPv6(t *testing.T) {
|
|||
}
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, execTemplate)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))
|
||||
if err != nil {
|
||||
t.Errorf("InitNetworkPlugin() failed: %v", err)
|
||||
}
|
||||
|
|
|
@ -18,11 +18,13 @@ package network
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
nettest "k8s.io/kubernetes/pkg/kubelet/network/testing"
|
||||
)
|
||||
|
||||
func TestSelectDefaultPlugin(t *testing.T) {
|
||||
all_plugins := []NetworkPlugin{}
|
||||
plug, err := InitNetworkPlugin(all_plugins, "", NewFakeHost(nil))
|
||||
plug, err := InitNetworkPlugin(all_plugins, "", nettest.NewFakeHost(nil))
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error in selecting default plugin: %v", err)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package network
|
||||
package testing
|
||||
|
||||
// helper for testing plugins
|
||||
// a fake host is created here that can be used by plugins for testing
|
||||
|
@ -23,6 +23,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api"
|
||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
)
|
||||
|
||||
type fakeNetworkHost struct {
|
||||
|
@ -43,5 +44,5 @@ func (fnh *fakeNetworkHost) GetKubeClient() clientset.Interface {
|
|||
}
|
||||
|
||||
func (nh *fakeNetworkHost) GetRuntime() kubecontainer.Runtime {
|
||||
return &kubecontainer.FakeRuntime{}
|
||||
return &containertest.FakeRuntime{}
|
||||
}
|
|
@ -21,12 +21,12 @@ import (
|
|||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/record"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
|
||||
)
|
||||
|
||||
func TestBasic(t *testing.T) {
|
||||
fakeRecorder := &record.FakeRecorder{}
|
||||
mockCadvisor := &cadvisor.Fake{}
|
||||
mockCadvisor := &cadvisortest.Fake{}
|
||||
node := &api.ObjectReference{}
|
||||
oomWatcher := NewOOMWatcher(mockCadvisor, fakeRecorder)
|
||||
err := oomWatcher.Start(node)
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
)
|
||||
|
@ -35,11 +36,11 @@ const (
|
|||
|
||||
type TestGenericPLEG struct {
|
||||
pleg *GenericPLEG
|
||||
runtime *kubecontainer.FakeRuntime
|
||||
runtime *containertest.FakeRuntime
|
||||
}
|
||||
|
||||
func newTestGenericPLEG() *TestGenericPLEG {
|
||||
fakeRuntime := &kubecontainer.FakeRuntime{}
|
||||
fakeRuntime := &containertest.FakeRuntime{}
|
||||
// The channel capacity should be large enough to hold all events in a
|
||||
// single test.
|
||||
pleg := &GenericPLEG{
|
||||
|
@ -213,8 +214,8 @@ func TestReportMissingPods(t *testing.T) {
|
|||
verifyEvents(t, expected, actual)
|
||||
}
|
||||
|
||||
func newTestGenericPLEGWithRuntimeMock() (*GenericPLEG, *kubecontainer.Mock) {
|
||||
runtimeMock := &kubecontainer.Mock{}
|
||||
func newTestGenericPLEGWithRuntimeMock() (*GenericPLEG, *containertest.Mock) {
|
||||
runtimeMock := &containertest.Mock{}
|
||||
pleg := &GenericPLEG{
|
||||
relistPeriod: time.Hour,
|
||||
runtime: runtimeMock,
|
||||
|
|
|
@ -21,12 +21,13 @@ import (
|
|||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
podtest "k8s.io/kubernetes/pkg/kubelet/pod/testing"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
)
|
||||
|
||||
// Stub out mirror client for testing purpose.
|
||||
func newTestManager() (*basicManager, *FakeMirrorClient) {
|
||||
fakeMirrorClient := NewFakeMirrorClient()
|
||||
func newTestManager() (*basicManager, *podtest.FakeMirrorClient) {
|
||||
fakeMirrorClient := podtest.NewFakeMirrorClient()
|
||||
manager := NewBasicPodManager(fakeMirrorClient).(*basicManager)
|
||||
return manager, fakeMirrorClient
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pod
|
||||
package testing
|
||||
|
||||
import (
|
||||
"sync"
|
|
@ -25,11 +25,38 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/record"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util/queue"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
)
|
||||
|
||||
// fakePodWorkers runs sync pod function in serial, so we can have
|
||||
// deterministic behaviour in testing.
|
||||
type fakePodWorkers struct {
|
||||
syncPodFn syncPodFnType
|
||||
cache kubecontainer.Cache
|
||||
t TestingInterface
|
||||
}
|
||||
|
||||
func (f *fakePodWorkers) UpdatePod(pod *api.Pod, mirrorPod *api.Pod, updateType kubetypes.SyncPodType, updateComplete func()) {
|
||||
status, err := f.cache.Get(pod.UID)
|
||||
if err != nil {
|
||||
f.t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
if err := f.syncPodFn(pod, mirrorPod, status, kubetypes.SyncPodUpdate); err != nil {
|
||||
f.t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fakePodWorkers) ForgetNonExistingPodWorkers(desiredPods map[types.UID]empty) {}
|
||||
|
||||
func (f *fakePodWorkers) ForgetWorker(uid types.UID) {}
|
||||
|
||||
type TestingInterface interface {
|
||||
Errorf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
func newPod(uid, name string) *api.Pod {
|
||||
return &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
|
@ -43,8 +70,8 @@ func createPodWorkers() (*podWorkers, map[types.UID][]string) {
|
|||
lock := sync.Mutex{}
|
||||
processed := make(map[types.UID][]string)
|
||||
fakeRecorder := &record.FakeRecorder{}
|
||||
fakeRuntime := &kubecontainer.FakeRuntime{}
|
||||
fakeCache := kubecontainer.NewFakeCache(fakeRuntime)
|
||||
fakeRuntime := &containertest.FakeRuntime{}
|
||||
fakeCache := containertest.NewFakeCache(fakeRuntime)
|
||||
podWorkers := newPodWorkers(
|
||||
func(pod *api.Pod, mirrorPod *api.Pod, status *kubecontainer.PodStatus, updateType kubetypes.SyncPodType) error {
|
||||
func() {
|
||||
|
@ -183,8 +210,8 @@ func (b byContainerName) Less(i, j int) bool {
|
|||
// for their invocation of the syncPodFn.
|
||||
func TestFakePodWorkers(t *testing.T) {
|
||||
fakeRecorder := &record.FakeRecorder{}
|
||||
fakeRuntime := &kubecontainer.FakeRuntime{}
|
||||
fakeCache := kubecontainer.NewFakeCache(fakeRuntime)
|
||||
fakeRuntime := &containertest.FakeRuntime{}
|
||||
fakeCache := containertest.NewFakeCache(fakeRuntime)
|
||||
|
||||
kubeletForRealWorkers := &simpleFakeKubelet{}
|
||||
kubeletForFakeWorkers := &simpleFakeKubelet{}
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package prober
|
||||
package testing
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
|
@ -23,8 +23,6 @@ import (
|
|||
|
||||
type FakeManager struct{}
|
||||
|
||||
var _ Manager = FakeManager{}
|
||||
|
||||
// Unused methods.
|
||||
func (_ FakeManager) AddPod(_ *api.Pod) {}
|
||||
func (_ FakeManager) RemovePod(_ *api.Pod) {}
|
|
@ -25,18 +25,21 @@ import (
|
|||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/record"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
nettest "k8s.io/kubernetes/pkg/kubelet/network/testing"
|
||||
kubepod "k8s.io/kubernetes/pkg/kubelet/pod"
|
||||
podtest "k8s.io/kubernetes/pkg/kubelet/pod/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/status"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||
)
|
||||
|
||||
func TestRunOnce(t *testing.T) {
|
||||
cadvisor := &cadvisor.Mock{}
|
||||
cadvisor := &cadvisortest.Mock{}
|
||||
cadvisor.On("MachineInfo").Return(&cadvisorapi.MachineInfo{}, nil)
|
||||
cadvisor.On("DockerImagesFsInfo").Return(cadvisorapiv2.FsInfo{
|
||||
Usage: 400 * mb,
|
||||
|
@ -47,9 +50,9 @@ func TestRunOnce(t *testing.T) {
|
|||
Usage: 9 * mb,
|
||||
Capacity: 10 * mb,
|
||||
}, nil)
|
||||
podManager := kubepod.NewBasicPodManager(kubepod.NewFakeMirrorClient())
|
||||
podManager := kubepod.NewBasicPodManager(podtest.NewFakeMirrorClient())
|
||||
diskSpaceManager, _ := newDiskSpaceManager(cadvisor, DiskSpacePolicy{})
|
||||
fakeRuntime := &kubecontainer.FakeRuntime{}
|
||||
fakeRuntime := &containertest.FakeRuntime{}
|
||||
basePath, err := utiltesting.MkTmpdir("kubelet")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp rootdir %v", err)
|
||||
|
@ -64,7 +67,7 @@ func TestRunOnce(t *testing.T) {
|
|||
statusManager: status.NewManager(nil, podManager),
|
||||
containerRefManager: kubecontainer.NewRefManager(),
|
||||
podManager: podManager,
|
||||
os: kubecontainer.FakeOS{},
|
||||
os: containertest.FakeOS{},
|
||||
volumeManager: newVolumeManager(),
|
||||
diskSpaceManager: diskSpaceManager,
|
||||
containerRuntime: fakeRuntime,
|
||||
|
@ -73,7 +76,7 @@ func TestRunOnce(t *testing.T) {
|
|||
}
|
||||
kb.containerManager = cm.NewStubContainerManager()
|
||||
|
||||
kb.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
|
||||
kb.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil))
|
||||
if err := kb.setupDataDirs(); err != nil {
|
||||
t.Errorf("Failed to init data dirs: %v", err)
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
kubepod "k8s.io/kubernetes/pkg/kubelet/pod"
|
||||
podtest "k8s.io/kubernetes/pkg/kubelet/pod/testing"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
@ -68,7 +69,7 @@ func (m *manager) testSyncBatch() {
|
|||
}
|
||||
|
||||
func newTestManager(kubeClient clientset.Interface) *manager {
|
||||
podManager := kubepod.NewBasicPodManager(kubepod.NewFakeMirrorClient())
|
||||
podManager := kubepod.NewBasicPodManager(podtest.NewFakeMirrorClient())
|
||||
podManager.AddPod(getTestPod())
|
||||
return NewManager(kubeClient, podManager).(*manager)
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||
"k8s.io/kubernetes/pkg/volume/empty_dir"
|
||||
"k8s.io/kubernetes/test/integration"
|
||||
|
@ -64,7 +64,7 @@ func NewHollowKubelet(
|
|||
cadvisorInterface,
|
||||
manifestFilePath,
|
||||
nil, /* cloud-provider */
|
||||
kubecontainer.FakeOS{}, /* os-interface */
|
||||
containertest.FakeOS{}, /* os-interface */
|
||||
20*time.Second, /* FileCheckFrequency */
|
||||
20*time.Second, /* HTTPCheckFrequency */
|
||||
1*time.Minute, /* MinimumGCAge */
|
||||
|
|
Loading…
Reference in New Issue