Browse Source

Fix panic due to nil bind options

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 4c2e1a9cb04614d360e91a81959cb196380283b1)
Brian Goff 9 years ago
parent
commit
5ff054ef51
1 changed files with 8 additions and 1 deletions
  1. 8 1
      api/client/service/opts.go

+ 8 - 1
api/client/service/opts.go

@@ -160,6 +160,13 @@ func (m *MountOpt) Set(value string) error {
 		return mount.VolumeOptions
 		return mount.VolumeOptions
 	}
 	}
 
 
+	bindOptions := func() *swarm.BindOptions {
+		if mount.BindOptions == nil {
+			mount.BindOptions = new(swarm.BindOptions)
+		}
+		return mount.BindOptions
+	}
+
 	setValueOnMap := func(target map[string]string, value string) {
 	setValueOnMap := func(target map[string]string, value string) {
 		parts := strings.SplitN(value, "=", 2)
 		parts := strings.SplitN(value, "=", 2)
 		if len(parts) == 1 {
 		if len(parts) == 1 {
@@ -194,7 +201,7 @@ func (m *MountOpt) Set(value string) error {
 				return fmt.Errorf("invalid value for writable: %s", value)
 				return fmt.Errorf("invalid value for writable: %s", value)
 			}
 			}
 		case "bind-propagation":
 		case "bind-propagation":
-			mount.BindOptions.Propagation = swarm.MountPropagation(strings.ToUpper(value))
+			bindOptions().Propagation = swarm.MountPropagation(strings.ToUpper(value))
 		case "volume-populate":
 		case "volume-populate":
 			volumeOptions().Populate, err = strconv.ParseBool(value)
 			volumeOptions().Populate, err = strconv.ParseBool(value)
 			if err != nil {
 			if err != nil {