mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-13 05:02:50 +00:00
Remove deprecated bits from kubelet
This commit is contained in:
@@ -198,29 +198,20 @@ func makeEnvironmentVariables(container *api.Container) []string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeVolumesAndBinds(pod *Pod, container *api.Container, podVolumes volumeMap) (map[string]struct{}, []string) {
|
func makeBinds(pod *Pod, container *api.Container, podVolumes volumeMap) []string {
|
||||||
volumes := map[string]struct{}{}
|
|
||||||
binds := []string{}
|
binds := []string{}
|
||||||
for _, volume := range container.VolumeMounts {
|
for _, mount := range container.VolumeMounts {
|
||||||
var basePath string
|
vol, ok := podVolumes[mount.Name]
|
||||||
if vol, ok := podVolumes[volume.Name]; ok {
|
if !ok {
|
||||||
// Host volumes are not Docker volumes and are directly mounted from the host.
|
continue
|
||||||
basePath = fmt.Sprintf("%s:%s", vol.GetPath(), volume.MountPath)
|
|
||||||
} else if volume.MountType == "HOST" {
|
|
||||||
// DEPRECATED: VolumeMount.MountType will be handled by the Volume struct.
|
|
||||||
basePath = fmt.Sprintf("%s:%s", volume.MountPath, volume.MountPath)
|
|
||||||
} else {
|
|
||||||
// TODO(jonesdl) This clause should be deleted and an error should be thrown. The default
|
|
||||||
// behavior is now supported by the EmptyDirectory type.
|
|
||||||
volumes[volume.MountPath] = struct{}{}
|
|
||||||
basePath = fmt.Sprintf("/exports/%s/%s:%s", GetPodFullName(pod), volume.Name, volume.MountPath)
|
|
||||||
}
|
}
|
||||||
if volume.ReadOnly {
|
b := fmt.Sprintf("%s:%s", vol.GetPath(), mount.MountPath)
|
||||||
basePath += ":ro"
|
if mount.ReadOnly {
|
||||||
|
b += ":ro"
|
||||||
}
|
}
|
||||||
binds = append(binds, basePath)
|
binds = append(binds, b)
|
||||||
}
|
}
|
||||||
return volumes, binds
|
return binds
|
||||||
}
|
}
|
||||||
|
|
||||||
func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, map[docker.Port][]docker.PortBinding) {
|
func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, map[docker.Port][]docker.PortBinding) {
|
||||||
@@ -294,7 +285,7 @@ func (kl *Kubelet) mountExternalVolumes(manifest *api.ContainerManifest) (volume
|
|||||||
// 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 (kl *Kubelet) runContainer(pod *Pod, container *api.Container, podVolumes volumeMap, netMode string) (id DockerID, err error) {
|
func (kl *Kubelet) runContainer(pod *Pod, container *api.Container, podVolumes volumeMap, netMode string) (id DockerID, err error) {
|
||||||
envVariables := makeEnvironmentVariables(container)
|
envVariables := makeEnvironmentVariables(container)
|
||||||
volumes, binds := makeVolumesAndBinds(pod, container, podVolumes)
|
binds := makeBinds(pod, container, podVolumes)
|
||||||
exposedPorts, portBindings := makePortsAndBindings(container)
|
exposedPorts, portBindings := makePortsAndBindings(container)
|
||||||
|
|
||||||
opts := docker.CreateContainerOptions{
|
opts := docker.CreateContainerOptions{
|
||||||
@@ -307,7 +298,6 @@ func (kl *Kubelet) runContainer(pod *Pod, container *api.Container, podVolumes v
|
|||||||
Image: container.Image,
|
Image: container.Image,
|
||||||
Memory: int64(container.Memory),
|
Memory: int64(container.Memory),
|
||||||
CpuShares: int64(milliCPUToShares(container.CPU)),
|
CpuShares: int64(milliCPUToShares(container.CPU)),
|
||||||
Volumes: volumes,
|
|
||||||
WorkingDir: container.WorkingDir,
|
WorkingDir: container.WorkingDir,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -671,17 +671,10 @@ func TestMakeVolumesAndBinds(t *testing.T) {
|
|||||||
Name: "disk",
|
Name: "disk",
|
||||||
ReadOnly: false,
|
ReadOnly: false,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
MountPath: "/mnt/path2",
|
|
||||||
Name: "disk2",
|
|
||||||
ReadOnly: true,
|
|
||||||
MountType: "LOCAL",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
MountPath: "/mnt/path3",
|
MountPath: "/mnt/path3",
|
||||||
Name: "disk3",
|
Name: "disk",
|
||||||
ReadOnly: false,
|
ReadOnly: true,
|
||||||
MountType: "HOST",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MountPath: "/mnt/path4",
|
MountPath: "/mnt/path4",
|
||||||
@@ -701,24 +694,21 @@ func TestMakeVolumesAndBinds(t *testing.T) {
|
|||||||
Namespace: "test",
|
Namespace: "test",
|
||||||
}
|
}
|
||||||
|
|
||||||
podVolumes := make(volumeMap)
|
podVolumes := volumeMap{
|
||||||
podVolumes["disk4"] = &volume.HostDirectory{"/mnt/host"}
|
"disk": &volume.HostDirectory{"/mnt/disk"},
|
||||||
podVolumes["disk5"] = &volume.EmptyDirectory{"disk5", "podID", "/var/lib/kubelet"}
|
"disk4": &volume.HostDirectory{"/mnt/host"},
|
||||||
|
"disk5": &volume.EmptyDirectory{"disk5", "podID", "/var/lib/kubelet"},
|
||||||
volumes, binds := makeVolumesAndBinds(&pod, &container, podVolumes)
|
|
||||||
|
|
||||||
expectedVolumes := []string{"/mnt/path", "/mnt/path2"}
|
|
||||||
expectedBinds := []string{"/exports/pod.test/disk:/mnt/path", "/exports/pod.test/disk2:/mnt/path2:ro", "/mnt/path3:/mnt/path3",
|
|
||||||
"/mnt/host:/mnt/path4", "/var/lib/kubelet/podID/volumes/empty/disk5:/mnt/path5"}
|
|
||||||
|
|
||||||
if len(volumes) != len(expectedVolumes) {
|
|
||||||
t.Errorf("Unexpected volumes. Expected %#v got %#v. Container was: %#v", expectedVolumes, volumes, container)
|
|
||||||
}
|
}
|
||||||
for _, expectedVolume := range expectedVolumes {
|
|
||||||
if _, ok := volumes[expectedVolume]; !ok {
|
binds := makeBinds(&pod, &container, podVolumes)
|
||||||
t.Errorf("Volumes map is missing key: %s. %#v", expectedVolume, volumes)
|
|
||||||
}
|
expectedBinds := []string{
|
||||||
|
"/mnt/disk:/mnt/path",
|
||||||
|
"/mnt/disk:/mnt/path3:ro",
|
||||||
|
"/mnt/host:/mnt/path4",
|
||||||
|
"/var/lib/kubelet/podID/volumes/empty/disk5:/mnt/path5",
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(binds) != len(expectedBinds) {
|
if len(binds) != len(expectedBinds) {
|
||||||
t.Errorf("Unexpected binds: Expected %#v got %#v. Container was: %#v", expectedBinds, binds, container)
|
t.Errorf("Unexpected binds: Expected %#v got %#v. Container was: %#v", expectedBinds, binds, container)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user