Skip to content

Commit

Permalink
Merge pull request #8150 from kwilczynski/fix/linux-resources-nil-panic
Browse files Browse the repository at this point in the history
Check for nil values when importing container definition
  • Loading branch information
openshift-merge-bot[bot] committed May 8, 2024
2 parents 87f6542 + 794ce67 commit 9712c53
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions server/container_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,24 @@ func (s *Server) CRImportCheckpoint(
) (ctrID string, retErr error) {
var mountPoint string

input := createConfig.Image.Image
// Ensure that the image to restore the checkpoint from has been provided.
if createConfig.Image == nil || createConfig.Image.Image == "" {
return "", errors.New(`attribute "image" missing from container definition`)
}

inputImage := createConfig.Image.Image
createMounts := createConfig.Mounts
createAnnotations := createConfig.Annotations
createLabels := createConfig.Labels

restoreStorageImageID, err := s.checkIfCheckpointOCIImage(ctx, input)
restoreStorageImageID, err := s.checkIfCheckpointOCIImage(ctx, inputImage)
if err != nil {
return "", err
}

var restoreArchivePath string
if restoreStorageImageID != nil {
log.Debugf(ctx, "Restoring from oci image %s\n", input)
log.Debugf(ctx, "Restoring from oci image %s", inputImage)

// This is not out-of-process, but it is at least out of the CRI-O codebase; containers/storage uses raw strings.
mountPoint, err = s.ContainerServer.StorageImageServer().GetStore().MountImage(restoreStorageImageID.IDStringForOutOfProcessConsumptionOnly(), nil, "")
Expand All @@ -88,17 +93,17 @@ func (s *Server) CRImportCheckpoint(
} else {
// First get the container definition from the
// tarball to a temporary directory
archiveFile, err := os.Open(input)
archiveFile, err := os.Open(inputImage)
if err != nil {
return "", fmt.Errorf("failed to open checkpoint archive %s for import: %w", input, err)
return "", fmt.Errorf("failed to open checkpoint archive %s for import: %w", inputImage, err)
}
defer func(f *os.File) {
if err := f.Close(); err != nil {
log.Errorf(ctx, "Unable to close file %s: %q", f.Name(), err)
}
}(archiveFile)

restoreArchivePath = input
restoreArchivePath = inputImage
options := &archive.TarOptions{
// Here we only need the files config.dump and spec.dump
ExcludePatterns: []string{
Expand Down Expand Up @@ -270,11 +275,14 @@ func (s *Server) CRImportCheckpoint(
Labels: originalLabels,
}

if createConfig.Linux.Resources != nil {
containerConfig.Linux.Resources = createConfig.Linux.Resources
}
if createConfig.Linux.SecurityContext != nil {
containerConfig.Linux.SecurityContext = createConfig.Linux.SecurityContext
if createConfig.Linux != nil {
if createConfig.Linux.Resources != nil {
containerConfig.Linux.Resources = createConfig.Linux.Resources
}

if createConfig.Linux.SecurityContext != nil {
containerConfig.Linux.SecurityContext = createConfig.Linux.SecurityContext
}
}

if dumpSpec.Linux != nil {
Expand Down

0 comments on commit 9712c53

Please sign in to comment.