mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-24 11:01:26 +00:00
kubelet: Minor refactors.
Remove some TODOs. Unexport DockerManager.Puller and DockerManager.PodInfraContainerImage. Add "docker" for all "go-dockerclient" imports.
This commit is contained in:
parent
b42869181a
commit
f197a9db4e
@ -29,7 +29,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
"github.com/google/gofuzz"
|
"github.com/google/gofuzz"
|
||||||
|
|
||||||
"speter.net/go/exp/math/dec/inf"
|
"speter.net/go/exp/math/dec/inf"
|
||||||
|
@ -32,8 +32,6 @@ type RuntimeCache interface {
|
|||||||
ForceUpdateIfOlder(time.Time) error
|
ForceUpdateIfOlder(time.Time) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(yifan): This interface can be removed once docker manager has implemented
|
|
||||||
// all the runtime interfaces, (thus we can pass the runtime directly).
|
|
||||||
type podsGetter interface {
|
type podsGetter interface {
|
||||||
GetPods(bool) ([]*Pod, error)
|
GetPods(bool) ([]*Pod, error)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
||||||
"github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
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.
|
// ExecHandler knows how to execute a command in a running Docker container.
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
|
@ -41,7 +41,7 @@ func NewFakeDockerManager(
|
|||||||
|
|
||||||
dm := NewDockerManager(client, recorder, readinessManager, containerRefManager, podInfraContainerImage, qps,
|
dm := NewDockerManager(client, recorder, readinessManager, containerRefManager, podInfraContainerImage, qps,
|
||||||
burst, containerLogsDir, osInterface, networkPlugin, generator, httpClient, runtimeHooks, &NativeExecHandler{})
|
burst, containerLogsDir, osInterface, networkPlugin, generator, httpClient, runtimeHooks, &NativeExecHandler{})
|
||||||
dm.Puller = &FakeDockerPuller{}
|
dm.puller = &FakeDockerPuller{}
|
||||||
dm.prober = prober.New(nil, readinessManager, containerRefManager, recorder)
|
dm.prober = prober.New(nil, readinessManager, containerRefManager, recorder)
|
||||||
return dm
|
return dm
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics"
|
||||||
"github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
type instrumentedDockerInterface struct {
|
type instrumentedDockerInterface struct {
|
||||||
|
@ -68,9 +68,8 @@ type DockerManager struct {
|
|||||||
containerRefManager *kubecontainer.RefManager
|
containerRefManager *kubecontainer.RefManager
|
||||||
os kubecontainer.OSInterface
|
os kubecontainer.OSInterface
|
||||||
|
|
||||||
// TODO(yifan): PodInfraContainerImage can be unexported once
|
// The image name of the pod infra container.
|
||||||
// we move createPodInfraContainer into dockertools.
|
podInfraContainerImage string
|
||||||
PodInfraContainerImage string
|
|
||||||
// reasonCache stores the failure reason of the last container creation
|
// reasonCache stores the failure reason of the last container creation
|
||||||
// and/or start in a string, keyed by <pod_UID>_<container_name>. The goal
|
// 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
|
// 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
|
// means that some entries may be recycled before a pod has been
|
||||||
// deleted.
|
// deleted.
|
||||||
reasonCache stringCache
|
reasonCache stringCache
|
||||||
// TODO(yifan): We export this for testability, so when we have a fake
|
// TODO(yifan): Record the pull failure so we can eliminate the image checking
|
||||||
// container manager, then we can unexport this. Also at that time, we
|
// in GetPodStatus()?
|
||||||
// use the concrete type so that we can record the pull failure and eliminate
|
puller DockerPuller
|
||||||
// the image checking in GetPodStatus().
|
|
||||||
Puller DockerPuller
|
|
||||||
|
|
||||||
// Root of the Docker runtime.
|
// Root of the Docker runtime.
|
||||||
dockerRoot string
|
dockerRoot string
|
||||||
@ -164,9 +161,9 @@ func NewDockerManager(
|
|||||||
readinessManager: readinessManager,
|
readinessManager: readinessManager,
|
||||||
containerRefManager: containerRefManager,
|
containerRefManager: containerRefManager,
|
||||||
os: osInterface,
|
os: osInterface,
|
||||||
PodInfraContainerImage: podInfraContainerImage,
|
podInfraContainerImage: podInfraContainerImage,
|
||||||
reasonCache: reasonCache,
|
reasonCache: reasonCache,
|
||||||
Puller: newDockerPuller(client, qps, burst),
|
puller: newDockerPuller(client, qps, burst),
|
||||||
dockerRoot: dockerRoot,
|
dockerRoot: dockerRoot,
|
||||||
containerLogsDir: containerLogsDir,
|
containerLogsDir: containerLogsDir,
|
||||||
networkPlugin: networkPlugin,
|
networkPlugin: networkPlugin,
|
||||||
@ -784,12 +781,12 @@ func (dm *DockerManager) ListImages() ([]kubecontainer.Image, error) {
|
|||||||
// TODO(vmarmol): Consider unexporting.
|
// TODO(vmarmol): Consider unexporting.
|
||||||
// PullImage pulls an image from network to local storage.
|
// PullImage pulls an image from network to local storage.
|
||||||
func (dm *DockerManager) PullImage(image kubecontainer.ImageSpec, secrets []api.Secret) error {
|
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.
|
// IsImagePresent checks whether the container image is already in the local storage.
|
||||||
func (dm *DockerManager) IsImagePresent(image kubecontainer.ImageSpec) (bool, error) {
|
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.
|
// Removes the specified image.
|
||||||
@ -825,7 +822,7 @@ func (dm *DockerManager) podInfraContainerChanged(pod *api.Pod, podInfraContaine
|
|||||||
}
|
}
|
||||||
expectedPodInfraContainer := &api.Container{
|
expectedPodInfraContainer := &api.Container{
|
||||||
Name: PodInfraContainerName,
|
Name: PodInfraContainerName,
|
||||||
Image: dm.PodInfraContainerImage,
|
Image: dm.podInfraContainerImage,
|
||||||
Ports: ports,
|
Ports: ports,
|
||||||
}
|
}
|
||||||
return podInfraContainer.Hash != kubecontainer.HashContainer(expectedPodInfraContainer), nil
|
return podInfraContainer.Hash != kubecontainer.HashContainer(expectedPodInfraContainer), nil
|
||||||
@ -1203,7 +1200,7 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubeletTypes.Doc
|
|||||||
|
|
||||||
container := &api.Container{
|
container := &api.Container{
|
||||||
Name: PodInfraContainerName,
|
Name: PodInfraContainerName,
|
||||||
Image: dm.PodInfraContainerImage,
|
Image: dm.podInfraContainerImage,
|
||||||
Ports: ports,
|
Ports: ports,
|
||||||
}
|
}
|
||||||
ref, err := kubecontainer.GenerateContainerRef(pod, container)
|
ref, err := kubecontainer.GenerateContainerRef(pod, container)
|
||||||
|
@ -38,7 +38,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
uexec "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
|
uexec "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
|
||||||
"github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeHTTP struct {
|
type fakeHTTP struct {
|
||||||
@ -876,7 +876,7 @@ func runSyncPod(t *testing.T, dm *DockerManager, fakeDocker *FakeDockerClient, p
|
|||||||
|
|
||||||
func TestSyncPodCreateNetAndContainer(t *testing.T) {
|
func TestSyncPodCreateNetAndContainer(t *testing.T) {
|
||||||
dm, fakeDocker := newTestDockerManager()
|
dm, fakeDocker := newTestDockerManager()
|
||||||
dm.PodInfraContainerImage = "custom_image_name"
|
dm.podInfraContainerImage = "custom_image_name"
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{}
|
fakeDocker.ContainerList = []docker.APIContainers{}
|
||||||
pod := &api.Pod{
|
pod := &api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
@ -921,10 +921,10 @@ func TestSyncPodCreateNetAndContainer(t *testing.T) {
|
|||||||
|
|
||||||
func TestSyncPodCreatesNetAndContainerPullsImage(t *testing.T) {
|
func TestSyncPodCreatesNetAndContainerPullsImage(t *testing.T) {
|
||||||
dm, fakeDocker := newTestDockerManager()
|
dm, fakeDocker := newTestDockerManager()
|
||||||
dm.PodInfraContainerImage = "custom_image_name"
|
dm.podInfraContainerImage = "custom_image_name"
|
||||||
puller := dm.Puller.(*FakeDockerPuller)
|
puller := dm.puller.(*FakeDockerPuller)
|
||||||
puller.HasImages = []string{}
|
puller.HasImages = []string{}
|
||||||
dm.PodInfraContainerImage = "custom_image_name"
|
dm.podInfraContainerImage = "custom_image_name"
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{}
|
fakeDocker.ContainerList = []docker.APIContainers{}
|
||||||
pod := &api.Pod{
|
pod := &api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
@ -1282,9 +1282,9 @@ func TestSyncPodsDoesNothing(t *testing.T) {
|
|||||||
|
|
||||||
func TestSyncPodWithPullPolicy(t *testing.T) {
|
func TestSyncPodWithPullPolicy(t *testing.T) {
|
||||||
dm, fakeDocker := newTestDockerManager()
|
dm, fakeDocker := newTestDockerManager()
|
||||||
puller := dm.Puller.(*FakeDockerPuller)
|
puller := dm.puller.(*FakeDockerPuller)
|
||||||
puller.HasImages = []string{"existing_one", "want:latest"}
|
puller.HasImages = []string{"existing_one", "want:latest"}
|
||||||
dm.PodInfraContainerImage = "custom_image_name"
|
dm.podInfraContainerImage = "custom_image_name"
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{}
|
fakeDocker.ContainerList = []docker.APIContainers{}
|
||||||
|
|
||||||
pod := &api.Pod{
|
pod := &api.Pod{
|
||||||
@ -1649,7 +1649,7 @@ func TestGetPodPullImageFailureReason(t *testing.T) {
|
|||||||
dm, fakeDocker := newTestDockerManager()
|
dm, fakeDocker := newTestDockerManager()
|
||||||
// Initialize the FakeDockerPuller so that it'd try to pull non-existent
|
// Initialize the FakeDockerPuller so that it'd try to pull non-existent
|
||||||
// images.
|
// images.
|
||||||
puller := dm.Puller.(*FakeDockerPuller)
|
puller := dm.puller.(*FakeDockerPuller)
|
||||||
puller.HasImages = []string{}
|
puller.HasImages = []string{}
|
||||||
// Inject the pull image failure error.
|
// Inject the pull image failure error.
|
||||||
failureReason := "pull image faiulre"
|
failureReason := "pull image faiulre"
|
||||||
|
@ -2124,7 +2124,6 @@ func (kl *Kubelet) ServeLogs(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
// findContainer finds and returns the container with the given pod ID, full name, and container name.
|
// findContainer finds and returns the container with the given pod ID, full name, and container name.
|
||||||
// It returns nil if not found.
|
// It returns nil if not found.
|
||||||
// TODO(yifan): Move this to runtime once the runtime interface has been all implemented.
|
|
||||||
func (kl *Kubelet) findContainer(podFullName string, podUID types.UID, containerName string) (*kubecontainer.Container, error) {
|
func (kl *Kubelet) findContainer(podFullName string, podUID types.UID, containerName string) (*kubecontainer.Container, error) {
|
||||||
pods, err := kl.containerRuntime.GetPods(false)
|
pods, err := kl.containerRuntime.GetPods(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +50,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
|
||||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/host_path"
|
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/volume/host_path"
|
||||||
"github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
cadvisorApi "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
cadvisorApiv2 "github.com/google/cadvisor/info/v2"
|
cadvisorApiv2 "github.com/google/cadvisor/info/v2"
|
||||||
)
|
)
|
||||||
@ -2176,17 +2176,12 @@ func TestPortForward(t *testing.T) {
|
|||||||
var port uint16 = 5000
|
var port uint16 = 5000
|
||||||
stream := &fakeReadWriteCloser{}
|
stream := &fakeReadWriteCloser{}
|
||||||
|
|
||||||
podInfraContainerImage := "POD"
|
|
||||||
infraContainerID := "infra"
|
infraContainerID := "infra"
|
||||||
// TODO: Move this test to dockertools so that we don't have to do the hacky
|
|
||||||
// type assertion here.
|
|
||||||
dm := kubelet.containerRuntime.(*dockertools.DockerManager)
|
|
||||||
dm.PodInfraContainerImage = podInfraContainerImage
|
|
||||||
|
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{
|
fakeDocker.ContainerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
ID: infraContainerID,
|
ID: infraContainerID,
|
||||||
Names: []string{"/k8s_" + podInfraContainerImage + "_" + podName + "_" + podNamespace + "_12345678_42"},
|
Names: []string{"/k8s_POD" + "_" + podName + "_" + podNamespace + "_12345678_42"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: containerID,
|
ID: containerID,
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newPod(uid, name string) *api.Pod {
|
func newPod(uid, name string) *api.Pod {
|
||||||
|
Loading…
Reference in New Issue
Block a user