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,9 +142,11 @@ 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
imageUser := imageConfig.Config.User if imageConfig != nil {
if imageUser != "" { imageUser := imageConfig.Config.User
containerUser = imageUser if imageUser != "" {
containerUser = imageUser
}
} }
} }
} }
@ -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,24 +528,28 @@ 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 {
parts := strings.SplitN(item, "=", 2) for _, item := range containerImageConfig.Config.Env {
if len(parts) != 2 { parts := strings.SplitN(item, "=", 2)
return nil, fmt.Errorf("invalid env from image: %s", item) if len(parts) != 2 {
} return nil, fmt.Errorf("invalid env from image: %s", item)
}
if parts[0] == "" { if parts[0] == "" {
continue continue
}
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 {
if imageCwd != "" { imageCwd := containerImageConfig.Config.WorkingDir
containerCwd = imageCwd if imageCwd != "" {
containerCwd = imageCwd
}
} }
runtimeCwd := containerConfig.WorkingDir runtimeCwd := containerConfig.WorkingDir
if runtimeCwd != "" { if 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
} }
} }