- 
                Notifications
    You must be signed in to change notification settings 
- Fork 711
checkpoint: support checkpoint create command #4484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c8ddcd8
              
                checkpoint: support nerdctl checkpoint create command
              
              
                ChengyuZhu6 8f8eaf0
              
                checkpoint: add unit tests for checkpoint create command
              
              
                ChengyuZhu6 9c36d7b
              
                docs: add checkpoint create command reference
              
              
                ChengyuZhu6 2c4729c
              
                container: add checkpoint restore support to container start
              
              
                ChengyuZhu6 0e2bd47
              
                container: add unit test for container start with checkpoint
              
              
                ChengyuZhu6 4560704
              
                docs: add nerdctl start with checkpoint command reference
              
              
                ChengyuZhu6 d12925e
              
                ci: install criu dependency
              
              
                ChengyuZhu6 a59921c
              
                taskutil: introduce taskoptions to reduce argument numbers
              
              
                ChengyuZhu6 060469a
              
                Disable checkpoint/restore unit tests for docker
              
              
                ChengyuZhu6 627f63d
              
                fix ci failures about soci
              
              
                ChengyuZhu6 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|  | ||
| package checkpoint | ||
|  | ||
| import ( | ||
| "github.com/spf13/cobra" | ||
|  | ||
| "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" | ||
| ) | ||
|  | ||
| func Command() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Annotations: map[string]string{helpers.Category: helpers.Management}, | ||
| Use: "checkpoint", | ||
| Short: "Manage checkpoints.", | ||
| RunE: helpers.UnknownSubcommandAction, | ||
| SilenceUsage: true, | ||
| SilenceErrors: true, | ||
| } | ||
|  | ||
| cmd.AddCommand( | ||
| CreateCommand(), | ||
| ) | ||
|  | ||
| return cmd | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|  | ||
| package checkpoint | ||
|  | ||
| import ( | ||
| "path/filepath" | ||
|  | ||
| "github.com/spf13/cobra" | ||
|  | ||
| "github.com/containerd/nerdctl/v2/cmd/nerdctl/completion" | ||
| "github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers" | ||
| "github.com/containerd/nerdctl/v2/pkg/api/types" | ||
| "github.com/containerd/nerdctl/v2/pkg/clientutil" | ||
| "github.com/containerd/nerdctl/v2/pkg/cmd/checkpoint" | ||
| ) | ||
|  | ||
| func CreateCommand() *cobra.Command { | ||
| var cmd = &cobra.Command{ | ||
| Use: "create [OPTIONS] CONTAINER CHECKPOINT", | ||
| Short: "Create a checkpoint from a running container", | ||
| Args: cobra.ExactArgs(2), | ||
| RunE: createAction, | ||
| ValidArgsFunction: createShellComplete, | ||
| SilenceUsage: true, | ||
| SilenceErrors: true, | ||
| } | ||
| cmd.Flags().Bool("leave-running", false, "Leave the container running after checkpointing") | ||
| cmd.Flags().String("checkpoint-dir", "", "Checkpoint directory") | ||
| return cmd | ||
| } | ||
|  | ||
| func processCreateFlags(cmd *cobra.Command) (types.CheckpointCreateOptions, error) { | ||
| globalOptions, err := helpers.ProcessRootCmdFlags(cmd) | ||
| if err != nil { | ||
| return types.CheckpointCreateOptions{}, err | ||
| } | ||
|  | ||
| leaveRunning, err := cmd.Flags().GetBool("leave-running") | ||
| if err != nil { | ||
| return types.CheckpointCreateOptions{}, err | ||
| } | ||
| checkpointDir, err := cmd.Flags().GetString("checkpoint-dir") | ||
| if err != nil { | ||
| return types.CheckpointCreateOptions{}, err | ||
| } | ||
| if checkpointDir == "" { | ||
| checkpointDir = filepath.Join(globalOptions.DataRoot, "checkpoints") | ||
| } | ||
|  | ||
| return types.CheckpointCreateOptions{ | ||
| Stdout: cmd.OutOrStdout(), | ||
| GOptions: globalOptions, | ||
| LeaveRunning: leaveRunning, | ||
| CheckpointDir: checkpointDir, | ||
| }, nil | ||
| } | ||
|  | ||
| func createAction(cmd *cobra.Command, args []string) error { | ||
| createOptions, err := processCreateFlags(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), createOptions.GOptions.Namespace, createOptions.GOptions.Address) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer cancel() | ||
|  | ||
| err = checkpoint.Create(ctx, client, args[0], args[1], createOptions) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|  | ||
| return nil | ||
| } | ||
|  | ||
| func createShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
| return completion.ImageNames(cmd) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|  | ||
| package checkpoint | ||
|  | ||
| import ( | ||
| "errors" | ||
| "testing" | ||
|  | ||
| "github.com/containerd/nerdctl/mod/tigron/expect" | ||
| "github.com/containerd/nerdctl/mod/tigron/require" | ||
| "github.com/containerd/nerdctl/mod/tigron/test" | ||
|  | ||
| "github.com/containerd/nerdctl/v2/pkg/testutil" | ||
| "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" | ||
| ) | ||
|  | ||
| func TestCheckpointCreateErrors(t *testing.T) { | ||
| testCase := nerdtest.Setup() | ||
|  | ||
| testCase.Require = require.All( | ||
| require.Not(nerdtest.Rootless), | ||
| // Docker version 28.x has a known regression that breaks Checkpoint/Restore functionality. | ||
| // The issue is tracked in the moby/moby project as https://github.com/moby/moby/issues/50750. | ||
| require.Not(nerdtest.Docker), | ||
| ) | ||
| testCase.SubTests = []*test.Case{ | ||
| { | ||
| Description: "too-few-arguments", | ||
| Command: test.Command("checkpoint", "create", "too-few-arguments"), | ||
| Expected: func(data test.Data, helpers test.Helpers) *test.Expected { | ||
| return &test.Expected{ | ||
| ExitCode: 1, | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| Description: "too-many-arguments", | ||
| Command: test.Command("checkpoint", "create", "too", "many", "arguments"), | ||
| Expected: func(data test.Data, helpers test.Helpers) *test.Expected { | ||
| return &test.Expected{ | ||
| ExitCode: 1, | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| Description: "invalid-container-id", | ||
| Command: test.Command("checkpoint", "create", "foo", "bar"), | ||
| Expected: func(data test.Data, helpers test.Helpers) *test.Expected { | ||
| return &test.Expected{ | ||
| ExitCode: 1, | ||
| Errors: []error{errors.New("error creating checkpoint for container: foo")}, | ||
| } | ||
| }, | ||
| }, | ||
| } | ||
|  | ||
| testCase.Run(t) | ||
| } | ||
|  | ||
| func TestCheckpointCreate(t *testing.T) { | ||
| const ( | ||
| checkpointName = "checkpoint-bar" | ||
| checkpointDir = "/dir/foo" | ||
| ) | ||
| testCase := nerdtest.Setup() | ||
| testCase.Require = require.All( | ||
| require.Not(nerdtest.Rootless), | ||
| // Docker version 28.x has a known regression that breaks Checkpoint/Restore functionality. | ||
| // The issue is tracked in the moby/moby project as https://github.com/moby/moby/issues/50750. | ||
| require.Not(nerdtest.Docker), | ||
| ) | ||
| testCase.SubTests = []*test.Case{ | ||
| { | ||
| Description: "leave-running=true", | ||
| Setup: func(data test.Data, helpers test.Helpers) { | ||
| helpers.Ensure("run", "-d", "--name", data.Identifier("container-running"), testutil.CommonImage, "sleep", "infinity") | ||
| }, | ||
| Cleanup: func(data test.Data, helpers test.Helpers) { | ||
| helpers.Anyhow("rm", "-f", data.Identifier("container-running")) | ||
| }, | ||
| Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { | ||
| return helpers.Command("checkpoint", "create", "--leave-running", "--checkpoint-dir", checkpointDir, data.Identifier("container-running"), checkpointName+"running") | ||
| }, | ||
| Expected: func(data test.Data, helpers test.Helpers) *test.Expected { | ||
| return &test.Expected{ | ||
| ExitCode: 0, | ||
| Output: expect.Equals(checkpointName + "running\n"), | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| Description: "leave-running=false", | ||
| Setup: func(data test.Data, helpers test.Helpers) { | ||
| helpers.Ensure("run", "-d", "--name", data.Identifier("container-exit"), testutil.CommonImage, "sleep", "infinity") | ||
| }, | ||
| Cleanup: func(data test.Data, helpers test.Helpers) { | ||
| helpers.Anyhow("rm", "-f", data.Identifier("container-exit")) | ||
| }, | ||
| Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { | ||
| return helpers.Command("checkpoint", "create", "--checkpoint-dir", checkpointDir, data.Identifier("container-exit"), checkpointName+"exit") | ||
| }, | ||
| Expected: func(data test.Data, helpers test.Helpers) *test.Expected { | ||
| return &test.Expected{ | ||
| ExitCode: 0, | ||
| Output: expect.Equals(checkpointName + "exit\n"), | ||
| } | ||
| }, | ||
| }, | ||
| } | ||
|  | ||
| testCase.Run(t) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|  | ||
| package checkpoint | ||
|  | ||
| import ( | ||
| "testing" | ||
|  | ||
| "github.com/containerd/nerdctl/v2/pkg/testutil" | ||
| ) | ||
|  | ||
| func TestMain(m *testing.M) { | ||
| testutil.M(m) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.