mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
kubelet/container: Move kubelet.volumeMap to container.VolumeMap.
This is a quick fix to solve circular dependency problem when rkt references volume maps.
This commit is contained in:
parent
d6ea33fbb5
commit
8715c54bd3
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Version interface {
|
type Version interface {
|
||||||
@ -205,6 +206,8 @@ type RunContainerOptions struct {
|
|||||||
CgroupParent string
|
CgroupParent string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VolumeMap map[string]volume.Volume
|
||||||
|
|
||||||
type Pods []*Pod
|
type Pods []*Pod
|
||||||
|
|
||||||
// FindPodByID finds and returns a pod in the pod list by UID. It will return an empty pod
|
// FindPodByID finds and returns a pod in the pod list by UID. It will return an empty pod
|
||||||
|
@ -93,8 +93,6 @@ type SyncHandler interface {
|
|||||||
|
|
||||||
type SourcesReadyFn func() bool
|
type SourcesReadyFn func() bool
|
||||||
|
|
||||||
type volumeMap map[string]volume.Volume
|
|
||||||
|
|
||||||
// Wait for the container runtime to be up with a timeout.
|
// Wait for the container runtime to be up with a timeout.
|
||||||
func waitUntilRuntimeIsUp(cr kubecontainer.Runtime, timeout time.Duration) error {
|
func waitUntilRuntimeIsUp(cr kubecontainer.Runtime, timeout time.Duration) error {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
@ -645,7 +643,7 @@ func (kl *Kubelet) syncNodeStatus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeBinds(container *api.Container, podVolumes volumeMap) (binds []string) {
|
func makeBinds(container *api.Container, podVolumes kubecontainer.VolumeMap) (binds []string) {
|
||||||
for _, mount := range container.VolumeMounts {
|
for _, mount := range container.VolumeMounts {
|
||||||
vol, ok := podVolumes[mount.Name]
|
vol, ok := podVolumes[mount.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -1307,7 +1307,7 @@ func TestMakeVolumesAndBinds(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
podVolumes := volumeMap{
|
podVolumes := kubecontainer.VolumeMap{
|
||||||
"disk": &stubVolume{"/mnt/disk"},
|
"disk": &stubVolume{"/mnt/disk"},
|
||||||
"disk4": &stubVolume{"/mnt/host"},
|
"disk4": &stubVolume{"/mnt/host"},
|
||||||
"disk5": &stubVolume{"/var/lib/kubelet/podID/volumes/empty/disk5"},
|
"disk5": &stubVolume{"/var/lib/kubelet/podID/volumes/empty/disk5"},
|
||||||
@ -3990,7 +3990,7 @@ func TestGetPodCreationFailureReason(t *testing.T) {
|
|||||||
}
|
}
|
||||||
pods := []*api.Pod{pod}
|
pods := []*api.Pod{pod}
|
||||||
kubelet.podManager.SetPods(pods)
|
kubelet.podManager.SetPods(pods)
|
||||||
kubelet.volumeManager.SetVolumes(pod.UID, volumeMap{})
|
kubelet.volumeManager.SetVolumes(pod.UID, kubecontainer.VolumeMap{})
|
||||||
// TODO: Move this test to dockertools so that we don't have to do the hacky
|
// TODO: Move this test to dockertools so that we don't have to do the hacky
|
||||||
// type assertion here.
|
// type assertion here.
|
||||||
dm := kubelet.containerRuntime.(*dockertools.DockerManager)
|
dm := kubelet.containerRuntime.(*dockertools.DockerManager)
|
||||||
|
@ -19,6 +19,7 @@ package kubelet
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,18 +28,18 @@ import (
|
|||||||
// take care of the volumePlugins.
|
// take care of the volumePlugins.
|
||||||
type volumeManager struct {
|
type volumeManager struct {
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
volumeMaps map[types.UID]volumeMap
|
volumeMaps map[types.UID]kubecontainer.VolumeMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func newVolumeManager() *volumeManager {
|
func newVolumeManager() *volumeManager {
|
||||||
vm := &volumeManager{}
|
vm := &volumeManager{}
|
||||||
vm.volumeMaps = make(map[types.UID]volumeMap)
|
vm.volumeMaps = make(map[types.UID]kubecontainer.VolumeMap)
|
||||||
return vm
|
return vm
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVolumes sets the volume map for a pod.
|
// SetVolumes sets the volume map for a pod.
|
||||||
// TODO(yifan): Currently we assume the volume is already mounted, so we only do a book keeping here.
|
// TODO(yifan): Currently we assume the volume is already mounted, so we only do a book keeping here.
|
||||||
func (vm *volumeManager) SetVolumes(podUID types.UID, podVolumes volumeMap) {
|
func (vm *volumeManager) SetVolumes(podUID types.UID, podVolumes kubecontainer.VolumeMap) {
|
||||||
vm.lock.Lock()
|
vm.lock.Lock()
|
||||||
defer vm.lock.Unlock()
|
defer vm.lock.Unlock()
|
||||||
vm.volumeMaps[podUID] = podVolumes
|
vm.volumeMaps[podUID] = podVolumes
|
||||||
@ -46,7 +47,7 @@ func (vm *volumeManager) SetVolumes(podUID types.UID, podVolumes volumeMap) {
|
|||||||
|
|
||||||
// GetVolumes returns the volume map which are already mounted on the host machine
|
// GetVolumes returns the volume map which are already mounted on the host machine
|
||||||
// for a pod.
|
// for a pod.
|
||||||
func (vm *volumeManager) GetVolumes(podUID types.UID) (volumeMap, bool) {
|
func (vm *volumeManager) GetVolumes(podUID types.UID) (kubecontainer.VolumeMap, bool) {
|
||||||
vm.lock.RLock()
|
vm.lock.RLock()
|
||||||
defer vm.lock.RUnlock()
|
defer vm.lock.RUnlock()
|
||||||
vol, ok := vm.volumeMaps[podUID]
|
vol, ok := vm.volumeMaps[podUID]
|
||||||
|
@ -23,6 +23,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"
|
||||||
|
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
||||||
"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/GoogleCloudPlatform/kubernetes/pkg/util/mount"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
|
||||||
@ -96,8 +97,8 @@ func (kl *Kubelet) newVolumeBuilderFromPlugins(spec *volume.Spec, podRef *api.Ob
|
|||||||
return builder, nil
|
return builder, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kl *Kubelet) mountExternalVolumes(pod *api.Pod) (volumeMap, error) {
|
func (kl *Kubelet) mountExternalVolumes(pod *api.Pod) (kubecontainer.VolumeMap, error) {
|
||||||
podVolumes := make(volumeMap)
|
podVolumes := make(kubecontainer.VolumeMap)
|
||||||
for i := range pod.Spec.Volumes {
|
for i := range pod.Spec.Volumes {
|
||||||
volSpec := &pod.Spec.Volumes[i]
|
volSpec := &pod.Spec.Volumes[i]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user