kubelet: Minor refactors.

Remove some TODOs.
Unexport DockerManager.Puller and DockerManager.PodInfraContainerImage.
Add "docker" for all "go-dockerclient" imports.
This commit is contained in:
Yifan Gu
2015-06-04 14:36:59 -07:00
parent b42869181a
commit f197a9db4e
13 changed files with 29 additions and 40 deletions

View File

@@ -24,7 +24,7 @@ import (
"time"
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
"github.com/fsouza/go-dockerclient"
docker "github.com/fsouza/go-dockerclient"
)
// ExecHandler knows how to execute a command in a running Docker container.

View File

@@ -24,7 +24,7 @@ import (
"sort"
"sync"
"github.com/fsouza/go-dockerclient"
docker "github.com/fsouza/go-dockerclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

View File

@@ -41,7 +41,7 @@ func NewFakeDockerManager(
dm := NewDockerManager(client, recorder, readinessManager, containerRefManager, podInfraContainerImage, qps,
burst, containerLogsDir, osInterface, networkPlugin, generator, httpClient, runtimeHooks, &NativeExecHandler{})
dm.Puller = &FakeDockerPuller{}
dm.puller = &FakeDockerPuller{}
dm.prober = prober.New(nil, readinessManager, containerRefManager, recorder)
return dm
}

View File

@@ -20,7 +20,7 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics"
"github.com/fsouza/go-dockerclient"
docker "github.com/fsouza/go-dockerclient"
)
type instrumentedDockerInterface struct {

View File

@@ -68,9 +68,8 @@ type DockerManager struct {
containerRefManager *kubecontainer.RefManager
os kubecontainer.OSInterface
// TODO(yifan): PodInfraContainerImage can be unexported once
// we move createPodInfraContainer into dockertools.
PodInfraContainerImage string
// The image name of the pod infra container.
podInfraContainerImage string
// reasonCache stores the failure reason of the last container creation
// and/or start in a string, keyed by <pod_UID>_<container_name>. The goal
// is to propagate this reason to the container status. This endeavor is
@@ -80,11 +79,9 @@ type DockerManager struct {
// means that some entries may be recycled before a pod has been
// deleted.
reasonCache stringCache
// TODO(yifan): We export this for testability, so when we have a fake
// container manager, then we can unexport this. Also at that time, we
// use the concrete type so that we can record the pull failure and eliminate
// the image checking in GetPodStatus().
Puller DockerPuller
// TODO(yifan): Record the pull failure so we can eliminate the image checking
// in GetPodStatus()?
puller DockerPuller
// Root of the Docker runtime.
dockerRoot string
@@ -164,9 +161,9 @@ func NewDockerManager(
readinessManager: readinessManager,
containerRefManager: containerRefManager,
os: osInterface,
PodInfraContainerImage: podInfraContainerImage,
podInfraContainerImage: podInfraContainerImage,
reasonCache: reasonCache,
Puller: newDockerPuller(client, qps, burst),
puller: newDockerPuller(client, qps, burst),
dockerRoot: dockerRoot,
containerLogsDir: containerLogsDir,
networkPlugin: networkPlugin,
@@ -784,12 +781,12 @@ func (dm *DockerManager) ListImages() ([]kubecontainer.Image, error) {
// TODO(vmarmol): Consider unexporting.
// PullImage pulls an image from network to local storage.
func (dm *DockerManager) PullImage(image kubecontainer.ImageSpec, secrets []api.Secret) error {
return dm.Puller.Pull(image.Image, secrets)
return dm.puller.Pull(image.Image, secrets)
}
// IsImagePresent checks whether the container image is already in the local storage.
func (dm *DockerManager) IsImagePresent(image kubecontainer.ImageSpec) (bool, error) {
return dm.Puller.IsImagePresent(image.Image)
return dm.puller.IsImagePresent(image.Image)
}
// Removes the specified image.
@@ -825,7 +822,7 @@ func (dm *DockerManager) podInfraContainerChanged(pod *api.Pod, podInfraContaine
}
expectedPodInfraContainer := &api.Container{
Name: PodInfraContainerName,
Image: dm.PodInfraContainerImage,
Image: dm.podInfraContainerImage,
Ports: ports,
}
return podInfraContainer.Hash != kubecontainer.HashContainer(expectedPodInfraContainer), nil
@@ -1203,7 +1200,7 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubeletTypes.Doc
container := &api.Container{
Name: PodInfraContainerName,
Image: dm.PodInfraContainerImage,
Image: dm.podInfraContainerImage,
Ports: ports,
}
ref, err := kubecontainer.GenerateContainerRef(pod, container)

View File

@@ -38,7 +38,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
uexec "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
"github.com/fsouza/go-dockerclient"
docker "github.com/fsouza/go-dockerclient"
)
type fakeHTTP struct {
@@ -876,7 +876,7 @@ func runSyncPod(t *testing.T, dm *DockerManager, fakeDocker *FakeDockerClient, p
func TestSyncPodCreateNetAndContainer(t *testing.T) {
dm, fakeDocker := newTestDockerManager()
dm.PodInfraContainerImage = "custom_image_name"
dm.podInfraContainerImage = "custom_image_name"
fakeDocker.ContainerList = []docker.APIContainers{}
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
@@ -921,10 +921,10 @@ func TestSyncPodCreateNetAndContainer(t *testing.T) {
func TestSyncPodCreatesNetAndContainerPullsImage(t *testing.T) {
dm, fakeDocker := newTestDockerManager()
dm.PodInfraContainerImage = "custom_image_name"
puller := dm.Puller.(*FakeDockerPuller)
dm.podInfraContainerImage = "custom_image_name"
puller := dm.puller.(*FakeDockerPuller)
puller.HasImages = []string{}
dm.PodInfraContainerImage = "custom_image_name"
dm.podInfraContainerImage = "custom_image_name"
fakeDocker.ContainerList = []docker.APIContainers{}
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
@@ -1282,9 +1282,9 @@ func TestSyncPodsDoesNothing(t *testing.T) {
func TestSyncPodWithPullPolicy(t *testing.T) {
dm, fakeDocker := newTestDockerManager()
puller := dm.Puller.(*FakeDockerPuller)
puller := dm.puller.(*FakeDockerPuller)
puller.HasImages = []string{"existing_one", "want:latest"}
dm.PodInfraContainerImage = "custom_image_name"
dm.podInfraContainerImage = "custom_image_name"
fakeDocker.ContainerList = []docker.APIContainers{}
pod := &api.Pod{
@@ -1649,7 +1649,7 @@ func TestGetPodPullImageFailureReason(t *testing.T) {
dm, fakeDocker := newTestDockerManager()
// Initialize the FakeDockerPuller so that it'd try to pull non-existent
// images.
puller := dm.Puller.(*FakeDockerPuller)
puller := dm.puller.(*FakeDockerPuller)
puller.HasImages = []string{}
// Inject the pull image failure error.
failureReason := "pull image faiulre"