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 sealer alpha mount command #1848

Merged
merged 1 commit into from
Jan 16, 2023

Conversation

Stevent-fei
Copy link
Collaborator

@Stevent-fei Stevent-fei commented Nov 10, 2022

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

image

  1. support sealer alpha mount imageName/imageId
  2. support sealer alpha umount imageNmae/imageId
  3. support sealer alpha mount(view mount list)

Does this pull request fix one issue?

Describe how you did it

Describe how to verify it

Special notes for reviews

@github-actions github-actions bot added the test label Nov 10, 2022
@Stevent-fei Stevent-fei changed the title Add sealer alpha command Add sealer alpha create-rootfs command Nov 10, 2022

func NewCreateRootfsCmd() *cobra.Command {
createRootfsCmd := &cobra.Command{
Use: "create-rootfs",
Copy link
Member

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]
Copy link
Member

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)
Copy link
Member

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{
Copy link
Member

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.`
Copy link
Member

Choose a reason for hiding this comment

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

update pls

@Stevent-fei Stevent-fei changed the title Add sealer alpha create-rootfs command Add sealer alpha mount command Nov 10, 2022
Example: exampleForMountCmd,
RunE: func(cmd *cobra.Command, args []string) error {
defaultPlatform := platform.GetDefaultPlatform()
path := defaultPlatform.OS + "_" + defaultPlatform.Architecture + "_" + defaultPlatform.Variant
Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Example: exampleForUmountCmd,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

Copy link
Member

Choose a reason for hiding this comment

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

Useless Blank

Short: "mount image file",
Long: longMountCmdDescription,
Example: exampleForMountCmd,
Args: cobra.ExactArgs(2),
Copy link
Member

Choose a reason for hiding this comment

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

Args: cobra.MinimumNArgs(1),

return err
}
if _, err := imageEngine.CreateWorkingContainer(&imagecommon.BuildRootfsOptions{
DestDir: args[1] + "/rootfs",
Copy link
Member

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

return err
}
if _, err := imageEngine.CreateWorkingContainer(&imagecommon.BuildRootfsOptions{
DestDir: args[1] + "/rootfs",
Copy link
Member

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.

"github.com/spf13/cobra"
)

var longMountCmdDescription = `mount image file dir`
Copy link
Member

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-commenter
Copy link

codecov-commenter commented Nov 11, 2022

Codecov Report

Base: 21.11% // Head: 21.70% // Increases project coverage by +0.58% 🎉

Coverage data is based on head (edf57f5) compared to base (fbd817f).
Patch coverage: 40.00% of modified lines in pull request are covered.

❗ Current head edf57f5 differs from pull request most recent head 4acc83c. Consider uploading reports for the commit 4acc83c to get more accurate results

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     
Impacted Files Coverage Δ
build/kubefile/parser/kubefile.go 53.44% <0.00%> (-1.91%) ⬇️
cmd/sealer/cmd/utils/cluster.go 63.54% <ø> (ø)
cmd/sealer/cmd/utils/hosts.go 84.21% <ø> (ø)
cmd/sealer/cmd/utils/validate.go 38.88% <ø> (ø)
pkg/cluster-runtime/hook.go 3.75% <ø> (-0.05%) ⬇️
pkg/image/reference/util.go 83.78% <ø> (ø)
pkg/clusterfile/clusterfile.go 28.45% <14.89%> (-5.99%) ⬇️
build/kubefile/parser/utils.go 60.75% <53.68%> (-10.67%) ⬇️
build/kubefile/parser/app_handler.go 47.36% <100.00%> (-2.03%) ⬇️
... and 5 more

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Stevent-fei Stevent-fei changed the title Add sealer alpha mount command [WIP]Add sealer alpha mount command Nov 15, 2022
@Stevent-fei Stevent-fei force-pushed the support_multiple_app branch 2 times, most recently from dc6ecc0 to ad09883 Compare November 16, 2022 03:50
@Stevent-fei Stevent-fei changed the title [WIP]Add sealer alpha mount command Add sealer alpha mount command Nov 16, 2022
return err
}
mounter := imagedistributor.NewBuildAhMounter(imageEngine)
if err = mounter.Umount(args[0]); 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.

use imageengine to do umount

}); err != nil {
return err
}
return nil
Copy link
Member

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

Copy link
Member

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

if err != nil {
return err
}
if exists {
Copy link
Member

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.

if len(args) < 2 {
return fmt.Errorf("please enter full parameters")
}
exists, err := mount.PathExists(args[1])
Copy link
Member

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

if len(args) < 2 {
return fmt.Errorf("please enter full parameters")
}
path, err := filepath.Abs(args[1])
Copy link
Member

Choose a reason for hiding this comment

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

base dir

if err != nil {
return err
}
if os.IsFileExist(path) {
Copy link
Member

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
Copy link
Member

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

return err
}
if err := imageEngine.RemoveContainer(&imagecommon.RemoveContainerOptions{
ContainerNamesOrIDs: nil,
Copy link
Member

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.

@github-actions github-actions bot added area/doc ImageBuilding related to all staff with image building labels Nov 17, 2022
@github-actions github-actions bot removed area/doc ImageBuilding related to all staff with image building labels Nov 17, 2022
@Stevent-fei Stevent-fei force-pushed the support_multiple_app branch 2 times, most recently from f6f04c5 to b3696cc Compare November 22, 2022 05:33
@kakaZhou719
Copy link
Member

kakaZhou719 commented Nov 29, 2022

sealer alpha mount registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.22.15
sealer alpha mount : if no cluster image specified ,will show all mounted cluster image with its absolutely dir name.
sealer alpha umount /var/lib/sealer/data/overlay2/${ID}, will umount this cluster image.
sealer alpha umount --all

@Stevent-fei Stevent-fei changed the title Add sealer alpha mount command [WIP]Add sealer alpha mount command Nov 30, 2022
@Stevent-fei Stevent-fei force-pushed the support_multiple_app branch 3 times, most recently from b92d915 to eff42b9 Compare November 30, 2022 09:03
@Stevent-fei Stevent-fei changed the title [WIP]Add sealer alpha mount command Add sealer alpha mount command Nov 30, 2022
for _, image := range images {
for _, n := range image.Names {
if n == imageName {
cid = image.ID
Copy link
Member

Choose a reason for hiding this comment

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

just return string


func removeContainerDir(image storage.Image, file fs.FileInfo, imageName string) error {
for _, n := range image.Names {
if n == imageName {
Copy link
Member

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}

@Stevent-fei Stevent-fei force-pushed the support_multiple_app branch 2 times, most recently from 9a0b28c to 7599094 Compare December 6, 2022 05:38
@Stevent-fei
Copy link
Collaborator Author

image

@Stevent-fei Stevent-fei force-pushed the support_multiple_app branch 2 times, most recently from edf57f5 to 4acc83c Compare December 7, 2022 12:47
@starnop
Copy link
Collaborator

starnop commented Dec 19, 2022

@Stevent-fei Cloud please add some demo case as the description of this PR?

)

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
Copy link
Collaborator

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

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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

@Stevent-fei Stevent-fei force-pushed the support_multiple_app branch 2 times, most recently from b1c40a6 to b259d60 Compare January 11, 2023 03:15
@github-actions github-actions bot removed the test label Jan 11, 2023
)

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.

Copy link
Collaborator Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please pre-check the args here. Otherwise, errors may be reported in the subsequent flow.

image

"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"

Copy link
Collaborator

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)
Copy link
Collaborator

@starnop starnop Jan 12, 2023

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.

"github.com/sealerio/sealer/pkg/imageengine/buildah"
)

var (
Copy link
Collaborator

@starnop starnop Jan 12, 2023

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

Example: exampleForUmountCmd,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var cid string
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/cid/containerID

Copy link
Collaborator

@starnop starnop left a comment

Choose a reason for hiding this comment

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

LGTM

@starnop starnop merged commit f816172 into sealerio:main Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants