Skip to content

Commit 588d586

Browse files
authored
Merge pull request #467 from ndeloof/options_types
define Options type for (driver) options we pass as-is to runtime
2 parents 4b1e1a4 + 8188c76 commit 588d586

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

loader/loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ func createTransformHook(additionalTransformers ...Transformer) mapstructure.Dec
613613
reflect.TypeOf(types.HealthCheckTest{}): transformHealthCheckTest,
614614
reflect.TypeOf(types.ShellCommand{}): transformShellCommand,
615615
reflect.TypeOf(types.StringList{}): transformStringList,
616-
reflect.TypeOf(map[string]string{}): transformMapStringString,
616+
reflect.TypeOf(types.Options{}): transformMapStringString,
617617
reflect.TypeOf(types.UlimitsConfig{}): transformUlimits,
618618
reflect.TypeOf(types.UnitBytes(0)): transformSize,
619619
reflect.TypeOf([]types.ServicePortConfig{}): transformServicePort,

loader/merge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ func mergeLoggingConfig(dst, src reflect.Value) error {
320320
if getLoggingDriver(dst.Elem()) == "" {
321321
dst.Elem().FieldByName("Driver").SetString(getLoggingDriver(src.Elem()))
322322
}
323-
dstOptions := dst.Elem().FieldByName("Options").Interface().(map[string]string)
324-
srcOptions := src.Elem().FieldByName("Options").Interface().(map[string]string)
323+
dstOptions := dst.Elem().FieldByName("Options").Interface().(types.Options)
324+
srcOptions := src.Elem().FieldByName("Options").Interface().(types.Options)
325325
return mergo.Merge(&dstOptions, srcOptions, mergo.WithOverride)
326326
}
327327
// Different driver, override with src

types/types.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ func (m Mapping) Merge(o Mapping) Mapping {
535535
return m
536536
}
537537

538+
// Options is a mapping type for options we pass as-is to container runtime
539+
type Options map[string]string
540+
538541
// Labels is a mapping type for labels
539542
type Labels map[string]string
540543

@@ -609,8 +612,8 @@ func (h HostsList) MarshalJSON() ([]byte, error) {
609612

610613
// LoggingConfig the logging configuration for a service
611614
type LoggingConfig struct {
612-
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
613-
Options map[string]string `yaml:"options,omitempty" json:"options,omitempty"`
615+
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
616+
Options Options `yaml:"options,omitempty" json:"options,omitempty"`
614617

615618
Extensions Extensions `yaml:"#extensions,inline" json:"-"`
616619
}
@@ -955,16 +958,16 @@ func (u *UlimitsConfig) MarshalJSON() ([]byte, error) {
955958

956959
// NetworkConfig for a network
957960
type NetworkConfig struct {
958-
Name string `yaml:"name,omitempty" json:"name,omitempty"`
959-
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
960-
DriverOpts map[string]string `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
961-
Ipam IPAMConfig `yaml:"ipam,omitempty" json:"ipam,omitempty"`
962-
External External `yaml:"external,omitempty" json:"external,omitempty"`
963-
Internal bool `yaml:"internal,omitempty" json:"internal,omitempty"`
964-
Attachable bool `yaml:"attachable,omitempty" json:"attachable,omitempty"`
965-
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
966-
EnableIPv6 bool `yaml:"enable_ipv6,omitempty" json:"enable_ipv6,omitempty"`
967-
Extensions Extensions `yaml:"#extensions,inline" json:"-"`
961+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
962+
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
963+
DriverOpts Options `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
964+
Ipam IPAMConfig `yaml:"ipam,omitempty" json:"ipam,omitempty"`
965+
External External `yaml:"external,omitempty" json:"external,omitempty"`
966+
Internal bool `yaml:"internal,omitempty" json:"internal,omitempty"`
967+
Attachable bool `yaml:"attachable,omitempty" json:"attachable,omitempty"`
968+
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
969+
EnableIPv6 bool `yaml:"enable_ipv6,omitempty" json:"enable_ipv6,omitempty"`
970+
Extensions Extensions `yaml:"#extensions,inline" json:"-"`
968971
}
969972

970973
// IPAMConfig for a network
@@ -979,18 +982,18 @@ type IPAMPool struct {
979982
Subnet string `yaml:"subnet,omitempty" json:"subnet,omitempty"`
980983
Gateway string `yaml:"gateway,omitempty" json:"gateway,omitempty"`
981984
IPRange string `yaml:"ip_range,omitempty" json:"ip_range,omitempty"`
982-
AuxiliaryAddresses map[string]string `yaml:"aux_addresses,omitempty" json:"aux_addresses,omitempty"`
985+
AuxiliaryAddresses Mapping `yaml:"aux_addresses,omitempty" json:"aux_addresses,omitempty"`
983986
Extensions map[string]interface{} `yaml:",inline" json:"-"`
984987
}
985988

986989
// VolumeConfig for a volume
987990
type VolumeConfig struct {
988-
Name string `yaml:"name,omitempty" json:"name,omitempty"`
989-
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
990-
DriverOpts map[string]string `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
991-
External External `yaml:"external,omitempty" json:"external,omitempty"`
992-
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
993-
Extensions Extensions `yaml:"#extensions,inline" json:"-"`
991+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
992+
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
993+
DriverOpts Options `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
994+
External External `yaml:"external,omitempty" json:"external,omitempty"`
995+
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
996+
Extensions Extensions `yaml:"#extensions,inline" json:"-"`
994997
}
995998

996999
// External identifies a Volume or Network as a reference to a resource that is

0 commit comments

Comments
 (0)