Skip to content

Commit 593b777

Browse files
committed
make External a boolean
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 7210cee commit 593b777

File tree

10 files changed

+38
-156
lines changed

10 files changed

+38
-156
lines changed

loader/full-struct_test.go

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,12 @@ func networks() map[string]types.NetworkConfig {
482482
},
483483

484484
"external-network": {
485-
Name: "external-network",
486-
External: types.External{External: true},
485+
External: true,
487486
},
488487

489488
"other-external-network": {
490489
Name: "my-cool-network",
491-
External: types.External{External: true},
490+
External: true,
492491
Extensions: map[string]interface{}{
493492
"x-bar": "baz",
494493
"x-foo": "bar",
@@ -519,16 +518,15 @@ func volumes() map[string]types.VolumeConfig {
519518
},
520519
},
521520
"external-volume": {
522-
Name: "external-volume",
523-
External: types.External{External: true},
521+
External: true,
524522
},
525523
"other-external-volume": {
526524
Name: "my-cool-volume",
527-
External: types.External{External: true},
525+
External: true,
528526
},
529527
"external-volume3": {
530528
Name: "this-is-volume3",
531-
External: types.External{External: true},
529+
External: true,
532530
Extensions: map[string]interface{}{
533531
"x-bar": "baz",
534532
"x-foo": "bar",
@@ -547,11 +545,10 @@ func configs(workingDir string, homeDir string) map[string]types.ConfigObjConfig
547545
},
548546
"config2": {
549547
Name: "my_config",
550-
External: types.External{External: true},
548+
External: true,
551549
},
552550
"config3": {
553-
Name: "config3",
554-
External: types.External{External: true},
551+
External: true,
555552
},
556553
"config4": {
557554
Name: "foo",
@@ -574,11 +571,10 @@ func secrets(workingDir string) map[string]types.SecretConfig {
574571
},
575572
"secret2": {
576573
Name: "my_secret",
577-
External: types.External{External: true},
574+
External: true,
578575
},
579576
"secret3": {
580-
Name: "secret3",
581-
External: types.External{External: true},
577+
External: true,
582578
},
583579
"secret4": {
584580
Name: "bar",
@@ -948,7 +944,6 @@ services:
948944
x-foo: bar
949945
networks:
950946
external-network:
951-
name: external-network
952947
external: true
953948
other-external-network:
954949
name: my-cool-network
@@ -983,7 +978,6 @@ volumes:
983978
baz: "1"
984979
foo: bar
985980
external-volume:
986-
name: external-volume
987981
external: true
988982
external-volume3:
989983
name: this-is-volume3
@@ -1010,7 +1004,6 @@ secrets:
10101004
name: my_secret
10111005
external: true
10121006
secret3:
1013-
name: secret3
10141007
external: true
10151008
secret4:
10161009
name: bar
@@ -1028,7 +1021,6 @@ configs:
10281021
name: my_config
10291022
external: true
10301023
config3:
1031-
name: config3
10321024
external: true
10331025
config4:
10341026
name: foo
@@ -1060,7 +1052,6 @@ func fullExampleJSON(workingDir, homeDir string) string {
10601052
"configs": {
10611053
"config1": {
10621054
"file": "%s",
1063-
"external": false,
10641055
"labels": {
10651056
"foo": "bar"
10661057
}
@@ -1070,19 +1061,16 @@ func fullExampleJSON(workingDir, homeDir string) string {
10701061
"external": true
10711062
},
10721063
"config3": {
1073-
"name": "config3",
10741064
"external": true
10751065
},
10761066
"config4": {
10771067
"name": "foo",
1078-
"file": "%s",
1079-
"external": false
1068+
"file": "%s"
10801069
}
10811070
},
10821071
"name": "full_example_project_name",
10831072
"networks": {
10841073
"external-network": {
1085-
"name": "external-network",
10861074
"ipam": {},
10871075
"external": true
10881076
},
@@ -1116,20 +1104,17 @@ func fullExampleJSON(workingDir, homeDir string) string {
11161104
}
11171105
]
11181106
},
1119-
"external": false,
11201107
"labels": {
11211108
"foo": "bar"
11221109
}
11231110
},
11241111
"some-network": {
1125-
"ipam": {},
1126-
"external": false
1112+
"ipam": {}
11271113
}
11281114
},
11291115
"secrets": {
11301116
"secret1": {
11311117
"file": "%s",
1132-
"external": false,
11331118
"labels": {
11341119
"foo": "bar"
11351120
}
@@ -1139,17 +1124,14 @@ func fullExampleJSON(workingDir, homeDir string) string {
11391124
"external": true
11401125
},
11411126
"secret3": {
1142-
"name": "secret3",
11431127
"external": true
11441128
},
11451129
"secret4": {
11461130
"name": "bar",
1147-
"environment": "BAR",
1148-
"external": false
1131+
"environment": "BAR"
11491132
},
11501133
"secret5": {
1151-
"file": "/abs/secret_data",
1152-
"external": false
1134+
"file": "/abs/secret_data"
11531135
}
11541136
},
11551137
"services": {
@@ -1653,11 +1635,9 @@ func fullExampleJSON(workingDir, homeDir string) string {
16531635
"driver_opts": {
16541636
"baz": "1",
16551637
"foo": "bar"
1656-
},
1657-
"external": false
1638+
}
16581639
},
16591640
"external-volume": {
1660-
"name": "external-volume",
16611641
"external": true
16621642
},
16631643
"external-volume3": {
@@ -1674,14 +1654,11 @@ func fullExampleJSON(workingDir, homeDir string) string {
16741654
"baz": "1",
16751655
"foo": "bar"
16761656
},
1677-
"external": false,
16781657
"labels": {
16791658
"foo": "bar"
16801659
}
16811660
},
1682-
"some-volume": {
1683-
"external": false
1684-
}
1661+
"some-volume": {}
16851662
},
16861663
"x-bar": "baz",
16871664
"x-foo": "bar",

loader/loader_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -859,19 +859,18 @@ networks:
859859
},
860860
},
861861
Configs: map[string]types.ConfigObjConfig{
862-
"appconfig": {External: types.External{External: true}, Name: "appconfig"},
862+
"appconfig": {External: true},
863863
},
864864
Secrets: map[string]types.SecretConfig{
865-
"super": {External: types.External{External: true}, Name: "super"},
865+
"super": {External: true},
866866
},
867867
Volumes: map[string]types.VolumeConfig{
868-
"data": {External: types.External{External: true}, Name: "data"},
868+
"data": {External: true},
869869
},
870870
Networks: map[string]types.NetworkConfig{
871871
"back": {},
872872
"front": {
873-
External: types.External{External: true},
874-
Name: "front",
873+
External: true,
875874
Internal: true,
876875
Attachable: true,
877876
},
@@ -1455,7 +1454,7 @@ volumes:
14551454
expected := types.Volumes{
14561455
"foo": {
14571456
Name: "oops",
1458-
External: types.External{External: true},
1457+
External: true,
14591458
},
14601459
}
14611460
assert.Check(t, is.DeepEqual(expected, project.Volumes))
@@ -1514,7 +1513,7 @@ secrets:
15141513
expected := types.Secrets{
15151514
"foo": {
15161515
Name: "oops",
1517-
External: types.External{External: true},
1516+
External: true,
15181517
},
15191518
}
15201519
assert.Check(t, is.DeepEqual(expected, project.Secrets))
@@ -1537,7 +1536,7 @@ networks:
15371536
expected := types.Networks{
15381537
"foo": {
15391538
Name: "oops",
1540-
External: types.External{External: true},
1539+
External: true,
15411540
},
15421541
}
15431542
assert.Check(t, is.DeepEqual(expected, project.Networks))
@@ -1805,14 +1804,14 @@ secrets:
18051804
Configs: map[string]types.ConfigObjConfig{
18061805
"config": {
18071806
Name: "config",
1808-
External: types.External{External: true},
1807+
External: true,
18091808
TemplateDriver: "config-driver",
18101809
},
18111810
},
18121811
Secrets: map[string]types.SecretConfig{
18131812
"secret": {
18141813
Name: "secret",
1815-
External: types.External{External: true},
1814+
External: true,
18161815
TemplateDriver: "secret-driver",
18171816
},
18181817
},
@@ -1874,7 +1873,7 @@ secrets:
18741873
Configs: map[string]types.ConfigObjConfig{
18751874
"config": {
18761875
Name: "config",
1877-
External: types.External{External: true},
1876+
External: true,
18781877
},
18791878
},
18801879
Secrets: map[string]types.SecretConfig{

loader/normalize.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ func Normalize(project *types.Project) error {
3737
project.Networks["default"] = types.NetworkConfig{}
3838
}
3939

40-
if err := relocateExternalName(project); err != nil {
41-
return err
42-
}
43-
4440
for i, s := range project.Services {
4541
if len(s.Networks) == 0 && s.NetworkMode == "" {
4642
// Service without explicit network attachment are implicitly exposed on default network
@@ -224,49 +220,6 @@ func setNameFromKey(project *types.Project) {
224220
}
225221
}
226222

227-
func relocateExternalName(project *types.Project) error {
228-
for i, n := range project.Networks {
229-
if n.External.Name != "" {
230-
if n.Name != "" {
231-
return errors.Wrap(errdefs.ErrInvalid, "can't use both 'networks.external.name' (deprecated) and 'networks.name'")
232-
}
233-
n.Name = n.External.Name
234-
}
235-
project.Networks[i] = n
236-
}
237-
238-
for i, v := range project.Volumes {
239-
if v.External.Name != "" {
240-
if v.Name != "" {
241-
return errors.Wrap(errdefs.ErrInvalid, "can't use both 'volumes.external.name' (deprecated) and 'volumes.name'")
242-
}
243-
v.Name = v.External.Name
244-
}
245-
project.Volumes[i] = v
246-
}
247-
248-
for i, s := range project.Secrets {
249-
if s.External.Name != "" {
250-
if s.Name != "" {
251-
return errors.Wrap(errdefs.ErrInvalid, "can't use both 'secrets.external.name' (deprecated) and 'secrets.name'")
252-
}
253-
s.Name = s.External.Name
254-
}
255-
project.Secrets[i] = s
256-
}
257-
258-
for i, c := range project.Configs {
259-
if c.External.Name != "" {
260-
if c.Name != "" {
261-
return errors.Wrap(errdefs.ErrInvalid, "can't use both 'configs.external.name' (deprecated) and 'configs.name'")
262-
}
263-
c.Name = c.External.Name
264-
}
265-
project.Configs[i] = c
266-
}
267-
return nil
268-
}
269-
270223
func relocateLogOpt(s *types.ServiceConfig) error {
271224
if len(s.LogOpt) != 0 {
272225
logrus.Warn("`log_opts` is deprecated. Use the `logging` element")

loader/normalize_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestNormalizeNetworkNames(t *testing.T) {
3535
Networks: types.Networks{
3636
"myExternalnet": {
3737
Name: "myExternalnet", // this is automaticaly setup by loader for externa networks before reaching normalization
38-
External: types.External{External: true},
38+
External: true,
3939
},
4040
"mynet": {},
4141
"myNamedNet": {
@@ -92,7 +92,7 @@ func TestNormalizeVolumes(t *testing.T) {
9292
Volumes: types.Volumes{
9393
"myExternalVol": {
9494
Name: "myExternalVol", // this is automaticaly setup by loader for externa networks before reaching normalization
95-
External: types.External{External: true},
95+
External: true,
9696
},
9797
"myvol": {},
9898
"myNamedVol": {
@@ -107,7 +107,7 @@ func TestNormalizeVolumes(t *testing.T) {
107107
Volumes: types.Volumes{
108108
"myExternalVol": {
109109
Name: "myExternalVol",
110-
External: types.External{External: true},
110+
External: true,
111111
},
112112
"myvol": {Name: "myProject_myvol"},
113113
"myNamedVol": {

loader/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func checkConsistency(project *types.Project) error {
117117
}
118118

119119
for name, secret := range project.Secrets {
120-
if secret.External.External {
120+
if secret.External {
121121
continue
122122
}
123123
if secret.File == "" && secret.Environment == "" {

loader/validate_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func TestValidateSecret(t *testing.T) {
185185
project := &types.Project{
186186
Secrets: types.Secrets{
187187
"foo": types.SecretConfig{
188-
External: types.External{External: true},
188+
External: true,
189189
},
190190
},
191191
}
@@ -206,9 +206,7 @@ func TestValidateSecret(t *testing.T) {
206206
project := &types.Project{
207207
Secrets: types.Secrets{
208208
"foo": types.SecretConfig{
209-
External: types.External{
210-
External: true,
211-
},
209+
External: true,
212210
},
213211
},
214212
Services: types.Services([]types.ServiceConfig{

0 commit comments

Comments
 (0)