mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-03 18:27:49 +00:00
Create Kubelet types package for common shared types.
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
|
||||||
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/leaky"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/leaky"
|
||||||
|
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
||||||
"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/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
@@ -68,9 +69,6 @@ type DockerInterface interface {
|
|||||||
StartExec(string, docker.StartExecOptions) error
|
StartExec(string, docker.StartExecOptions) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
// KubeletContainerName encapsulates a pod name and a Kubernetes container name.
|
// KubeletContainerName encapsulates a pod name and a Kubernetes container name.
|
||||||
type KubeletContainerName struct {
|
type KubeletContainerName struct {
|
||||||
PodFullName string
|
PodFullName string
|
||||||
@@ -174,7 +172,7 @@ func (p throttledDockerPuller) IsImagePresent(name string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DockerContainers is a map of containers
|
// DockerContainers is a map of containers
|
||||||
type DockerContainers map[DockerID]*docker.APIContainers
|
type DockerContainers map[kubeletTypes.DockerID]*docker.APIContainers
|
||||||
|
|
||||||
func (c DockerContainers) FindPodContainer(podFullName string, uid types.UID, containerName string) (*docker.APIContainers, bool, uint64) {
|
func (c DockerContainers) FindPodContainer(podFullName string, uid types.UID, containerName string) (*docker.APIContainers, bool, uint64) {
|
||||||
for _, dockerContainer := range c {
|
for _, dockerContainer := range c {
|
||||||
@@ -319,7 +317,7 @@ func GetKubeletDockerContainers(client DockerInterface, allContainers bool) (Doc
|
|||||||
glog.V(3).Infof("Docker Container: %s is not managed by kubelet.", container.Names[0])
|
glog.V(3).Infof("Docker Container: %s is not managed by kubelet.", container.Names[0])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result[DockerID(container.ID)] = container
|
result[kubeletTypes.DockerID(container.ID)] = container
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
||||||
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
||||||
|
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
||||||
"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"
|
"github.com/fsouza/go-dockerclient"
|
||||||
@@ -988,7 +989,7 @@ func (dm *DockerManager) KillContainer(containerID types.UID) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run a single container from a pod. Returns the docker container ID
|
// Run a single container from a pod. Returns the docker container ID
|
||||||
func (dm *DockerManager) RunContainer(pod *api.Pod, container *api.Container, generator kubecontainer.RunContainerOptionsGenerator, runner kubecontainer.HandlerRunner, netMode, ipcMode string) (DockerID, error) {
|
func (dm *DockerManager) RunContainer(pod *api.Pod, container *api.Container, generator kubecontainer.RunContainerOptionsGenerator, runner kubecontainer.HandlerRunner, netMode, ipcMode string) (kubeletTypes.DockerID, error) {
|
||||||
ref, err := kubecontainer.GenerateContainerRef(pod, container)
|
ref, err := kubecontainer.GenerateContainerRef(pod, container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Couldn't make a ref to pod %v, container %v: '%v'", pod.Name, container.Name, err)
|
glog.Errorf("Couldn't make a ref to pod %v, container %v: '%v'", pod.Name, container.Name, err)
|
||||||
@@ -1013,7 +1014,7 @@ func (dm *DockerManager) RunContainer(pod *api.Pod, container *api.Container, ge
|
|||||||
handlerErr := runner.Run(id, pod, container, container.Lifecycle.PostStart)
|
handlerErr := runner.Run(id, pod, container, container.Lifecycle.PostStart)
|
||||||
if handlerErr != nil {
|
if handlerErr != nil {
|
||||||
dm.KillContainer(types.UID(id))
|
dm.KillContainer(types.UID(id))
|
||||||
return DockerID(""), fmt.Errorf("failed to call event handler: %v", handlerErr)
|
return kubeletTypes.DockerID(""), fmt.Errorf("failed to call event handler: %v", handlerErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1027,11 +1028,11 @@ func (dm *DockerManager) RunContainer(pod *api.Pod, container *api.Container, ge
|
|||||||
if err = dm.os.Symlink(containerLogFile, symlinkFile); err != nil {
|
if err = dm.os.Symlink(containerLogFile, symlinkFile); err != nil {
|
||||||
glog.Errorf("Failed to create symbolic link to the log file of pod %q container %q: %v", podFullName, container.Name, err)
|
glog.Errorf("Failed to create symbolic link to the log file of pod %q container %q: %v", podFullName, container.Name, err)
|
||||||
}
|
}
|
||||||
return DockerID(id), err
|
return kubeletTypes.DockerID(id), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePodInfraContainer starts the pod infra container for a pod. Returns the docker container ID of the newly created container.
|
// CreatePodInfraContainer starts the pod infra container for a pod. Returns the docker container ID of the newly created container.
|
||||||
func (dm *DockerManager) CreatePodInfraContainer(pod *api.Pod, generator kubecontainer.RunContainerOptionsGenerator, runner kubecontainer.HandlerRunner) (DockerID, error) {
|
func (dm *DockerManager) CreatePodInfraContainer(pod *api.Pod, generator kubecontainer.RunContainerOptionsGenerator, runner kubecontainer.HandlerRunner) (kubeletTypes.DockerID, error) {
|
||||||
// Use host networking if specified.
|
// Use host networking if specified.
|
||||||
netNamespace := ""
|
netNamespace := ""
|
||||||
var ports []api.ContainerPort
|
var ports []api.ContainerPort
|
||||||
|
@@ -43,6 +43,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/envvars"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/envvars"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
|
||||||
|
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
@@ -892,7 +893,7 @@ func (kl *Kubelet) killPod(pod kubecontainer.Pod) error {
|
|||||||
errList := []error{}
|
errList := []error{}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Call the networking plugin for teardown.
|
// Call the networking plugin for teardown.
|
||||||
err = kl.networkPlugin.TearDownPod(pod.Namespace, pod.Name, dockertools.DockerID(container.ID))
|
err = kl.networkPlugin.TearDownPod(pod.Namespace, pod.Name, kubeletTypes.DockerID(container.ID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed tearing down the network plugin for pod %q: %v", pod.ID, err)
|
glog.Errorf("Failed tearing down the network plugin for pod %q: %v", pod.ID, err)
|
||||||
errList = append(errList, err)
|
errList = append(errList, err)
|
||||||
@@ -973,9 +974,9 @@ func shouldContainerBeRestarted(container *api.Container, pod *api.Pod, podStatu
|
|||||||
// - all running containers which are NOT contained in containersToKeep should be killed.
|
// - all running containers which are NOT contained in containersToKeep should be killed.
|
||||||
type podContainerChangesSpec struct {
|
type podContainerChangesSpec struct {
|
||||||
startInfraContainer bool
|
startInfraContainer bool
|
||||||
infraContainerId dockertools.DockerID
|
infraContainerId kubeletTypes.DockerID
|
||||||
containersToStart map[int]empty
|
containersToStart map[int]empty
|
||||||
containersToKeep map[dockertools.DockerID]int
|
containersToKeep map[kubeletTypes.DockerID]int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubecontainer.Pod, podStatus api.PodStatus) (podContainerChangesSpec, error) {
|
func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubecontainer.Pod, podStatus api.PodStatus) (podContainerChangesSpec, error) {
|
||||||
@@ -984,11 +985,11 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
|
|||||||
glog.V(4).Infof("Syncing Pod %+v, podFullName: %q, uid: %q", pod, podFullName, uid)
|
glog.V(4).Infof("Syncing Pod %+v, podFullName: %q, uid: %q", pod, podFullName, uid)
|
||||||
|
|
||||||
containersToStart := make(map[int]empty)
|
containersToStart := make(map[int]empty)
|
||||||
containersToKeep := make(map[dockertools.DockerID]int)
|
containersToKeep := make(map[kubeletTypes.DockerID]int)
|
||||||
createPodInfraContainer := false
|
createPodInfraContainer := false
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var podInfraContainerID dockertools.DockerID
|
var podInfraContainerID kubeletTypes.DockerID
|
||||||
var changed bool
|
var changed bool
|
||||||
podInfraContainer := runningPod.FindContainerByName(dockertools.PodInfraContainerName)
|
podInfraContainer := runningPod.FindContainerByName(dockertools.PodInfraContainerName)
|
||||||
if podInfraContainer != nil {
|
if podInfraContainer != nil {
|
||||||
@@ -1007,7 +1008,7 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
|
|||||||
} else {
|
} else {
|
||||||
glog.V(4).Infof("Pod infra container looks good, keep it %q", podFullName)
|
glog.V(4).Infof("Pod infra container looks good, keep it %q", podFullName)
|
||||||
createPodInfraContainer = false
|
createPodInfraContainer = false
|
||||||
podInfraContainerID = dockertools.DockerID(podInfraContainer.ID)
|
podInfraContainerID = kubeletTypes.DockerID(podInfraContainer.ID)
|
||||||
containersToKeep[podInfraContainerID] = -1
|
containersToKeep[podInfraContainerID] = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1026,7 +1027,7 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
containerID := dockertools.DockerID(c.ID)
|
containerID := kubeletTypes.DockerID(c.ID)
|
||||||
hash := c.Hash
|
hash := c.Hash
|
||||||
glog.V(3).Infof("pod %q container %q exists as %v", podFullName, container.Name, containerID)
|
glog.V(3).Infof("pod %q container %q exists as %v", podFullName, container.Name, containerID)
|
||||||
|
|
||||||
@@ -1074,7 +1075,7 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
|
|||||||
|
|
||||||
// If Infra container is the last running one, we don't want to keep it.
|
// If Infra container is the last running one, we don't want to keep it.
|
||||||
if !createPodInfraContainer && len(containersToStart) == 0 && len(containersToKeep) == 1 {
|
if !createPodInfraContainer && len(containersToStart) == 0 && len(containersToKeep) == 1 {
|
||||||
containersToKeep = make(map[dockertools.DockerID]int)
|
containersToKeep = make(map[kubeletTypes.DockerID]int)
|
||||||
}
|
}
|
||||||
|
|
||||||
return podContainerChangesSpec{
|
return podContainerChangesSpec{
|
||||||
@@ -1147,7 +1148,7 @@ func (kl *Kubelet) syncPod(pod *api.Pod, mirrorPod *api.Pod, runningPod kubecont
|
|||||||
} else {
|
} else {
|
||||||
// Otherwise kill any containers in this pod which are not specified as ones to keep.
|
// Otherwise kill any containers in this pod which are not specified as ones to keep.
|
||||||
for _, container := range runningPod.Containers {
|
for _, container := range runningPod.Containers {
|
||||||
_, keep := containerChanges.containersToKeep[dockertools.DockerID(container.ID)]
|
_, keep := containerChanges.containersToKeep[kubeletTypes.DockerID(container.ID)]
|
||||||
if !keep {
|
if !keep {
|
||||||
glog.V(3).Infof("Killing unwanted container %+v", container)
|
glog.V(3).Infof("Killing unwanted container %+v", container)
|
||||||
err = kl.containerManager.KillContainer(container.ID)
|
err = kl.containerManager.KillContainer(container.ID)
|
||||||
|
@@ -54,8 +54,8 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
|
||||||
|
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
||||||
utilexec "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
|
utilexec "github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
@@ -125,13 +125,13 @@ func (plugin *execNetworkPlugin) validate() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *execNetworkPlugin) SetUpPod(namespace string, name string, id dockertools.DockerID) error {
|
func (plugin *execNetworkPlugin) SetUpPod(namespace string, name string, id kubeletTypes.DockerID) error {
|
||||||
out, err := utilexec.New().Command(plugin.getExecutable(), setUpCmd, namespace, name, string(id)).CombinedOutput()
|
out, err := utilexec.New().Command(plugin.getExecutable(), setUpCmd, namespace, name, string(id)).CombinedOutput()
|
||||||
glog.V(5).Infof("SetUpPod 'exec' network plugin output: %s, %v", string(out), err)
|
glog.V(5).Infof("SetUpPod 'exec' network plugin output: %s, %v", string(out), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id dockertools.DockerID) error {
|
func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id kubeletTypes.DockerID) error {
|
||||||
out, err := utilexec.New().Command(plugin.getExecutable(), tearDownCmd, namespace, name, string(id)).CombinedOutput()
|
out, err := utilexec.New().Command(plugin.getExecutable(), tearDownCmd, namespace, name, string(id)).CombinedOutput()
|
||||||
glog.V(5).Infof("TearDownPod 'exec' network plugin output: %s, %v", string(out), err)
|
glog.V(5).Infof("TearDownPod 'exec' network plugin output: %s, %v", string(out), err)
|
||||||
return err
|
return err
|
||||||
|
@@ -22,7 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
@@ -43,10 +43,10 @@ type NetworkPlugin interface {
|
|||||||
// SetUpPod is the method called after the infra container of
|
// SetUpPod is the method called after the infra container of
|
||||||
// the pod has been created but before the other containers of the
|
// the pod has been created but before the other containers of the
|
||||||
// pod are launched.
|
// pod are launched.
|
||||||
SetUpPod(namespace string, name string, podInfraContainerID dockertools.DockerID) error
|
SetUpPod(namespace string, name string, podInfraContainerID kubeletTypes.DockerID) error
|
||||||
|
|
||||||
// TearDownPod is the method called before a pod's infra container will be deleted
|
// TearDownPod is the method called before a pod's infra container will be deleted
|
||||||
TearDownPod(namespace string, name string, podInfraContainerID dockertools.DockerID) error
|
TearDownPod(namespace string, name string, podInfraContainerID kubeletTypes.DockerID) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Host is an interface that plugins can use to access the kubelet.
|
// Host is an interface that plugins can use to access the kubelet.
|
||||||
@@ -113,10 +113,10 @@ func (plugin *noopNetworkPlugin) Name() string {
|
|||||||
return DefaultPluginName
|
return DefaultPluginName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *noopNetworkPlugin) SetUpPod(namespace string, name string, id dockertools.DockerID) error {
|
func (plugin *noopNetworkPlugin) SetUpPod(namespace string, name string, id kubeletTypes.DockerID) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *noopNetworkPlugin) TearDownPod(namespace string, name string, id dockertools.DockerID) error {
|
func (plugin *noopNetworkPlugin) TearDownPod(namespace string, name string, id kubeletTypes.DockerID) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
18
pkg/kubelet/types/doc.go
Normal file
18
pkg/kubelet/types/doc.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2015 Google Inc. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Common types in the Kubelet.
|
||||||
|
package types
|
20
pkg/kubelet/types/docker.go
Normal file
20
pkg/kubelet/types/docker.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2015 Google Inc. 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 types
|
||||||
|
|
||||||
|
// 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
|
Reference in New Issue
Block a user