-
Notifications
You must be signed in to change notification settings - Fork 950
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
bugfix: missing merge some config from image #2156
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -355,6 +355,21 @@ func (mgr *ContainerManager) Create(ctx context.Context, name string, config *ty | |
HostConfig: config.HostConfig, | ||
} | ||
|
||
// merge image's config into container | ||
if err := container.merge(func() (ocispec.ImageConfig, error) { | ||
img, err := mgr.Client.GetImage(ctx, config.Image) | ||
if err != nil { | ||
return ocispec.ImageConfig{}, err | ||
} | ||
ociImage, err := containerdImageToOciImage(ctx, img) | ||
if err != nil { | ||
return ocispec.ImageConfig{}, err | ||
} | ||
return ociImage.Config, nil | ||
}); err != nil { | ||
return nil, err | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put merge funtion before initContainerStorage, make mount points generate completely. |
||
// set container basefs, basefs is not created in pouchd, it will created | ||
// after create options passed to containerd. | ||
mgr.setBaseFS(ctx, container, id) | ||
|
@@ -382,18 +397,6 @@ func (mgr *ContainerManager) Create(ctx context.Context, name string, config *ty | |
return nil, err | ||
} | ||
|
||
// merge image's config into container | ||
if err := container.merge(func() (ocispec.ImageConfig, error) { | ||
img, err := mgr.Client.GetImage(ctx, config.Image) | ||
ociImage, err := containerdImageToOciImage(ctx, img) | ||
if err != nil { | ||
return ocispec.ImageConfig{}, err | ||
} | ||
return ociImage.Config, nil | ||
}); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Get snapshot UpperDir | ||
mounts, err := mgr.Client.GetMounts(ctx, id) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,7 +285,7 @@ func (c *Container) StopTimeout() int64 { | |
func (c *Container) merge(getconfig func() (v1.ImageConfig, error)) error { | ||
c.Lock() | ||
defer c.Unlock() | ||
config, err := getconfig() | ||
imageConf, err := getconfig() | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -294,19 +294,66 @@ func (c *Container) merge(getconfig func() (v1.ImageConfig, error)) error { | |
// Otherwise use the image's configuration to fill it. | ||
if len(c.Config.Entrypoint) == 0 { | ||
if len(c.Config.Cmd) == 0 { | ||
c.Config.Cmd = config.Cmd | ||
c.Config.Cmd = imageConf.Cmd | ||
} | ||
c.Config.Entrypoint = config.Entrypoint | ||
c.Config.Entrypoint = imageConf.Entrypoint | ||
} | ||
|
||
// ContainerConfig.Env is new, and the ImageConfig.Env is old | ||
newEnvSlice, err := mergeEnvSlice(c.Config.Env, config.Env) | ||
newEnvSlice, err := mergeEnvSlice(c.Config.Env, imageConf.Env) | ||
if err != nil { | ||
return err | ||
} | ||
c.Config.Env = newEnvSlice | ||
if c.Config.WorkingDir == "" { | ||
c.Config.WorkingDir = config.WorkingDir | ||
c.Config.WorkingDir = imageConf.WorkingDir | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing volumes here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update and add. |
||
// merge user from image image config. | ||
if c.Config.User == "" { | ||
c.Config.User = imageConf.User | ||
} | ||
|
||
// merge stop signal from image config. | ||
if c.Config.StopSignal == "" { | ||
c.Config.StopSignal = imageConf.StopSignal | ||
} | ||
|
||
// merge label from image image config, if same label key exist, | ||
// use container config. | ||
if imageConf.Labels != nil { | ||
if c.Config.Labels == nil { | ||
c.Config.Labels = make(map[string]string) | ||
} | ||
for k, v := range c.Config.Labels { | ||
imageConf.Labels[k] = v | ||
} | ||
c.Config.Labels = imageConf.Labels | ||
} | ||
|
||
// merge exposed ports from image config, if same label key exist, | ||
// use container config. | ||
if len(imageConf.ExposedPorts) > 0 { | ||
if c.Config.ExposedPorts == nil { | ||
c.Config.ExposedPorts = make(map[string]interface{}) | ||
} | ||
for k, v := range imageConf.ExposedPorts { | ||
if _, exist := c.Config.ExposedPorts[k]; !exist { | ||
c.Config.ExposedPorts[k] = interface{}(v) | ||
} | ||
} | ||
} | ||
|
||
// merge volumes from image config. | ||
if len(imageConf.Volumes) > 0 { | ||
if c.Config.Volumes == nil { | ||
c.Config.Volumes = make(map[string]interface{}) | ||
} | ||
for k, v := range imageConf.Volumes { | ||
if _, exist := c.Config.Volumes[k]; !exist { | ||
c.Config.Volumes[k] = interface{}(v) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no error check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should ask the one wrote for it, seems like a bug.