Commit ce15f0e8 authored by Yifan Gu's avatar Yifan Gu

rkt: Refactoring the construction of the mount points.

So that at most one volume object will be created for every unique host path. Also the volume's name is random generated UUID to avoid collision since the mount point's name passed by kubelet is not guaranteed to be unique when 'subpath' is specified.
parent c8591c71
...@@ -342,6 +342,8 @@ type EnvVar struct { ...@@ -342,6 +342,8 @@ type EnvVar struct {
type Mount struct { type Mount struct {
// Name of the volume mount. // Name of the volume mount.
// TODO(yifan): Remove this field, as this is not representing the unique name of the mount,
// but the volume name only.
Name string Name string
// Path of the mount within the container. // Path of the mount within the container.
ContainerPath string ContainerPath string
......
...@@ -949,7 +949,9 @@ func TestSetApp(t *testing.T) { ...@@ -949,7 +949,9 @@ func TestSetApp(t *testing.T) {
tests := []struct { tests := []struct {
container *api.Container container *api.Container
opts *kubecontainer.RunContainerOptions mountPoints []appctypes.MountPoint
containerPorts []appctypes.Port
envs []kubecontainer.EnvVar
ctx *api.SecurityContext ctx *api.SecurityContext
podCtx *api.PodSecurityContext podCtx *api.PodSecurityContext
supplementalGids []int64 supplementalGids []int64
...@@ -959,7 +961,9 @@ func TestSetApp(t *testing.T) { ...@@ -959,7 +961,9 @@ func TestSetApp(t *testing.T) {
// Nothing should change, but the "User" and "Group" should be filled. // Nothing should change, but the "User" and "Group" should be filled.
{ {
container: &api.Container{}, container: &api.Container{},
opts: &kubecontainer.RunContainerOptions{}, mountPoints: []appctypes.MountPoint{},
containerPorts: []appctypes.Port{},
envs: []kubecontainer.EnvVar{},
ctx: nil, ctx: nil,
podCtx: nil, podCtx: nil,
supplementalGids: nil, supplementalGids: nil,
...@@ -969,8 +973,10 @@ func TestSetApp(t *testing.T) { ...@@ -969,8 +973,10 @@ func TestSetApp(t *testing.T) {
// error verifying non-root. // error verifying non-root.
{ {
container: &api.Container{}, container: &api.Container{},
opts: &kubecontainer.RunContainerOptions{}, mountPoints: []appctypes.MountPoint{},
containerPorts: []appctypes.Port{},
envs: []kubecontainer.EnvVar{},
ctx: &api.SecurityContext{ ctx: &api.SecurityContext{
RunAsNonRoot: &runAsNonRootTrue, RunAsNonRoot: &runAsNonRootTrue,
RunAsUser: &rootUser, RunAsUser: &rootUser,
...@@ -986,7 +992,9 @@ func TestSetApp(t *testing.T) { ...@@ -986,7 +992,9 @@ func TestSetApp(t *testing.T) {
container: &api.Container{ container: &api.Container{
Args: []string{"foo"}, Args: []string{"foo"},
}, },
opts: &kubecontainer.RunContainerOptions{}, mountPoints: []appctypes.MountPoint{},
containerPorts: []appctypes.Port{},
envs: []kubecontainer.EnvVar{},
ctx: nil, ctx: nil,
podCtx: nil, podCtx: nil,
supplementalGids: nil, supplementalGids: nil,
...@@ -1025,16 +1033,14 @@ func TestSetApp(t *testing.T) { ...@@ -1025,16 +1033,14 @@ func TestSetApp(t *testing.T) {
Requests: api.ResourceList{"cpu": resource.MustParse("5m"), "memory": resource.MustParse("5M")}, Requests: api.ResourceList{"cpu": resource.MustParse("5m"), "memory": resource.MustParse("5M")},
}, },
}, },
opts: &kubecontainer.RunContainerOptions{ mountPoints: []appctypes.MountPoint{
Envs: []kubecontainer.EnvVar{ {Name: *appctypes.MustACName("mnt-bar"), Path: "/mnt-bar", ReadOnly: true},
{Name: "env-bar", Value: "foo"}, },
}, containerPorts: []appctypes.Port{
Mounts: []kubecontainer.Mount{ {Name: *appctypes.MustACName("port-bar"), Protocol: "TCP", Port: 1234},
{Name: "mnt-bar", ContainerPath: "/mnt-bar", ReadOnly: true}, },
}, envs: []kubecontainer.EnvVar{
PortMappings: []kubecontainer.PortMapping{ {Name: "env-bar", Value: "foo"},
{Name: "port-bar", Protocol: api.ProtocolTCP, ContainerPort: 1234},
},
}, },
ctx: &api.SecurityContext{ ctx: &api.SecurityContext{
Capabilities: &api.Capabilities{ Capabilities: &api.Capabilities{
...@@ -1088,17 +1094,15 @@ func TestSetApp(t *testing.T) { ...@@ -1088,17 +1094,15 @@ func TestSetApp(t *testing.T) {
Requests: api.ResourceList{"memory": resource.MustParse("5M")}, Requests: api.ResourceList{"memory": resource.MustParse("5M")},
}, },
}, },
opts: &kubecontainer.RunContainerOptions{ mountPoints: []appctypes.MountPoint{
Envs: []kubecontainer.EnvVar{ {Name: *appctypes.MustACName("mnt-foo"), Path: "/mnt-foo", ReadOnly: true},
{Name: "env-foo", Value: "foo"}, },
{Name: "env-bar", Value: "bar"}, containerPorts: []appctypes.Port{
}, {Name: *appctypes.MustACName("port-foo"), Protocol: "TCP", Port: 1234},
Mounts: []kubecontainer.Mount{ },
{Name: "mnt-foo", ContainerPath: "/mnt-bar", ReadOnly: true}, envs: []kubecontainer.EnvVar{
}, {Name: "env-foo", Value: "foo"},
PortMappings: []kubecontainer.PortMapping{ {Name: "env-bar", Value: "bar"},
{Name: "port-foo", Protocol: api.ProtocolTCP, ContainerPort: 1234},
},
}, },
ctx: &api.SecurityContext{ ctx: &api.SecurityContext{
Capabilities: &api.Capabilities{ Capabilities: &api.Capabilities{
...@@ -1124,7 +1128,7 @@ func TestSetApp(t *testing.T) { ...@@ -1124,7 +1128,7 @@ func TestSetApp(t *testing.T) {
{Name: "env-bar", Value: "bar"}, {Name: "env-bar", Value: "bar"},
}, },
MountPoints: []appctypes.MountPoint{ MountPoints: []appctypes.MountPoint{
{Name: *appctypes.MustACName("mnt-foo"), Path: "/mnt-bar", ReadOnly: true}, {Name: *appctypes.MustACName("mnt-foo"), Path: "/mnt-foo", ReadOnly: true},
}, },
Ports: []appctypes.Port{ Ports: []appctypes.Port{
{Name: *appctypes.MustACName("port-foo"), Protocol: "TCP", Port: 1234}, {Name: *appctypes.MustACName("port-foo"), Protocol: "TCP", Port: 1234},
...@@ -1142,7 +1146,11 @@ func TestSetApp(t *testing.T) { ...@@ -1142,7 +1146,11 @@ func TestSetApp(t *testing.T) {
for i, tt := range tests { for i, tt := range tests {
testCaseHint := fmt.Sprintf("test case #%d", i) testCaseHint := fmt.Sprintf("test case #%d", i)
img := baseImageManifest(t) img := baseImageManifest(t)
err := setApp(img, tt.container, tt.opts, tt.ctx, tt.podCtx, tt.supplementalGids)
err := setApp(img, tt.container,
tt.mountPoints, tt.containerPorts, tt.envs,
tt.ctx, tt.podCtx, tt.supplementalGids)
if err == nil && tt.err != nil || err != nil && tt.err == nil { if err == nil && tt.err != nil || err != nil && tt.err == nil {
t.Errorf("%s: expect %v, saw %v", testCaseHint, tt.err, err) t.Errorf("%s: expect %v, saw %v", testCaseHint, tt.err, err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment