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

sealer run-app supports concurrent run #1850

Merged
merged 1 commit into from
Nov 15, 2022

Conversation

kakaZhou719
Copy link
Member

@kakaZhou719 kakaZhou719 commented Nov 11, 2022

Describe what this PR does / why we need it

At present, our cluster image data is mixed with application image data and base image data, If we run multiple images at the same time, there will be conflicts.

  1. Detach the mount directory
    all imagedata mount directory will under below directory:
    /var/lib/sealer/data/mount/${imageName}/${platform}

all application imagedata rootfs directory will under below directory:
var/lib/sealer/data/${imageName}/rootfs/application/apps

all basefs imagedata directory will under below directory:
var/lib/sealer/data/${imageName}/rootfs

  1. add a file lock on .sealer/application.json

Does this pull request fix one issue?

Describe how you did it

Describe how to verify it

Special notes for reviews

@kakaZhou719 kakaZhou719 force-pushed the detach-raw-cluster-image branch from 8d9c883 to 7dc802d Compare November 11, 2022 07:02
@codecov-commenter
Copy link

codecov-commenter commented Nov 11, 2022

Codecov Report

Base: 21.65% // Head: 21.12% // Decreases project coverage by -0.52% ⚠️

Coverage data is based on head (3cc21a1) compared to base (f9cc112).
Patch coverage: 9.52% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1850      +/-   ##
==========================================
- Coverage   21.65%   21.12%   -0.53%     
==========================================
  Files          72       74       +2     
  Lines        6586     6760     +174     
==========================================
+ Hits         1426     1428       +2     
- Misses       4974     5146     +172     
  Partials      186      186              
Impacted Files Coverage Δ
pkg/cluster-runtime/apps.go 0.00% <0.00%> (ø)
pkg/cluster-runtime/installer.go 0.00% <0.00%> (ø)
pkg/cluster-runtime/scale.go 0.00% <0.00%> (ø)
pkg/imagedistributor/scp_distributor.go 0.00% <0.00%> (ø)
pkg/imagedistributor/mount.go 2.77% <20.00%> (ø)
pkg/infradriver/ssh_infradriver.go 38.91% <100.00%> (ø)

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.

@kakaZhou719 kakaZhou719 force-pushed the detach-raw-cluster-image branch from 7dc802d to 9bbd571 Compare November 11, 2022 07:13
@kakaZhou719 kakaZhou719 changed the title add image name to mount dir path sealer run-app supports concurrent run Nov 11, 2022
clusterRootfs = i.infraDriver.GetClusterRootfsPath()
ex = shell.NewLex('\\')
cmds []string
appPath = i.infraDriver.GetClusterRootfsPath()
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we can keep use clusterRootfs.

And In my understanding, we may need a new appRootPath variable, and it's going to be filepath.Join(clusterRootfs,"applications")

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, we should launch app in their own workspace, thats why i rename this value from "clusterRootfs" to "appRootPath". later we only need to update this func to support it directly.

imagecommon "github.com/sealerio/sealer/pkg/define/options"
"github.com/sealerio/sealer/pkg/imageengine"
v1 "github.com/sealerio/sealer/types/api/v1"
osi "github.com/sealerio/sealer/utils/os"
"github.com/sealerio/sealer/utils/os/fs"
)

