Check for case when image config isn't present

Signed-off-by: Mrunal Patel <mpatel@redhat.com>
This commit is contained in:
Mrunal Patel 2017-04-04 15:39:59 -07:00
parent 3c7f3ab2ec
commit aac24e1715

View file

@ -172,9 +172,11 @@ func setupContainerUser(specgen *generate.Generator, rootfs string, sc *pb.Linux
containerUser = userName
} else {
// Case 3: get user from image config
imageUser := imageConfig.Config.User
if imageUser != "" {
containerUser = imageUser
if imageConfig != nil {
imageUser := imageConfig.Config.User
if imageUser != "" {
containerUser = imageUser
}
}
}
}
@ -536,7 +538,9 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
return nil, fmt.Errorf("failed to mount container %s(%s): %v", containerName, containerID, err)
}
processArgs, err := buildOCIProcessArgs(containerConfig, containerInfo.Config)
containerImageConfig := containerInfo.Config
processArgs, err := buildOCIProcessArgs(containerConfig, containerImageConfig)
if err != nil {
return nil, err
}
@ -554,24 +558,28 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
specgen.AddProcessEnv(key, value)
}
}
for _, item := range containerInfo.Config.Config.Env {
parts := strings.SplitN(item, "=", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("invalid env from image: %s", item)
}
if containerImageConfig != nil {
for _, item := range containerImageConfig.Config.Env {
parts := strings.SplitN(item, "=", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("invalid env from image: %s", item)
}
if parts[0] == "" {
continue
if parts[0] == "" {
continue
}
specgen.AddProcessEnv(parts[0], parts[1])
}
specgen.AddProcessEnv(parts[0], parts[1])
}
// Set working directory
// Pick it up from image config first and override if specified in CRI
containerCwd := "/"
imageCwd := containerInfo.Config.Config.WorkingDir
if imageCwd != "" {
containerCwd = imageCwd
if containerImageConfig != nil {
imageCwd := containerImageConfig.Config.WorkingDir
if imageCwd != "" {
containerCwd = imageCwd
}
}
runtimeCwd := containerConfig.WorkingDir
if runtimeCwd != "" {
@ -581,7 +589,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
// Setup user and groups
if linux != nil {
if err = setupContainerUser(&specgen, mountPoint, linux.GetSecurityContext(), containerInfo.Config); err != nil {
if err = setupContainerUser(&specgen, mountPoint, linux.GetSecurityContext(), containerImageConfig); err != nil {
return nil, err
}
}