@@ -18,9 +18,9 @@ import (
1818)
1919
2020// CheckpointContainer checkpoints a container
21- func (s * Server ) CheckpointContainer (ctx context.Context , req * types.CheckpointContainerRequest ) error {
21+ func (s * Server ) CheckpointContainer (ctx context.Context , req * types.CheckpointContainerRequest ) ( * types. CheckpointContainerResponse , error ) {
2222 if ! s .config .RuntimeConfig .CheckpointRestore () {
23- return fmt .Errorf ("checkpoint/restore support not available" )
23+ return nil , fmt .Errorf ("checkpoint/restore support not available" )
2424 }
2525
2626 var opts []* lib.ContainerCheckpointRestoreOptions
@@ -32,17 +32,17 @@ func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointC
3232 // Maybe the user specified a Pod
3333 sb , err := s .LookupSandbox (req .ContainerId )
3434 if err != nil {
35- return status .Errorf (codes .NotFound , "could not find container or pod %q: %v" , req .ContainerId , err )
35+ return nil , status .Errorf (codes .NotFound , "could not find container or pod %q: %v" , req .ContainerId , err )
3636 }
3737 if req .Location == "" {
38- return status .Errorf (codes .NotFound , "Pod checkpointing requires a destination file" )
38+ return nil , status .Errorf (codes .NotFound , "Pod checkpointing requires a destination file" )
3939 }
4040
4141 log .Infof (ctx , "Checkpointing pod: %s" , req .ContainerId )
4242 // Create a temporary directory
4343 podCheckpointDirectory , err = os .MkdirTemp ("" , "checkpoint" )
4444 if err != nil {
45- return err
45+ return nil , err
4646 }
4747 sandboxConfig := types.PodSandboxConfig {
4848 Metadata : & types.PodSandboxMetadata {
@@ -83,7 +83,7 @@ func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointC
8383 sandboxConfig .DnsConfig = dnsConfig
8484 }
8585 if _ , err := metadata .WriteJSONFile (sandboxConfig , podCheckpointDirectory , metadata .PodDumpFile ); err != nil {
86- return err
86+ return nil , err
8787 }
8888 defer func () {
8989 if err := os .RemoveAll (podCheckpointDirectory ); err != nil {
@@ -104,7 +104,7 @@ func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointC
104104 checkpointedPodOptions .Containers = append (checkpointedPodOptions .Containers , ctr .Name ())
105105 }
106106 if len (opts ) == 0 {
107- return status .Errorf (codes .NotFound , "No containers found in Pod %q" , req .ContainerId )
107+ return nil , status .Errorf (codes .NotFound , "No containers found in Pod %q" , req .ContainerId )
108108 }
109109 checkpointedPodOptions .Version = 1
110110 checkpointedPodOptions .MountLabel = sb .MountLabel ()
@@ -126,36 +126,36 @@ func (s *Server) CheckpointContainer(ctx context.Context, req *types.CheckpointC
126126 for _ , opt := range opts {
127127 _ , err = s .ContainerServer .ContainerCheckpoint (ctx , opt )
128128 if err != nil {
129- return err
129+ return nil , err
130130 }
131131 }
132132
133133 if podCheckpointDirectory != "" {
134134 if podOptions , err := metadata .WriteJSONFile (checkpointedPodOptions , podCheckpointDirectory , metadata .PodOptionsFile ); err != nil {
135- return fmt .Errorf ("error creating checkpointedContainers list file %q: %w" , podOptions , err )
135+ return nil , fmt .Errorf ("error creating checkpointedContainers list file %q: %w" , podOptions , err )
136136 }
137137 // It is a Pod checkpoint. Create the archive
138138 podTar , err := archive .TarWithOptions (podCheckpointDirectory , & archive.TarOptions {
139139 IncludeSourceDir : true ,
140140 })
141141 if err != nil {
142- return err
142+ return nil , err
143143 }
144144 // The resulting tar archive should not readable by everyone as it contains
145145 // every memory page of the checkpointed processes.
146146 podTarFile , err := os .OpenFile (req .Location , os .O_RDWR | os .O_CREATE , 0o600 )
147147 if err != nil {
148- return fmt .Errorf ("error creating pod checkpoint archive %q: %w" , req .Location , err )
148+ return nil , fmt .Errorf ("error creating pod checkpoint archive %q: %w" , req .Location , err )
149149 }
150150 defer podTarFile .Close ()
151151 _ , err = io .Copy (podTarFile , podTar )
152152 if err != nil {
153- return fmt .Errorf ("failed writing to pod tar archive %q: %w" , req .Location , err )
153+ return nil , fmt .Errorf ("failed writing to pod tar archive %q: %w" , req .Location , err )
154154 }
155155 log .Infof (ctx , "Checkpointed pod: %s" , req .ContainerId )
156156 } else {
157157 log .Infof (ctx , "Checkpointed container: %s" , req .ContainerId )
158158 }
159159
160- return nil
160+ return & types. CheckpointContainerResponse {}, nil
161161}
0 commit comments