const (
mountBaseDir = "/var/lib/sealer/data/mount"
Copy link
Collaborator

Choose a reason for hiding this comment

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

move it to. common/common.go file?

Copy link
Member Author

Choose a reason for hiding this comment

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

mountBaseDir is internal used , so i dont move it to pubic common.

if _, err := b.imageEngine.CreateWorkingContainer(&imagecommon.BuildRootfsOptions{
// make sure base mount Dir is existed.
err := fs.FS.MkdirAll(filepath.Dir(mountDir))
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider the following syntax to avoid widening the scope of error

if err := fs.FS.MkdirAll(filepath.Dir(mountDir));err!=nil{}

for _, info := range imageMountInfo {
err := c.Mounter.Umount(info.MountDir)
if err != nil {
return fmt.Errorf("failed to umount %s:%v", info.MountDir, err)
}
}
// delete all mounted images
if err := fs.FS.RemoveAll(filepath.Join(mountBaseDir, formatImageName(imageName))); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about extracting a public method to return the mount root directory for the specified image name?

@@ -125,3 +139,7 @@ func NewImageMounter(imageEngine imageengine.Interface, hostsPlatform map[v1.Pla
c.Mounter = NewBuildAhMounter(imageEngine)
return c, nil
}

func formatImageName(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.

add some unit tests and try to consider more scenarios

}

func (d *SSHInfraDriver) GetClusterBasePath() string {
return common.DefaultClusterBaseDir(d.clusterName)
return filepath.Join(common.DefaultSealerDataDir, d.clusterName)
Copy link
Collaborator

@starnop starnop Nov 12, 2022

Choose a reason for hiding this comment

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

ditto

@@ -337,11 +338,11 @@ func (d *SSHInfraDriver) GetHostsPlatform(hosts []net.IP) (map[v1.Platform][]net
}

func (d *SSHInfraDriver) GetClusterRootfsPath() string {
return common.DefaultTheClusterRootfsDir(d.clusterName)
return filepath.Join(common.DefaultSealerDataDir, d.clusterName, "rootfs")
Copy link
Collaborator

@starnop starnop Nov 12, 2022

Choose a reason for hiding this comment

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

why not keep it?

And I don't see a logical change

Copy link
Member Author

Choose a reason for hiding this comment

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

here i thought, the only way we get the cluster value such as "GetClusterRootfsPath" and the same kind parameters. not from common pkg directly .

Copy link
Collaborator

Choose a reason for hiding this comment

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

And then, should we delete the function common.DefaultTheClusterRootfsDir?

applicationFile := common.GetDefaultApplicationFile()
func (i AppInstaller) save(applicationFile string) error {
f, err := os.OpenFile(applicationFile, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0600)
defer func() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

use defer f.Close() is OK

Copy link
Member Author

Choose a reason for hiding this comment

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

golang lint will check the func return error ,to make sure each error was handled . so i use defer func()

}

extensionList = append(extensionList, i.extension)
content, err := json.Marshal(extensionList)
content, err := json.Marshal(i.extension)
Copy link
Collaborator

Choose a reason for hiding this comment

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

user defer func to unlock file locker here

if err != nil {
return fmt.Errorf("failed to marshal image extension: %v", err)
}

return osutils.NewCommonWriter(applicationFile).WriteFile(content)
_, err = f.Write(content)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

unify use
if err:=func();err!=nil{}

please check the whole picture for yourself

if err != nil {
return fmt.Errorf("failed to marshal image extension: %v", err)
}

return osutils.NewCommonWriter(applicationFile).WriteFile(content)
_, err = f.Write(content)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find these codes changed the existing logic and the old logic will append the extensions from the old applicationFile.

Cloud you please make a simple explanation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently ,it's also record app installations with append option, just separated from each installation record.

@github-actions github-actions bot added the test label Nov 14, 2022
@kakaZhou719 kakaZhou719 force-pushed the detach-raw-cluster-image branch from 3cc21a1 to 996f159 Compare November 14, 2022 06:56
add image name to mount dir path

add flock to application.json
@kakaZhou719 kakaZhou719 force-pushed the detach-raw-cluster-image branch from 996f159 to 14d591a Compare November 15, 2022 02:53
@starnop starnop merged commit 145eb4c into sealerio:main Nov 15, 2022
Stevent-fei pushed a commit to Stevent-fei/sealer that referenced this pull request Nov 17, 2022
add image name to mount dir path

add flock to application.json
@kakaZhou719 kakaZhou719 deleted the detach-raw-cluster-image branch June 28, 2023 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants