Browse code

Fix issue where TmpfsOptions are not sent to swarm

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2016/12/03 01:43:47
Showing 2 changed files
... ...
@@ -64,6 +64,13 @@ func containerSpecFromGRPC(c *swarmapi.ContainerSpec) types.ContainerSpec {
64 64
 				}
65 65
 			}
66 66
 		}
67
+
68
+		if m.TmpfsOptions != nil {
69
+			mount.TmpfsOptions = &mounttypes.TmpfsOptions{
70
+				SizeBytes: m.TmpfsOptions.SizeBytes,
71
+				Mode:      m.TmpfsOptions.Mode,
72
+			}
73
+		}
67 74
 		containerSpec.Mounts = append(containerSpec.Mounts, mount)
68 75
 	}
69 76
 
... ...
@@ -174,9 +181,7 @@ func containerToGRPC(c types.ContainerSpec) (*swarmapi.ContainerSpec, error) {
174 174
 				mount.BindOptions = &swarmapi.Mount_BindOptions{Propagation: swarmapi.Mount_BindOptions_MountPropagation(mountPropagation)}
175 175
 			} else if string(m.BindOptions.Propagation) != "" {
176 176
 				return nil, fmt.Errorf("invalid MountPropagation: %q", m.BindOptions.Propagation)
177
-
178 177
 			}
179
-
180 178
 		}
181 179
 
182 180
 		if m.VolumeOptions != nil {
... ...
@@ -192,6 +197,13 @@ func containerToGRPC(c types.ContainerSpec) (*swarmapi.ContainerSpec, error) {
192 192
 			}
193 193
 		}
194 194
 
195
+		if m.TmpfsOptions != nil {
196
+			mount.TmpfsOptions = &swarmapi.Mount_TmpfsOptions{
197
+				SizeBytes: m.TmpfsOptions.SizeBytes,
198
+				Mode:      m.TmpfsOptions.Mode,
199
+			}
200
+		}
201
+
195 202
 		containerSpec.Mounts = append(containerSpec.Mounts, mount)
196 203
 	}
197 204
 
... ...
@@ -123,7 +123,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTarget(c *check.C) {
123 123
 
124 124
 func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) {
125 125
 	d := s.AddDaemon(c, true, true)
126
-	out, err := d.Cmd("service", "create", "--mount", "type=tmpfs,target=/foo", "busybox", "sh", "-c", "mount | grep foo; tail -f /dev/null")
126
+	out, err := d.Cmd("service", "create", "--mount", "type=tmpfs,target=/foo,tmpfs-size=1MB", "busybox", "sh", "-c", "mount | grep foo; tail -f /dev/null")
127 127
 	c.Assert(err, checker.IsNil, check.Commentf(out))
128 128
 	id := strings.TrimSpace(out)
129 129
 
... ...
@@ -152,6 +152,8 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) {
152 152
 	c.Assert(mountConfig[0].Source, checker.Equals, "")
153 153
 	c.Assert(mountConfig[0].Target, checker.Equals, "/foo")
154 154
 	c.Assert(mountConfig[0].Type, checker.Equals, mount.TypeTmpfs)
155
+	c.Assert(mountConfig[0].TmpfsOptions, checker.NotNil)
156
+	c.Assert(mountConfig[0].TmpfsOptions.SizeBytes, checker.Equals, int64(1048576))
155 157
 
156 158
 	// check container mounts actual
157 159
 	out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
... ...
@@ -169,4 +171,5 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) {
169 169
 	out, err = s.nodeCmd(c, task.NodeID, "logs", task.Status.ContainerStatus.ContainerID)
170 170
 	c.Assert(err, checker.IsNil, check.Commentf(out))
171 171
 	c.Assert(strings.TrimSpace(out), checker.HasPrefix, "tmpfs on /foo type tmpfs")
172
+	c.Assert(strings.TrimSpace(out), checker.Contains, "size=1024k")
172 173
 }