Skip to content

feat: add edit subcommand#205

Closed
ImranullahKhann wants to merge 2 commits into
checkpoint-restore:mainfrom
ImranullahKhann:main
Closed

feat: add edit subcommand#205
ImranullahKhann wants to merge 2 commits into
checkpoint-restore:mainfrom
ImranullahKhann:main

Conversation

@ImranullahKhann

@ImranullahKhann ImranullahKhann commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

Currently only supports tcp listen port remapping. Made the following changes:

  • Added the edit command in cmd/.
  • Added edit_archive.go in internals/ for the main edit logic.
  • Added archive_modifiers.go inside internals/. It contains the modifier logic for any entry that would need changes in the archive.
  • Added unit and integration tests for verifying the functionality.

Kept extensibility in mind, for any additional edit logic in the future, we can reuse the same function tarStreamRewrite (in edit_archive.go) and write additional modifier functions in archive_modifiers.go.

Closes #169

@github-actions

github-actions Bot commented Mar 1, 2026

Copy link
Copy Markdown

Binary Size Check Failed

The binary size increase exceeds the allowed threshold.

Size Check Output

Changes from d956de3cd8b2f43c671801ba53563af332983285 to d956de3cd8b2f43c671801ba53563af332983285:
Rebasing (2/6)
Executing: test/check-size.sh
go build -o checkpointctl -ldflags "-X main.name=checkpointctl -X main.version=1.5.0"
BINARY SIZE (3fc6820): 9727704
No previous size present, storing current size
Rebasing (3/6)
Rebasing (4/6)
Executing: test/check-size.sh
go build -o checkpointctl -ldflags "-X main.name=checkpointctl -X main.version=1.5.0"
BINARY SIZE (0f46401): 10509672
FAIL: size difference of 781968 B exceeds limit 51200 B
warning: execution failed: test/check-size.sh
You can fix the problem, and then run

  git rebase --continue

How to resolve

If this size increase is expected and acceptable, a maintainer can add
the bloat-ok label to this PR to bypass the size check.


Binary size check performed by CI

@github-actions

github-actions Bot commented Mar 1, 2026

Copy link
Copy Markdown

Test Results

94 tests  +8   94 ✅ +8   4s ⏱️ -1s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 796785e. ± Comparison against base commit 34f655f.

♻️ This comment has been updated with latest results.

@ImranullahKhann

Copy link
Copy Markdown
Contributor Author

I have tested the functionality on Podman and CRI-O checkpoints. I will start working on writing the tests and would appreciate any feedback and guidance.

@codecov-commenter

codecov-commenter commented Mar 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.41281% with 100 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.84%. Comparing base (34f655f) to head (796785e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
internal/edit_archive.go 50.00% 49 Missing and 19 partials ⚠️
internal/archive_modifiers.go 73.77% 16 Missing and 16 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #205      +/-   ##
==========================================
- Coverage   79.98%   77.84%   -2.15%     
==========================================
  Files          16       19       +3     
  Lines        1759     2040     +281     
==========================================
+ Hits         1407     1588     +181     
- Misses        263      328      +65     
- Partials       89      124      +35     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ImranullahKhann

Copy link
Copy Markdown
Contributor Author

@rst0git, please take a look

@adrianreber

Copy link
Copy Markdown
Member

Please take a look at providing unit tests and end to end tests.

@ImranullahKhann ImranullahKhann force-pushed the main branch 2 times, most recently from e536151 to 1c8ceeb Compare March 19, 2026 11:34
@ImranullahKhann

Copy link
Copy Markdown
Contributor Author

@adrianreber, please have a look

@adrianreber

Copy link
Copy Markdown
Member

Try to add more unit tests. Especially the error branches are not covered well.

Currently only supports tcp listen port remapping. Made the following changes:
- Added the edit command in cmd/.
- Added edit_archive.go in internals/ for the main edit logic.
- Added archive_modifiers.go inside internals/. It contains the modifier
logic for any entry that would need changes in the archive.
Kept extensibility in mind, for any additional change logic in the future,
we can reuse the same function tarStreamRewrite (in edit_archive.go) and
write additional modifier functions in archive_modifiers.go.

Assisted-by: Github Copilot
Signed-off-by: Imranullah Khan <imranullahkhann2004@gmail.com>
Signed-off-by: Imranullah Khan <imranullahkhann2004@gmail.com>
@ImranullahKhann

Copy link
Copy Markdown
Contributor Author

Please have a look

@behouba behouba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ImranullahKhann thank you for working on this. I added some comments, feel free to take a look when you can.

continue
}

containerPort, ok := mappingMap["container_port"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i understand correctly, this match on the container port only, so --tcp-listen-remap could rewrite UDP mapping that share the same port (common situation with containers like pihole and coredns). Would it make sense to skip non TCP ports here?

if proto, _ := mappingMap["protocol"].(string); proto != "" && proto != "tcp" {
    continue
}

Comment thread internal/edit_archive.go
b := make([]byte, 10)
n, err := io.ReadFull(archiveFile, b)
if err != nil {
return fmt.Errorf("failed to read archive magic bytes")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to read archive magic bytes")
return fmt.Errorf("failed to read archive magic bytes: %w", err)

Comment thread internal/edit_archive.go
comp := archive.DetectCompression(b[:n])
// Seek back so DecompressStream can read from the start
if _, err := archiveFile.Seek(0, 0); err != nil {
return fmt.Errorf("failed to seek archive")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to seek archive")
return fmt.Errorf("failed to seek archive: %w", err)

Comment thread internal/edit_archive.go
// Decompress the archive into a plan tar stream
tarStream, err := archive.DecompressStream(archiveFile)
if err != nil {
return fmt.Errorf("failed to decompress archive")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to decompress archive")
return fmt.Errorf("failed to decompress archive: %w", err)

Comment thread internal/edit_archive.go
if err != nil {
outFile.Close()
os.Remove(outputPath)
return fmt.Errorf("failed to create compressor")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to create compressor")
return fmt.Errorf("failed to create compressor: %w", err)

var config map[string]any
if err := json.Unmarshal(data, &config); err != nil {
return nil, nil, fmt.Errorf("parsing config.dump JSON: %w", err)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big integers get rounded here because of map[string]any will decode all numbers as float64. This can corrupt the output when the default system resource limits are overwritten ( --ulimit).

Maybe something like this can keep the fidelity is unchanged.

      dec := json.NewDecoder(bytes.NewReader(data))
      dec.UseNumber()
      var config map[string]any
      if err := dec.Decode(&config); err != nil {
              return nil, nil, fmt.Errorf("parsing config.dump JSON: %w", err)
      }

Comment on lines +134 to +137
var spec map[string]any
if err := json.Unmarshal(data, &spec); err != nil {
return nil, nil, fmt.Errorf("parsing spec.dump JSON: %w", err)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same possible issue as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remapping of TCP listen ports

4 participants