Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make External a boolean #480

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 15 additions & 38 deletions loader/full-struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,12 @@ func networks() map[string]types.NetworkConfig {
},

"external-network": {
Name: "external-network",
External: types.External{External: true},
External: true,
},

"other-external-network": {
Name: "my-cool-network",
External: types.External{External: true},
External: true,
Extensions: map[string]interface{}{
"x-bar": "baz",
"x-foo": "bar",
Expand Down Expand Up @@ -519,16 +518,15 @@ func volumes() map[string]types.VolumeConfig {
},
},
"external-volume": {
Name: "external-volume",
External: types.External{External: true},
External: true,
},
"other-external-volume": {
Name: "my-cool-volume",
External: types.External{External: true},
External: true,
},
"external-volume3": {
Name: "this-is-volume3",
External: types.External{External: true},
External: true,
Extensions: map[string]interface{}{
"x-bar": "baz",
"x-foo": "bar",
Expand All @@ -547,11 +545,10 @@ func configs(workingDir string, homeDir string) map[string]types.ConfigObjConfig
},
"config2": {
Name: "my_config",
External: types.External{External: true},
External: true,
},
"config3": {
Name: "config3",
External: types.External{External: true},
External: true,
},
"config4": {
Name: "foo",
Expand All @@ -574,11 +571,10 @@ func secrets(workingDir string) map[string]types.SecretConfig {
},
"secret2": {
Name: "my_secret",
External: types.External{External: true},
External: true,
},
"secret3": {
Name: "secret3",
External: types.External{External: true},
External: true,
},
"secret4": {
Name: "bar",
Expand Down Expand Up @@ -948,7 +944,6 @@ services:
x-foo: bar
networks:
external-network:
name: external-network
external: true
other-external-network:
name: my-cool-network
Expand Down Expand Up @@ -983,7 +978,6 @@ volumes:
baz: "1"
foo: bar
external-volume:
name: external-volume
external: true
external-volume3:
name: this-is-volume3
Expand All @@ -1010,7 +1004,6 @@ secrets:
name: my_secret
external: true
secret3:
name: secret3
external: true
secret4:
name: bar
Expand All @@ -1028,7 +1021,6 @@ configs:
name: my_config
external: true
config3:
name: config3
external: true
config4:
name: foo
Expand Down Expand Up @@ -1060,7 +1052,6 @@ func fullExampleJSON(workingDir, homeDir string) string {
"configs": {
"config1": {
"file": "%s",
"external": false,
"labels": {
"foo": "bar"
}
Expand All @@ -1070,19 +1061,16 @@ func fullExampleJSON(workingDir, homeDir string) string {
"external": true
},
"config3": {
"name": "config3",
"external": true
},
"config4": {
"name": "foo",
"file": "%s",
"external": false
"file": "%s"
}
},
"name": "full_example_project_name",
"networks": {
"external-network": {
"name": "external-network",
"ipam": {},
"external": true
},
Expand Down Expand Up @@ -1116,20 +1104,17 @@ func fullExampleJSON(workingDir, homeDir string) string {
}
]
},
"external": false,
"labels": {
"foo": "bar"
}
},
"some-network": {
"ipam": {},
"external": false
"ipam": {}
}
},
"secrets": {
"secret1": {
"file": "%s",
"external": false,
"labels": {
"foo": "bar"
}
Expand All @@ -1139,17 +1124,14 @@ func fullExampleJSON(workingDir, homeDir string) string {
"external": true
},
"secret3": {
"name": "secret3",
"external": true
},
"secret4": {
"name": "bar",
"environment": "BAR",
"external": false
"environment": "BAR"
},
"secret5": {
"file": "/abs/secret_data",
"external": false
"file": "/abs/secret_data"
}
},
"services": {
Expand Down Expand Up @@ -1653,11 +1635,9 @@ func fullExampleJSON(workingDir, homeDir string) string {
"driver_opts": {
"baz": "1",
"foo": "bar"
},
"external": false
}
},
"external-volume": {
"name": "external-volume",
"external": true
},
"external-volume3": {
Expand All @@ -1674,14 +1654,11 @@ func fullExampleJSON(workingDir, homeDir string) string {
"baz": "1",
"foo": "bar"
},
"external": false,
"labels": {
"foo": "bar"
}
},
"some-volume": {
"external": false
}
"some-volume": {}
},
"x-bar": "baz",
"x-foo": "bar",
Expand Down
21 changes: 10 additions & 11 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,19 +859,18 @@ networks:
},
},
Configs: map[string]types.ConfigObjConfig{
"appconfig": {External: types.External{External: true}, Name: "appconfig"},
"appconfig": {External: true},
},
Secrets: map[string]types.SecretConfig{
"super": {External: types.External{External: true}, Name: "super"},
"super": {External: true},
},
Volumes: map[string]types.VolumeConfig{
"data": {External: types.External{External: true}, Name: "data"},
"data": {External: true},
},
Networks: map[string]types.NetworkConfig{
"back": {},
"front": {
External: types.External{External: true},
Name: "front",
External: true,
Internal: true,
Attachable: true,
},
Expand Down Expand Up @@ -1455,7 +1454,7 @@ volumes:
expected := types.Volumes{
"foo": {
Name: "oops",
External: types.External{External: true},
External: true,
},
}
assert.Check(t, is.DeepEqual(expected, project.Volumes))
Expand Down Expand Up @@ -1514,7 +1513,7 @@ secrets:
expected := types.Secrets{
"foo": {
Name: "oops",
External: types.External{External: true},
External: true,
},
}
assert.Check(t, is.DeepEqual(expected, project.Secrets))
Expand All @@ -1537,7 +1536,7 @@ networks:
expected := types.Networks{
"foo": {
Name: "oops",
External: types.External{External: true},
External: true,
},
}
assert.Check(t, is.DeepEqual(expected, project.Networks))
Expand Down Expand Up @@ -1805,14 +1804,14 @@ secrets:
Configs: map[string]types.ConfigObjConfig{
"config": {
Name: "config",
External: types.External{External: true},
External: true,
TemplateDriver: "config-driver",
},
},
Secrets: map[string]types.SecretConfig{
"secret": {
Name: "secret",
External: types.External{External: true},
External: true,
TemplateDriver: "secret-driver",
},
},
Expand Down Expand Up @@ -1874,7 +1873,7 @@ secrets:
Configs: map[string]types.ConfigObjConfig{
"config": {
Name: "config",
External: types.External{External: true},
External: true,
},
},
Secrets: map[string]types.SecretConfig{
Expand Down
47 changes: 0 additions & 47 deletions loader/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ func Normalize(project *types.Project) error {
project.Networks["default"] = types.NetworkConfig{}
}

if err := relocateExternalName(project); err != nil {
return err
}

for i, s := range project.Services {
if len(s.Networks) == 0 && s.NetworkMode == "" {
// Service without explicit network attachment are implicitly exposed on default network
Expand Down Expand Up @@ -224,49 +220,6 @@ func setNameFromKey(project *types.Project) {
}
}

func relocateExternalName(project *types.Project) error {
for i, n := range project.Networks {
if n.External.Name != "" {
if n.Name != "" {
return errors.Wrap(errdefs.ErrInvalid, "can't use both 'networks.external.name' (deprecated) and 'networks.name'")
}
n.Name = n.External.Name
}
project.Networks[i] = n
}

for i, v := range project.Volumes {
if v.External.Name != "" {
if v.Name != "" {
return errors.Wrap(errdefs.ErrInvalid, "can't use both 'volumes.external.name' (deprecated) and 'volumes.name'")
}
v.Name = v.External.Name
}
project.Volumes[i] = v
}

for i, s := range project.Secrets {
if s.External.Name != "" {
if s.Name != "" {
return errors.Wrap(errdefs.ErrInvalid, "can't use both 'secrets.external.name' (deprecated) and 'secrets.name'")
}
s.Name = s.External.Name
}
project.Secrets[i] = s
}

for i, c := range project.Configs {
if c.External.Name != "" {
if c.Name != "" {
return errors.Wrap(errdefs.ErrInvalid, "can't use both 'configs.external.name' (deprecated) and 'configs.name'")
}
c.Name = c.External.Name
}
project.Configs[i] = c
}
return nil
}

func relocateLogOpt(s *types.ServiceConfig) error {
if len(s.LogOpt) != 0 {
logrus.Warn("`log_opts` is deprecated. Use the `logging` element")
Expand Down
6 changes: 3 additions & 3 deletions loader/normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestNormalizeNetworkNames(t *testing.T) {
Networks: types.Networks{
"myExternalnet": {
Name: "myExternalnet", // this is automaticaly setup by loader for externa networks before reaching normalization
External: types.External{External: true},
External: true,
},
"mynet": {},
"myNamedNet": {
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestNormalizeVolumes(t *testing.T) {
Volumes: types.Volumes{
"myExternalVol": {
Name: "myExternalVol", // this is automaticaly setup by loader for externa networks before reaching normalization
External: types.External{External: true},
External: true,
},
"myvol": {},
"myNamedVol": {
Expand All @@ -107,7 +107,7 @@ func TestNormalizeVolumes(t *testing.T) {
Volumes: types.Volumes{
"myExternalVol": {
Name: "myExternalVol",
External: types.External{External: true},
External: true,
},
"myvol": {Name: "myProject_myvol"},
"myNamedVol": {
Expand Down
2 changes: 1 addition & 1 deletion loader/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func checkConsistency(project *types.Project) error {
}

for name, secret := range project.Secrets {
if secret.External.External {
if secret.External {
continue
}
if secret.File == "" && secret.Environment == "" {
Expand Down
6 changes: 2 additions & 4 deletions loader/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestValidateSecret(t *testing.T) {
project := &types.Project{
Secrets: types.Secrets{
"foo": types.SecretConfig{
External: types.External{External: true},
External: true,
},
},
}
Expand All @@ -206,9 +206,7 @@ func TestValidateSecret(t *testing.T) {
project := &types.Project{
Secrets: types.Secrets{
"foo": types.SecretConfig{
External: types.External{
External: true,
},
External: true,
},
},
Services: types.Services([]types.ServiceConfig{
Expand Down
Loading
Loading