Browse code

Merge pull request #31176 from adshmh/29662-stack-deploy-error-if-external-combined-with-other-volume-options

stack deploy exits with error if both 'external' and other options are specified for a volume

Sebastiaan van Stijn authored on 2017/03/11 09:59:43
Showing 2 changed files
... ...
@@ -435,9 +435,21 @@ func LoadVolumes(source types.Dict) (map[string]types.VolumeConfig, error) {
435 435
 		return volumes, err
436 436
 	}
437 437
 	for name, volume := range volumes {
438
-		if volume.External.External && volume.External.Name == "" {
439
-			volume.External.Name = name
440
-			volumes[name] = volume
438
+		if volume.External.External {
439
+			template := "conflicting parameters \"external\" and %q specified for volume %q"
440
+			if volume.Driver != "" {
441
+				return nil, fmt.Errorf(template, "driver", name)
442
+			}
443
+			if len(volume.DriverOpts) > 0 {
444
+				return nil, fmt.Errorf(template, "driver_opts", name)
445
+			}
446
+			if len(volume.Labels) > 0 {
447
+				return nil, fmt.Errorf(template, "labels", name)
448
+			}
449
+			if volume.External.Name == "" {
450
+				volume.External.Name = name
451
+				volumes[name] = volume
452
+			}
441 453
 		}
442 454
 	}
443 455
 	return volumes, nil
... ...
@@ -541,6 +541,50 @@ services:
541 541
 	assert.Contains(t, forbidden, "extends")
542 542
 }
543 543
 
544
+func TestInvalidExternalAndDriverCombination(t *testing.T) {
545
+	_, err := loadYAML(`
546
+version: "3"
547
+volumes:
548
+  external_volume:
549
+    external: true
550
+    driver: foobar
551
+`)
552
+
553
+	assert.Error(t, err)
554
+	assert.Contains(t, err.Error(), "conflicting parameters \"external\" and \"driver\" specified for volume")
555
+	assert.Contains(t, err.Error(), "external_volume")
556
+}
557
+
558
+func TestInvalidExternalAndDirverOptsCombination(t *testing.T) {
559
+	_, err := loadYAML(`
560
+version: "3"
561
+volumes:
562
+  external_volume:
563
+    external: true
564
+    driver_opts:
565
+      beep: boop
566
+`)
567
+
568
+	assert.Error(t, err)
569
+	assert.Contains(t, err.Error(), "conflicting parameters \"external\" and \"driver_opts\" specified for volume")
570
+	assert.Contains(t, err.Error(), "external_volume")
571
+}
572
+
573
+func TestInvalidExternalAndLabelsCombination(t *testing.T) {
574
+	_, err := loadYAML(`
575
+version: "3"
576
+volumes:
577
+  external_volume:
578
+    external: true
579
+    labels:
580
+      - beep=boop
581
+`)
582
+
583
+	assert.Error(t, err)
584
+	assert.Contains(t, err.Error(), "conflicting parameters \"external\" and \"labels\" specified for volume")
585
+	assert.Contains(t, err.Error(), "external_volume")
586
+}
587
+
544 588
 func durationPtr(value time.Duration) *time.Duration {
545 589
 	return &value
546 590
 }