Skip to content
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

Add '--mounts' option #43

Merged
merged 2 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion checkpointctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
version string
printStats bool
showMounts bool
fullPaths bool
)

func main() {
Expand Down Expand Up @@ -55,11 +56,21 @@ func setupShow() *cobra.Command {
false,
"Print overview about mounts used in the checkpoints",
)
flags.BoolVar(
sankalp-12 marked this conversation as resolved.
Show resolved Hide resolved
&fullPaths,
"full-paths",
false,
"Display mounts with full paths",
)

return cmd
}

func show(cmd *cobra.Command, args []string) error {
if fullPaths && !showMounts {
return fmt.Errorf("Cannot use --full-paths without --mounts option")
}

input := args[0]
tar, err := os.Stat(input)
if err != nil {
Expand All @@ -81,6 +92,5 @@ func show(cmd *cobra.Command, args []string) error {
if err := archive.UntarPath(input, dir); err != nil {
return fmt.Errorf("unpacking of checkpoint archive %s failed: %w", input, err)
}

return showContainerCheckpoint(dir)
}
7 changes: 6 additions & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ func showContainerCheckpoint(checkpointDirectory string) error {
table.Append([]string{
data.Destination,
data.Type,
shortenPath(data.Source),
func() string {
if fullPaths {
return data.Source
}
return shortenPath(data.Source)
}(),
adrianreber marked this conversation as resolved.
Show resolved Hide resolved
})
}
fmt.Println("\nOverview of Mounts")
Expand Down
35 changes: 35 additions & 0 deletions test/checkpointctl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,41 @@ function teardown() {
[[ ${lines[10]} == *"446571 us"* ]]
}

@test "Run checkpointctl show with tar file and --mounts and valid spec.dump" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --mounts
[ "$status" -eq 0 ]
[[ ${lines[6]} == *"Overview of Mounts"* ]]
[[ ${lines[8]} == *"DESTINATION"* ]]
[[ ${lines[10]} == *"/proc"* ]]
}

@test "Run checkpointctl show with tar file and --mounts and --full-paths and valid spec.dump" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --mounts --full-paths
[ "$status" -eq 0 ]
[[ ${lines[6]} == *"Overview of Mounts"* ]]
[[ ${lines[8]} == *"DESTINATION"* ]]
[[ ${lines[10]} == *"/proc"* ]]
}


@test "Run checkpointctl show with tar file and missing --mounts and --full-paths" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --full-paths
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"Error: Cannot use --full-paths without --mounts option"* ]]
}

@test "Run checkpointctl show with tar file with valid config.dump and valid spec.dump (CRI-O) and no checkpoint directory" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump.cri-o "$TEST_TMP_DIR1"/spec.dump
Expand Down
16 changes: 15 additions & 1 deletion test/spec.dump
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
{
"annotations": {"io.container.manager": "libpod"}
"mounts": [
{
"destination": "/proc",
"type": "proc",
"source": "proc"
},
{
"destination": "/etc/hostname",
"type": "bind",
"source": "/run/containers/storage/overlay-containers/d5eee7931a29b2d6bf51469e3ab7284bb22a9e6dad073277e30e2a29256efc84/userdata/hostname"
}
],
"annotations": {
"io.container.manager": "libpod"
}
}