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

Support copying files in volume #200

Merged

Conversation

fahedouch
Copy link
Member

fixing #165

@fahedouch fahedouch force-pushed the support_copying_files_in_volume branch 2 times, most recently from cf587a5 to d10e861 Compare April 29, 2021 22:44
@fahedouch fahedouch marked this pull request as draft April 29, 2021 22:44
@fahedouch fahedouch changed the title Support copying files in volume [WIP] Support copying files in volume Apr 29, 2021
@fahedouch fahedouch force-pushed the support_copying_files_in_volume branch 3 times, most recently from 7a00aaa to a82b0d0 Compare April 30, 2021 13:06
@fahedouch fahedouch marked this pull request as ready for review April 30, 2021 13:07
@fahedouch fahedouch changed the title [WIP] Support copying files in volume Support copying files in volume Apr 30, 2021
run_mount.go Outdated

s := client.SnapshotService(clicontext.String("snapshotter"))

tempDir, err := ioutil.TempDir(os.Getenv("GOTMPDIR"), "initialC")
Copy link
Member

Choose a reason for hiding this comment

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

Why GOTMPDIR

Copy link
Member Author

@fahedouch fahedouch Apr 30, 2021

Choose a reason for hiding this comment

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

it is just a choice. I can create tempDir in in the default location for OS. it doesn't change anything for me

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to tempDir, err := ioutil.TempDir("", "initialC")

run_mount.go Outdated
target := strings.Join([]string{tempDir, imgVol}, "")

//copying up initial contents of the mount point directory
copyExistingContents(target, anonVol.Mountpoint)
Copy link
Member

Choose a reason for hiding this comment

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

Named volumes need this as well

Copy link
Member

Choose a reason for hiding this comment

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

Also make sure to catch err

Copy link
Member Author

Choose a reason for hiding this comment

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

@AkihiroSuda I made modification. FYI : in docker named volume do not copy initial content ( that may override source volume)

Copy link
Member Author

Choose a reason for hiding this comment

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

@AkihiroSuda sorry I mixed mount bind and named volume. I added copyExistingContentsto named volume

@fahedouch fahedouch force-pushed the support_copying_files_in_volume branch 2 times, most recently from fd20868 to 66e8281 Compare May 3, 2021 14:35
base.Cmd("run", "-v", "/mnt", "--rm", imageName).AssertOut("hi")

//NamedVolume
base.Cmd("run", "-v", "/home:/mnt", "--rm", imageName).AssertFail()
Copy link
Member

Choose a reason for hiding this comment

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

This is a bind mount, not a named volume (nerdctl volume create)

run_mount.go Outdated
imgVol := filepath.Clean(imgVolRaw)
target := strings.Join([]string{tempDir, imgVol}, "")

//Coyping content only for AnonymousVolume
Copy link
Member

Choose a reason for hiding this comment

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

No

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

run_mount.go Outdated

