-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add support to migrate containers #2272
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
Changes from all commits
e0c8c14
a05cfd2
0028578
2aa3261
7b1ab8a
42e903d
a4d3333
0e072f9
bef83c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
| "github.com/containers/storage/pkg/archive" | ||
| "github.com/containers/storage/pkg/mount" | ||
| spec "github.com/opencontainers/runtime-spec/specs-go" | ||
| "github.com/opencontainers/runtime-tools/generate" | ||
| "github.com/opencontainers/selinux/go-selinux/label" | ||
| opentracing "github.com/opentracing/opentracing-go" | ||
| "github.com/pkg/errors" | ||
|
|
@@ -1345,7 +1346,7 @@ func (c *Container) appendStringToRundir(destFile, output string) (string, error | |
| return filepath.Join(c.state.RunDir, destFile), nil | ||
| } | ||
|
|
||
| // Save OCI spec to disk, replacing any existing specs for the container | ||
| // saveSpec saves the OCI spec to disk, replacing any existing specs for the container | ||
| func (c *Container) saveSpec(spec *spec.Spec) error { | ||
| // If the OCI spec already exists, we need to replace it | ||
| // Cannot guarantee some things, e.g. network namespaces, have the same | ||
|
|
@@ -1501,3 +1502,40 @@ func (c *Container) checkReadyForRemoval() error { | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| // writeJSONFile marshalls and writes the given data to a JSON file | ||
| // in the bundle path | ||
| func (c *Container) writeJSONFile(v interface{}, file string) (err error) { | ||
| fileJSON, err := json.MarshalIndent(v, "", " ") | ||
| if err != nil { | ||
| return errors.Wrapf(err, "error writing JSON to %s for container %s", file, c.ID()) | ||
| } | ||
| file = filepath.Join(c.bundlePath(), file) | ||
| if err := ioutil.WriteFile(file, fileJSON, 0644); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // prepareCheckpointExport writes the config and spec to | ||
| // JSON files for later export | ||
| func (c *Container) prepareCheckpointExport() (err error) { | ||
| // save live config | ||
| if err := c.writeJSONFile(c.Config(), "config.dump"); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // save spec | ||
| jsonPath := filepath.Join(c.bundlePath(), "config.json") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this just a file copy? We can probably use mrunalp/fileutils which has a CopyFile() function in it
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is almost a copy, but this is used to output the whole spec which has more information than only the config.json. Using copy would leave out some information. |
||
| g, err := generate.NewFromFile(jsonPath) | ||
| if err != nil { | ||
| logrus.Debugf("generating spec for container %q failed with %v", c.ID(), err) | ||
| return err | ||
| } | ||
| if err := c.writeJSONFile(g.Spec(), "spec.dump"); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.