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

fix mount and umount bug #2029

Merged
merged 1 commit into from
Mar 7, 2023
Merged

Conversation

Stevent-fei
Copy link
Collaborator

@Stevent-fei Stevent-fei commented Feb 14, 2023

Describe what this PR does / why we need it

fix sealer alpha mount and sealer alpha umount bug

sealer alpha mount ex:

Mount image name:
    sealer alpha mount imageName

Mount image id:
    sealer alpha mount ba15e47f5969

sealer alpha umount ex:

Umount image containerID:
    sealer alpha umount ba15e47f5969

Uninstall all images:
    sealer alpha umount --all

Does this pull request fix one issue?

Fixes #2000

Describe how you did it

Describe how to verify it

Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2023

Codecov Report

Patch coverage has no change and project coverage change: +0.89 🎉

Comparison is base (f983d9b) 18.40% compared to head (a4cfea4) 19.29%.

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

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2029      +/-   ##
==========================================
+ Coverage   18.40%   19.29%   +0.89%     
==========================================
  Files         101       96       -5     
  Lines        9201     8985     -216     
==========================================
+ Hits         1693     1734      +41     
+ Misses       7277     7026     -251     
+ Partials      231      225       -6     
Impacted Files Coverage Δ
pkg/imageengine/buildah/commit.go 0.00% <0.00%> (ø)
pkg/imageengine/buildah/common.go 0.00% <0.00%> (ø)
pkg/imageengine/buildah/config.go 0.00% <0.00%> (ø)
pkg/imageengine/buildah/copy.go 0.00% <0.00%> (ø)
pkg/imageengine/buildah/images.go 0.00% <0.00%> (ø)
pkg/imageengine/buildah/mount.go 0.00% <0.00%> (ø)
pkg/imageengine/buildah/remove_container.go 0.00% <0.00%> (ø)
pkg/application/v2app.go 29.34% <0.00%> (-24.94%) ⬇️
pkg/infradriver/ssh_infradriver.go 31.32% <0.00%> (-3.64%) ⬇️
build/kubefile/parser/kubefile.go 33.33% <0.00%> (-3.49%) ⬇️
... and 34 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.

`

const (
containerID = "CONTAINER ID"
Copy link
Collaborator

Choose a reason for hiding this comment

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

add table prefix

Copy link
Collaborator

Choose a reason for hiding this comment

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

tableHeaderContainerID

images, err := store.Images()
if err != nil {
return err
}

//output mount list
if len(args) == 0 {
if err := mountList(images); err != nil {
return err
table := tablewriter.NewWriter(common.StdOut)
Copy link
Collaborator

Choose a reason for hiding this comment

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

extract the table writer as separate method

if _, err = os.Stat(path); err == nil {
return fmt.Errorf("destination directionay %s exists, you should remove it first", path)
for _, container := range containers {
if builder.ContainerID == container.ID && mounted {
Copy link
Collaborator

Choose a reason for hiding this comment

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

return fast, avoid large code depth

if err := removeContainerDir(image, file, imgName); err != nil {
return err
for _, container := range containers {
if container.ImageID == imageID {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if container.ImageID != imageID{
continue
}

@Stevent-fei Stevent-fei changed the title fix mount and umount bug [WIP]fix mount and umount bug Feb 27, 2023
@Stevent-fei Stevent-fei changed the title [WIP]fix mount and umount bug fix mount and umount bug Feb 28, 2023
return id
}

func contain(imageName string, images []string) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

string slice contains

return err
for _, name := range args {
imageID := getImageID(images, name)
if ok := contain(imageID, imageIDList); !ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

return fast

return imgName, imageID
}

func getImageID(images []storage.Image, name string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how to determine the current os arch


func contain(imageName string, images []string) bool {
for _, image := range images {
if imageName == image || strings.Contains(image, imageName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Contains/hasPrefix

@Stevent-fei Stevent-fei force-pushed the fix_mount_bug branch 2 times, most recently from 4918848 to d7242af Compare March 1, 2023 06:44
tableHeaderContainerID = "CONTAINER ID"
)

type Mounter struct {
Copy link
Member

Choose a reason for hiding this comment

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

MountService


//too fast to mount.
time.Sleep(time.Second * 1)
func NewMountInfo() (Mounter, error) {
Copy link
Member

Choose a reason for hiding this comment

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

NewMountService

if err != nil {
return err
}

//output mount list
if len(args) == 0 {
if err := mountList(images); err != nil {
if err := mountInfo.generateMountList(); 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.

Show()

return err
func (m Mounter) generateMountList() error {
table := tablewriter.NewWriter(common.StdOut)
table.SetHeader([]string{imageName, tableHeaderContainerID, tableHeaderMountPath})
Copy link
Member

Choose a reason for hiding this comment

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

you should split table render from this func

return ""
}

func (m Mounter) mount(imageNameOrID []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.

Mount(imageNameOrID []string) error


for _, name := range imageNameOrID {
imageID := m.getImageID(name)
if ok := utilsstrings.IsInSlice(imageID, imageIDList); !ok {
Copy link
Member

Choose a reason for hiding this comment

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

ok := utilsstrings.IsInSlice(imageID, imageIDList)
if ok{
logrus.Infof("this image has already been mounted, please do not repeat the operation")
}
// do others

}
logrus.Infof("umount all cluster image successful")
logrus.Infof("umount all mount information was successful")
Copy link
Member

Choose a reason for hiding this comment

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

successful to umount all sealer image

imgName = args[0]
}
}
func (m Mounter) umount(imageNameOrID []string) {
Copy link
Member

Choose a reason for hiding this comment

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

Umount(imageNameOrID []string)

for _, n := range image.Names {
if n == imageName {
return image.ID, nil
func (m Mounter) umountAllContainers() error {
Copy link
Member

Choose a reason for hiding this comment

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

UmountAllContainers() error

RunE: func(cmd *cobra.Command, args []string) error {
var containerID string
var imgName string

if len(args) == 0 && !umountAll {
return fmt.Errorf("you must input imageName Or imageIp")
Copy link
Member

Choose a reason for hiding this comment

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

imageIp?

}
lastError = fmt.Errorf("error unmounting container %q: %w", builder.Container, err)
Copy link
Member

Choose a reason for hiding this comment

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

failed to

}
lastError = fmt.Errorf("error unmounting container %s: %w", name, err)
Copy link
Member

Choose a reason for hiding this comment

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

failed to

}
lastError = fmt.Errorf("error unmounting container %s: %w", name, err)
Copy link
Member

Choose a reason for hiding this comment

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

container ?

ContainerNamesOrIDs: []string{containerID}},
); err != nil {
return err
builder, err := buildah.OpenBuilder(context.TODO(), m.store, containerID)
Copy link
Member

Choose a reason for hiding this comment

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

what is builder? rename it to client ?

ok := utilsstrings.IsInSlice(imageID, imageIDList)
if ok {
logrus.Infof("this image has already been mounted, please do not repeat the operation")
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

continue here directly

}
if err = client.Unmount(); err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
Copy link
Collaborator

Choose a reason for hiding this comment

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

return error here

@Stevent-fei Stevent-fei force-pushed the fix_mount_bug branch 3 times, most recently from e779dee to 59035bf Compare March 7, 2023 03:49
Copy link
Member

@kakaZhou719 kakaZhou719 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

[BUG] failed to run sealer alpha mount
4 participants