if ensuredImage != nil {
imageVolumes = ensuredImage.ImageConfig.Volumes
client, ctx, cancel, err := newClient(clicontext)
Copy link
Member

Choose a reason for hiding this comment

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

No, we already have the client

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

Doesn’t seem fixed

Copy link
Member Author

Choose a reason for hiding this comment

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

it should be ok now!

@@ -90,7 +96,7 @@ func ProcessFlagV(s string, volStore volumestore.VolumeStore) (*Processed, error
return nil, errors.Errorf("failed to parse %q", s)
}
res.Mount = specs.Mount{
Type: "none",
Type: string(vType),
Copy link
Member

Choose a reason for hiding this comment

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

This is an OCI Mount object, you can’t mix up Docker API type here

Copy link
Member Author

@fahedouch fahedouch May 3, 2021

Choose a reason for hiding this comment

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

@AkihiroSuda does OCI provide types values ? or I may set them directly in the code ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@AkihiroSuda is it ok for you ?

@AkihiroSuda AkihiroSuda marked this pull request as draft May 3, 2021 19:20
base.Cmd("volume","create", "copying-initial-content").AssertOK()
base.Cmd("run", "-v", "copying-initial-content:/mnt", "--rm", imageName).AssertOut("hi")
//mount bind
base.Cmd("run", "-v", "/home:/mnt", "--rm", imageName).AssertFail()
Copy link
Member

@AkihiroSuda AkihiroSuda May 3, 2021

Choose a reason for hiding this comment

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

Mounting /home is dangerous, please use some ioutil.TempDir

@fahedouch fahedouch force-pushed the support_copying_files_in_volume branch 3 times, most recently from ff22da0 to 86e8f5f Compare May 4, 2021 22:44
@fahedouch fahedouch marked this pull request as ready for review May 4, 2021 22:44
@@ -90,7 +93,7 @@ func ProcessFlagV(s string, volStore volumestore.VolumeStore) (*Processed, error
return nil, errors.Errorf("failed to parse %q", s)
}
res.Mount = specs.Mount{
Type: "none",
Type: vType,
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

The type fIeld can be in this struct

type Processed struct {

Copy link
Member Author

Choose a reason for hiding this comment

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

@AkihiroSuda moved.

@AkihiroSuda AkihiroSuda marked this pull request as draft May 5, 2021 04:26
@fahedouch fahedouch marked this pull request as ready for review May 6, 2021 18:39
@fahedouch fahedouch force-pushed the support_copying_files_in_volume branch 2 times, most recently from cdff425 to 6a9b795 Compare May 6, 2021 18:40
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)

m := strings.Join([]string{"./", tmpDir, ":", "/mnt"}, "")
Copy link
Member

Choose a reason for hiding this comment

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

You don’t need ./ here

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -32,6 +32,7 @@ import (
type Processed struct {
Mount specs.Mount
AnonymousVolume string // name
Type string
Copy link
Member

Choose a reason for hiding this comment

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

enum (Bind = iota, Volume)

Copy link
Member Author

@fahedouch fahedouch May 9, 2021

Choose a reason for hiding this comment

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

@AkihiroSuda can review plz.

@fahedouch fahedouch force-pushed the support_copying_files_in_volume branch 2 times, most recently from b63c6f0 to 05d4340 Compare May 6, 2021 21:56
@fahedouch
Copy link
Member Author

fahedouch commented May 7, 2021

@AkihiroSuda any idea what is disturbing the cgroup2 job ?

return nil, nil, err
}

if err := mount.All(mounts, tempDir); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Where are the mounts getting cleaned up? The temp mount logic is ideal for these type of use cases

Copy link
Member Author

Choose a reason for hiding this comment

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

@dmcgowan I added unmount logic . The temp mount logic is ideal but not in this context because it push me to make same steps ( tmp dir creation then mount then unmount ) in each iteration flagVSlice

Copy link
Member

Choose a reason for hiding this comment

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

I think it depends on user cannot CONTRL-C during copy. Need to figure out how to clean up in this case

Copy link
Member Author

Choose a reason for hiding this comment

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

@fahedouch fahedouch force-pushed the support_copying_files_in_volume branch 2 times, most recently from 0bb9b2e to c245c9c Compare May 9, 2021 23:24
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Pushed a new test.

LGTM if green. Thanks and sorry for slow reviewing

@AkihiroSuda AkihiroSuda requested review from fuweid and ktock May 17, 2021 05:12
run_mount.go Outdated Show resolved Hide resolved
run_mount.go Outdated Show resolved Hide resolved
@ktock
Copy link
Member

ktock commented May 17, 2021

needs rebase

Conflicting files
go.mod

fahedouch and others added 4 commits May 17, 2021 15:37
Signed-off-by: fahed dorgaa <fahed.dorgaa@gmail.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
The commit c245c9c "support copying files in volume"
(rebased as 89daa2b) improperly used `strings.Join` to join paths.

The new commit replaces `strings.Join` with `securejoin.SecureJoin`.

The problematic commit was not merged into the existing releases, so
nobody was exposed to potential vulns.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
@AkihiroSuda AkihiroSuda force-pushed the support_copying_files_in_volume branch from 697d2e7 to a0390ad Compare May 17, 2021 06:39
@fahedouch
Copy link
Member Author

@AkihiroSuda should we test hardlink too ?

}()

if err := mount.All(mounts, tempDir); err != nil {
if err := s.Remove(ctx, tempDir); err != nil && !errdefs.IsNotFound(err) {
Copy link
Member

Choose a reason for hiding this comment

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

need to umount first and then remove

Copy link
Member Author

Choose a reason for hiding this comment

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

@fuweid
Copy link
Member

fuweid commented May 18, 2021

Using tar and echo might be safety, like what kubectl cp does. It is hard to handle corner cases in nerdctl side.

WDYT? @AkihiroSuda @dmcgowan

@AkihiroSuda
Copy link
Member

@fahedouch

should we test hardlink too ?

Yes, that's more preferrable.


@fuweid

Using tar and echo might be safety, like what kubectl cp does. It is hard to handle corner cases in nerdctl side.

How do you use echo?
Could you open an issue/PR?

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

Successfully merging this pull request may close these issues.

5 participants