Merge pull request #427 from mrunalp/fix_nil_config

Check for case when image config isn't present
This commit is contained in:
Antonio Murdaca 2017-04-05 12:42:58 +02:00 committed by GitHub
commit 09d2a6b519

View file

@ -142,12 +142,14 @@ func setupContainerUser(specgen *generate.Generator, rootfs string, sc *pb.Linux
containerUser = userName containerUser = userName
} else { } else {
// Case 3: get user from image config // Case 3: get user from image config
if imageConfig != nil {
imageUser := imageConfig.Config.User imageUser := imageConfig.Config.User
if imageUser != "" { if imageUser != "" {
containerUser = imageUser containerUser = imageUser
} }
} }
} }
}
logrus.Debugf("CONTAINER USER: %+v", containerUser) logrus.Debugf("CONTAINER USER: %+v", containerUser)
@ -506,7 +508,9 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
return nil, fmt.Errorf("failed to mount container %s(%s): %v", containerName, containerID, err) 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 { if err != nil {
return nil, err return nil, err
} }
@ -524,7 +528,8 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
specgen.AddProcessEnv(key, value) specgen.AddProcessEnv(key, value)
} }
} }
for _, item := range containerInfo.Config.Config.Env { if containerImageConfig != nil {
for _, item := range containerImageConfig.Config.Env {
parts := strings.SplitN(item, "=", 2) parts := strings.SplitN(item, "=", 2)
if len(parts) != 2 { if len(parts) != 2 {
return nil, fmt.Errorf("invalid env from image: %s", item) return nil, fmt.Errorf("invalid env from image: %s", item)
@ -535,14 +540,17 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
} }
specgen.AddProcessEnv(parts[0], parts[1]) specgen.AddProcessEnv(parts[0], parts[1])
} }
}
// Set working directory // Set working directory
// Pick it up from image config first and override if specified in CRI // Pick it up from image config first and override if specified in CRI
containerCwd := "/" containerCwd := "/"
imageCwd := containerInfo.Config.Config.WorkingDir if containerImageConfig != nil {
imageCwd := containerImageConfig.Config.WorkingDir
if imageCwd != "" { if imageCwd != "" {
containerCwd = imageCwd containerCwd = imageCwd
} }
}
runtimeCwd := containerConfig.WorkingDir runtimeCwd := containerConfig.WorkingDir
if runtimeCwd != "" { if runtimeCwd != "" {
containerCwd = runtimeCwd containerCwd = runtimeCwd
@ -551,7 +559,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
// Setup user and groups // Setup user and groups
if linux != nil { 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 return nil, err
} }
} }