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

remote: fix podman-remote container checkpoint --compress #21056

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 13 additions & 10 deletions pkg/api/handlers/libpod/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/infra/abi"
"github.com/containers/podman/v4/pkg/util"
"github.com/containers/storage/pkg/archive"
"github.com/gorilla/schema"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -212,16 +213,17 @@ func Checkpoint(w http.ResponseWriter, r *http.Request) {

decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
Keep bool `schema:"keep"`
LeaveRunning bool `schema:"leaveRunning"`
TCPEstablished bool `schema:"tcpEstablished"`
Export bool `schema:"export"`
IgnoreRootFS bool `schema:"ignoreRootFS"`
PrintStats bool `schema:"printStats"`
PreCheckpoint bool `schema:"preCheckpoint"`
WithPrevious bool `schema:"withPrevious"`
FileLocks bool `schema:"fileLocks"`
CreateImage string `schema:"createImage"`
Keep bool `schema:"keep"`
LeaveRunning bool `schema:"leaveRunning"`
TCPEstablished bool `schema:"tcpEstablished"`
Export bool `schema:"export"`
IgnoreRootFS bool `schema:"ignoreRootFS"`
PrintStats bool `schema:"printStats"`
PreCheckpoint bool `schema:"preCheckpoint"`
WithPrevious bool `schema:"withPrevious"`
Compression archive.Compression `schema:"compression"`
FileLocks bool `schema:"fileLocks"`
CreateImage string `schema:"createImage"`
}{
// override any golang type defaults
}
Expand All @@ -246,6 +248,7 @@ func Checkpoint(w http.ResponseWriter, r *http.Request) {
PrintStats: query.PrintStats,
PreCheckPoint: query.PreCheckpoint,
WithPrevious: query.WithPrevious,
Compression: query.Compression,
FileLocks: query.FileLocks,
CreateImage: query.CreateImage,
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/server/register_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,10 @@ func (s *APIServer) registerContainersHandlers(r *mux.Router) error {
// type: boolean
// description: check out the container with previous criu image files in pre-dump. only works on runc 1.0-rc or higher
// - in: query
// name: compression
// type: integer
// description: select compression algorithm (gzip, none, zstd) for checkpoint archive. (default "zstd")
// - in: query
// name: fileLocks
// type: boolean
// description: checkpoint a container with filelocks
Expand Down
2 changes: 2 additions & 0 deletions pkg/bindings/containers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"

"github.com/containers/podman/v4/libpod/define"
"github.com/containers/storage/pkg/archive"
)

// LogOptions describe finer control of log content or
Expand Down Expand Up @@ -61,6 +62,7 @@ type CheckpointOptions struct {
PrintStats *bool
PreCheckpoint *bool
WithPrevious *bool
Compression *archive.Compression
FileLocks *bool
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/bindings/containers/types_checkpoint_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/domain/infra/tunnel/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ func (ic *ContainerEngine) ContainerCheckpoint(ctx context.Context, namesOrIds [
options.WithPreCheckpoint(opts.PreCheckPoint)
options.WithLeaveRunning(opts.LeaveRunning)
options.WithWithPrevious(opts.WithPrevious)
options.WithCompression(opts.Compression)

if opts.All {
allCtrs, err := getContainersByContext(ic.ClientCtx, true, false, []string{})
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@ var _ = Describe("Podman checkpoint", func() {
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(podmanTest.NumberOfContainers()).To(Equal(0))

// Check the compression type of the exported file with checkpoint
// it should be "zstd"
compressionType, err := CheckCompressionType(fileName)
Expect(err).ShouldNot(HaveOccurred())
Expect(compressionType).To(ContainSubstring("zstd"))

// Restore container
result = podmanTest.Podman([]string{"container", "restore", "-i", fileName})
result.WaitWithDefaultTimeout()
Expand All @@ -580,6 +586,12 @@ var _ = Describe("Podman checkpoint", func() {
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(podmanTest.NumberOfContainers()).To(Equal(0))

// Check the compression type of the exported file with checkpoint
// it should be "zstd"
compressionType, err = CheckCompressionType(fileName)
Expect(err).ShouldNot(HaveOccurred())
Expect(compressionType).To(ContainSubstring("zstd"))

// Restore container
result = podmanTest.Podman([]string{"container", "restore", "-i", fileName})
result.WaitWithDefaultTimeout()
Expand All @@ -599,6 +611,12 @@ var _ = Describe("Podman checkpoint", func() {
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(podmanTest.NumberOfContainers()).To(Equal(0))

// Check the compression type of the exported file with checkpoint
// it should be "none"
compressionType, err = CheckCompressionType(fileName)
Expect(err).ShouldNot(HaveOccurred())
Expect(compressionType).To(ContainSubstring("none"))

// Restore container
result = podmanTest.Podman([]string{"container", "restore", "-i", fileName})
result.WaitWithDefaultTimeout()
Expand All @@ -618,6 +636,12 @@ var _ = Describe("Podman checkpoint", func() {
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(podmanTest.NumberOfContainers()).To(Equal(0))

// Check the compression type of the exported file with checkpoint
// it should be "gzip"
compressionType, err = CheckCompressionType(fileName)
Expect(err).ShouldNot(HaveOccurred())
Expect(compressionType).To(ContainSubstring("gzip"))

// Restore container
result = podmanTest.Podman([]string{"container", "restore", "-i", fileName})
result.WaitWithDefaultTimeout()
Expand Down
28 changes: 28 additions & 0 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,31 @@ func WriteRSAKeyPair(fileName string, bitSize int) (string, string, error) {

return publicKeyFileName, privateKeyFileName, nil
}

// Check a compression type for a file
func CheckCompressionType(fileName string) (string, error) {
file, err := os.Open(fileName)

if err != nil {
return "", err
}

defer file.Close()

buff := make([]byte, 512)

_, err = file.Read(buff)

if err != nil {
return "", err
}

switch string(buff[:3]) {
case "\x28\xb5\x2f":
return "zstd", nil
case "\x1f\x8b\x08":
return "gzip", nil
default:
return "none", nil
}
}