-
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
fix mount and umount bug #2029
fix mount and umount bug #2029
Conversation
Codecov ReportPatch coverage has no change and project coverage change:
📣 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
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. |
e9eb8f2
to
3b09379
Compare
cmd/sealer/cmd/alpha/mount.go
Outdated
` | ||
|
||
const ( | ||
containerID = "CONTAINER 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.
add table prefix
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.
tableHeaderContainerID
cmd/sealer/cmd/alpha/mount.go
Outdated
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) |
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.
extract the table writer as separate method
cmd/sealer/cmd/alpha/mount.go
Outdated
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 { |
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.
return fast, avoid large code depth
cmd/sealer/cmd/alpha/umount.go
Outdated
if err := removeContainerDir(image, file, imgName); err != nil { | ||
return err | ||
for _, container := range containers { | ||
if container.ImageID == 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.
if container.ImageID != imageID{
continue
}
9e61c57
to
72cdb75
Compare
7b6bffc
to
98d2004
Compare
e3146d8
to
d438bb1
Compare
cmd/sealer/cmd/alpha/mount.go
Outdated
return id | ||
} | ||
|
||
func contain(imageName string, images []string) bool { |
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.
string slice contains
cmd/sealer/cmd/alpha/mount.go
Outdated
return err | ||
for _, name := range args { | ||
imageID := getImageID(images, name) | ||
if ok := contain(imageID, imageIDList); !ok { |
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.
return fast
cmd/sealer/cmd/alpha/mount.go
Outdated
return imgName, imageID | ||
} | ||
|
||
func getImageID(images []storage.Image, name string) 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.
how to determine the current os arch
cmd/sealer/cmd/alpha/mount.go
Outdated
|
||
func contain(imageName string, images []string) bool { | ||
for _, image := range images { | ||
if imageName == image || strings.Contains(image, 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.
Contains/hasPrefix
4918848
to
d7242af
Compare
cmd/sealer/cmd/alpha/mount.go
Outdated
tableHeaderContainerID = "CONTAINER ID" | ||
) | ||
|
||
type Mounter struct { |
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.
MountService
cmd/sealer/cmd/alpha/mount.go
Outdated
|
||
//too fast to mount. | ||
time.Sleep(time.Second * 1) | ||
func NewMountInfo() (Mounter, 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.
NewMountService
cmd/sealer/cmd/alpha/mount.go
Outdated
if err != nil { | ||
return err | ||
} | ||
|
||
//output mount list | ||
if len(args) == 0 { | ||
if err := mountList(images); err != nil { | ||
if err := mountInfo.generateMountList(); 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.
Show()
cmd/sealer/cmd/alpha/mount.go
Outdated
return err | ||
func (m Mounter) generateMountList() error { | ||
table := tablewriter.NewWriter(common.StdOut) | ||
table.SetHeader([]string{imageName, tableHeaderContainerID, tableHeaderMountPath}) |
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 should split table render from this func
cmd/sealer/cmd/alpha/mount.go
Outdated
return "" | ||
} | ||
|
||
func (m Mounter) mount(imageNameOrID []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.
Mount(imageNameOrID []string) error
cmd/sealer/cmd/alpha/mount.go
Outdated
|
||
for _, name := range imageNameOrID { | ||
imageID := m.getImageID(name) | ||
if ok := utilsstrings.IsInSlice(imageID, imageIDList); !ok { |
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.
ok := utilsstrings.IsInSlice(imageID, imageIDList)
if ok{
logrus.Infof("this image has already been mounted, please do not repeat the operation")
}
// do others
cmd/sealer/cmd/alpha/umount.go
Outdated
} | ||
logrus.Infof("umount all cluster image successful") | ||
logrus.Infof("umount all mount information was successful") |
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.
successful to umount all sealer image
cmd/sealer/cmd/alpha/umount.go
Outdated
imgName = args[0] | ||
} | ||
} | ||
func (m Mounter) umount(imageNameOrID []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.
Umount(imageNameOrID []string)
cmd/sealer/cmd/alpha/umount.go
Outdated
for _, n := range image.Names { | ||
if n == imageName { | ||
return image.ID, nil | ||
func (m Mounter) umountAllContainers() 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.
UmountAllContainers() error
cmd/sealer/cmd/alpha/umount.go
Outdated
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") |
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.
imageIp?
cmd/sealer/cmd/alpha/umount.go
Outdated
} | ||
lastError = fmt.Errorf("error unmounting container %q: %w", builder.Container, err) |
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.
failed to
cmd/sealer/cmd/alpha/umount.go
Outdated
} | ||
lastError = fmt.Errorf("error unmounting container %s: %w", name, err) |
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.
failed to
cmd/sealer/cmd/alpha/umount.go
Outdated
} | ||
lastError = fmt.Errorf("error unmounting container %s: %w", name, err) |
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.
container ?
cmd/sealer/cmd/alpha/umount.go
Outdated
ContainerNamesOrIDs: []string{containerID}}, | ||
); err != nil { | ||
return err | ||
builder, err := buildah.OpenBuilder(context.TODO(), m.store, containerID) |
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.
what is builder? rename it to client ?
27bdd07
to
bd2d1c4
Compare
cmd/sealer/cmd/alpha/mount.go
Outdated
ok := utilsstrings.IsInSlice(imageID, imageIDList) | ||
if ok { | ||
logrus.Infof("this image has already been mounted, please do not repeat the operation") | ||
} else { |
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.
continue here directly
cmd/sealer/cmd/alpha/umount.go
Outdated
} | ||
if err = client.Unmount(); err != nil { | ||
if lastError != nil { | ||
fmt.Fprintln(os.Stderr, lastError) |
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.
return error here
7cf2803
to
79262b6
Compare
e779dee
to
59035bf
Compare
a4cfea4
to
cad1aa6
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
fix sealer alpha mount and sealer alpha umount bug
sealer alpha mount ex:
sealer alpha umount ex:
Does this pull request fix one issue?
Fixes #2000
Describe how you did it
Describe how to verify it
Special notes for reviews