Check for case when image config isn't present
@@ -172,12 +172,14 @@ func setupContainerUser(specgen *generate.Generator, rootfs string, sc *pb.Linux
containerUser = userName
} else {
// Case 3: get user from image config
+ if imageConfig != nil {
imageUser := imageConfig.Config.User
if imageUser != "" {
containerUser = imageUser
}
}
}
+ }
logrus.Debugf("CONTAINER USER: %+v", containerUser)
@@ -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,7 +558,8 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
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)
if len(parts) != 2 {
return nil, fmt.Errorf("invalid env from image: %s", item)
@@ -565,14 +570,17 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
}
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 containerImageConfig != nil {
+ imageCwd := containerImageConfig.Config.WorkingDir
if imageCwd != "" {
containerCwd = imageCwd
}
+ }
runtimeCwd := containerConfig.WorkingDir
if runtimeCwd != "" {
containerCwd = 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
}
}
