-
Notifications
You must be signed in to change notification settings - Fork 362
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 sealer alpha mount command #1848
Conversation
|
||
func NewCreateRootfsCmd() *cobra.Command { | ||
createRootfsCmd := &cobra.Command{ | ||
Use: "create-rootfs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about named: sealer alpha mount my-image /tmp
var longCreateRootfsCmdDescription = `Check the image file to ensure that the Kubefile image is constructed correctly.` | ||
|
||
var exampleForCreateRootfsCmd = ` | ||
sealer alpha create-rootfs [image name or id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls set more specific example
if err != nil { | ||
return err | ||
} | ||
infraDriver, err := infradriver.NewInfraDriver(cluster) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need infraDriver? only use imageengine to do mount.
` | ||
|
||
func NewCreateRootfsCmd() *cobra.Command { | ||
createRootfsCmd := &cobra.Command{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also need umount sub command.
"github.com/spf13/cobra" | ||
) | ||
|
||
var longCreateRootfsCmdDescription = `Check the image file to ensure that the Kubefile image is constructed correctly.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update pls
cmd/sealer/cmd/alpha/mount.go
Outdated
Example: exampleForMountCmd, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
defaultPlatform := platform.GetDefaultPlatform() | ||
path := defaultPlatform.OS + "_" + defaultPlatform.Architecture + "_" + defaultPlatform.Variant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a common function to gen path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kakazhou is modify the mount dir, if his work done, the path should be different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The specified installation directory is used here and is not loaded back to the mount directory
284285d
to
101be51
Compare
Example: exampleForUmountCmd, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless Blank
cmd/sealer/cmd/alpha/mount.go
Outdated
Short: "mount image file", | ||
Long: longMountCmdDescription, | ||
Example: exampleForMountCmd, | ||
Args: cobra.ExactArgs(2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args: cobra.MinimumNArgs(1),
cmd/sealer/cmd/alpha/mount.go
Outdated
return err | ||
} | ||
if _, err := imageEngine.CreateWorkingContainer(&imagecommon.BuildRootfsOptions{ | ||
DestDir: args[1] + "/rootfs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do not modify the DestDir
cmd/sealer/cmd/alpha/mount.go
Outdated
return err | ||
} | ||
if _, err := imageEngine.CreateWorkingContainer(&imagecommon.BuildRootfsOptions{ | ||
DestDir: args[1] + "/rootfs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to determine in advance whether args[1]
is valid path address.
cmd/sealer/cmd/alpha/mount.go
Outdated
"github.com/spf13/cobra" | ||
) | ||
|
||
var longMountCmdDescription = `mount image file dir` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more detailed description is needed if we write longMountCmdDescription
Codecov ReportBase: 21.11% // Head: 21.70% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1848 +/- ##
==========================================
+ Coverage 21.11% 21.70% +0.58%
==========================================
Files 74 78 +4
Lines 6762 7055 +293
==========================================
+ Hits 1428 1531 +103
- Misses 5148 5322 +174
- Partials 186 202 +16
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
dc6ecc0
to
ad09883
Compare
cmd/sealer/cmd/alpha/umount.go
Outdated
return err | ||
} | ||
mounter := imagedistributor.NewBuildAhMounter(imageEngine) | ||
if err = mounter.Umount(args[0]); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use imageengine to do umount
}); err != nil { | ||
return err | ||
} | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
show user the specific path via fmt.println
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mount cluster image %s to %s successful
cmd/sealer/cmd/alpha/mount.go
Outdated
if err != nil { | ||
return err | ||
} | ||
if exists { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we need virtual path for mount, we should tell user via examples.
cmd/sealer/cmd/alpha/mount.go
Outdated
if len(args) < 2 { | ||
return fmt.Errorf("please enter full parameters") | ||
} | ||
exists, err := mount.PathExists(args[1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use utils os pkg IsFileExist
6877f1e
to
5191d56
Compare
cmd/sealer/cmd/alpha/mount.go
Outdated
if len(args) < 2 { | ||
return fmt.Errorf("please enter full parameters") | ||
} | ||
path, err := filepath.Abs(args[1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base dir
cmd/sealer/cmd/alpha/mount.go
Outdated
if err != nil { | ||
return err | ||
} | ||
if os.IsFileExist(path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use one line to check
}); err != nil { | ||
return err | ||
} | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mount cluster image %s to %s successful
cmd/sealer/cmd/alpha/umount.go
Outdated
return err | ||
} | ||
if err := imageEngine.RemoveContainer(&imagecommon.RemoveContainerOptions{ | ||
ContainerNamesOrIDs: nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dangerous ops: this will delete all running containers.
51ad922
to
615a23e
Compare
f6f04c5
to
b3696cc
Compare
sealer alpha mount registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.22.15 |
b92d915
to
eff42b9
Compare
beacaa9
to
82cbad8
Compare
82cbad8
to
b63060d
Compare
cmd/sealer/cmd/alpha/umount.go
Outdated
for _, image := range images { | ||
for _, n := range image.Names { | ||
if n == imageName { | ||
cid = image.ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return string
cmd/sealer/cmd/alpha/umount.go
Outdated
|
||
func removeContainerDir(image storage.Image, file fs.FileInfo, imageName string) error { | ||
for _, n := range image.Names { | ||
if n == imageName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if n == imageName && file.Name() == image.ID {return os.RemoveAll}
9a0b28c
to
7599094
Compare
edf57f5
to
4acc83c
Compare
4acc83c
to
362e5f4
Compare
@Stevent-fei Cloud please add some demo case as the description of this PR? |
cmd/sealer/cmd/alpha/mount.go
Outdated
) | ||
|
||
var longMountCmdDescription = ` | ||
mount the cluster image to '/var/lib/sealer/data/mountdir' the directory and check whether the contents of the build image and rootfs are consistent in advance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make mount dir configurable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make mount dir configurable
@starnop I think your suggestion is very good, but mount directory configurability needs to consider more parameters, how about setting it to the default directory /var/lib/sealer/data/overlay2?
} | ||
|
||
//output mount list | ||
if len(args) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a new function for listing images
we should make the main logic clean
44e2007
to
e578c51
Compare
b1c40a6
to
b259d60
Compare
) | ||
|
||
var longMountCmdDescription = ` | ||
mount the cluster image to '/var/lib/sealer/data/overlay2' the directory and check whether the contents of the build image and rootfs are consistent in advance |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we only mount to this path? Is it possible to specify the mount path?
@starnop Yes, mount to the default path; users don't need to care about the mount path, similar to the image file in containerd
RunE: func(cmd *cobra.Command, args []string) error { | ||
var cid string | ||
var imgName string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"github.com/containers/buildah" | ||
"github.com/containers/buildah/define" | ||
buildahcli "github.com/containers/buildah/pkg/cli" | ||
"github.com/containers/buildah/pkg/parse" | ||
"github.com/containers/common/pkg/config" | ||
encconfig "github.com/containers/ocicrypt/config" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete unused blank
for _, name := range i.Names { | ||
if name == args[0] || strings.Contains(i.ID, args[0]) { | ||
imageID = i.ID | ||
path = filepath.Join(common.DefaultLayerDir, imageID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make DefaultLayerDir configurable
And I think the default mount dir should not equal with the DefaultLayerDir
to prevent us from damaging an installed image.
cmd/sealer/cmd/alpha/mount.go
Outdated
"github.com/sealerio/sealer/pkg/imageengine/buildah" | ||
) | ||
|
||
var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why defined as global variable
cmd/sealer/cmd/alpha/umount.go
Outdated
Example: exampleForUmountCmd, | ||
Args: cobra.MaximumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var cid string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/cid/containerID
d0dc148
to
a521add
Compare
a521add
to
9900a90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Describe what this PR does / why we need it
add sealer alpha mount command and support check image file
we can go to the mount directory to check the mirrored files, which can ensure that the kubefile image is built correctly.
#1742
Does this pull request fix one issue?
Describe how you did it
Describe how to verify it
Special notes for reviews