mirror of https://github.com/docker/docs.git
Decoder does not work properly with nested pointers using gcc
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
This commit is contained in:
parent
b27f960504
commit
eb97de7dee
|
@ -132,15 +132,36 @@ type Config struct {
|
||||||
|
|
||||||
type ContainerConfigWrapper struct {
|
type ContainerConfigWrapper struct {
|
||||||
*Config
|
*Config
|
||||||
*hostConfigWrapper
|
InnerHostConfig *HostConfig `json:"HostConfig,omitempty"`
|
||||||
|
Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility.
|
||||||
|
*HostConfig // Deprecated. Exported to read attrubutes from json that are not in the inner host config structure.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ContainerConfigWrapper) HostConfig() *HostConfig {
|
func (w *ContainerConfigWrapper) GetHostConfig() *HostConfig {
|
||||||
if c.hostConfigWrapper == nil {
|
hc := w.HostConfig
|
||||||
return new(HostConfig)
|
|
||||||
|
if hc == nil && w.InnerHostConfig != nil {
|
||||||
|
hc = w.InnerHostConfig
|
||||||
|
} else if w.InnerHostConfig != nil {
|
||||||
|
if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 {
|
||||||
|
w.InnerHostConfig.Memory = hc.Memory
|
||||||
|
}
|
||||||
|
if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 {
|
||||||
|
w.InnerHostConfig.MemorySwap = hc.MemorySwap
|
||||||
|
}
|
||||||
|
if hc.CpuShares != 0 && w.InnerHostConfig.CpuShares == 0 {
|
||||||
|
w.InnerHostConfig.CpuShares = hc.CpuShares
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.hostConfigWrapper.GetHostConfig()
|
hc = w.InnerHostConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
if hc != nil && w.Cpuset != "" && hc.CpusetCpus == "" {
|
||||||
|
hc.CpusetCpus = w.Cpuset
|
||||||
|
}
|
||||||
|
|
||||||
|
return hc
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeContainerConfig decodes a json encoded config into a ContainerConfigWrapper
|
// DecodeContainerConfig decodes a json encoded config into a ContainerConfigWrapper
|
||||||
|
@ -155,5 +176,5 @@ func DecodeContainerConfig(src io.Reader) (*Config, *HostConfig, error) {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return w.Config, w.HostConfig(), nil
|
return w.Config, w.GetHostConfig(), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,47 +234,15 @@ type HostConfig struct {
|
||||||
func MergeConfigs(config *Config, hostConfig *HostConfig) *ContainerConfigWrapper {
|
func MergeConfigs(config *Config, hostConfig *HostConfig) *ContainerConfigWrapper {
|
||||||
return &ContainerConfigWrapper{
|
return &ContainerConfigWrapper{
|
||||||
config,
|
config,
|
||||||
&hostConfigWrapper{InnerHostConfig: hostConfig},
|
hostConfig,
|
||||||
|
"", nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type hostConfigWrapper struct {
|
|
||||||
InnerHostConfig *HostConfig `json:"HostConfig,omitempty"`
|
|
||||||
Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility.
|
|
||||||
|
|
||||||
*HostConfig // Deprecated. Exported to read attrubutes from json that are not in the inner host config structure.
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w hostConfigWrapper) GetHostConfig() *HostConfig {
|
|
||||||
hc := w.HostConfig
|
|
||||||
|
|
||||||
if hc == nil && w.InnerHostConfig != nil {
|
|
||||||
hc = w.InnerHostConfig
|
|
||||||
} else if w.InnerHostConfig != nil {
|
|
||||||
if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 {
|
|
||||||
w.InnerHostConfig.Memory = hc.Memory
|
|
||||||
}
|
|
||||||
if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 {
|
|
||||||
w.InnerHostConfig.MemorySwap = hc.MemorySwap
|
|
||||||
}
|
|
||||||
if hc.CpuShares != 0 && w.InnerHostConfig.CpuShares == 0 {
|
|
||||||
w.InnerHostConfig.CpuShares = hc.CpuShares
|
|
||||||
}
|
|
||||||
|
|
||||||
hc = w.InnerHostConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
if hc != nil && w.Cpuset != "" && hc.CpusetCpus == "" {
|
|
||||||
hc.CpusetCpus = w.Cpuset
|
|
||||||
}
|
|
||||||
|
|
||||||
return hc
|
|
||||||
}
|
|
||||||
|
|
||||||
func DecodeHostConfig(src io.Reader) (*HostConfig, error) {
|
func DecodeHostConfig(src io.Reader) (*HostConfig, error) {
|
||||||
decoder := json.NewDecoder(src)
|
decoder := json.NewDecoder(src)
|
||||||
|
|
||||||
var w hostConfigWrapper
|
var w ContainerConfigWrapper
|
||||||
if err := decoder.Decode(&w); err != nil {
|
if err := decoder.Decode(&w); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue