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

feature: sync .sealos workdir #3903

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions pkg/apply/applydrivers/apply_drivers_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/labring/sealos/pkg/client-go/kubernetes"
"github.com/labring/sealos/pkg/clusterfile"
"github.com/labring/sealos/pkg/constants"
"github.com/labring/sealos/pkg/ssh"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/confirm"
"github.com/labring/sealos/pkg/utils/iputils"
Expand Down Expand Up @@ -79,20 +80,14 @@ type Applier struct {
}

func (c *Applier) Apply() error {
clusterPath := constants.Clusterfile(c.ClusterDesired.Name)
// clusterErr and appErr should not appear in the same time
var clusterErr, appErr error
// save cluster to file after apply
defer func() {
switch clusterErr.(type) {
case *processor.CheckError, *processor.PreProcessError:
return
}
logger.Debug("save objects into local: %s, objects: %v", clusterPath, c.getWriteBackObjects())
saveErr := yaml.MarshalFile(clusterPath, c.getWriteBackObjects()...)
if saveErr != nil {
logger.Error("failed to serialize into file: %s error, %s", clusterPath, saveErr)
}
c.applyAfter()
}()
c.initStatus()
if c.ClusterCurrent == nil || c.ClusterCurrent.CreationTimestamp.IsZero() {
Expand Down Expand Up @@ -273,3 +268,30 @@ func (c *Applier) deleteCluster() error {
logger.Info("succeeded in deleting current cluster")
return nil
}

func (c *Applier) syncWorkdir() {
workDir := constants.ClusterDir(c.ClusterDesired.Name)
Copy link
Collaborator

@cuisongliu cuisongliu Sep 12, 2023

Choose a reason for hiding this comment

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

if exec sealos user is root and other node user name is not root , same this dir not using all nodes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes !,it should be ~/. sealos/.

Copy link
Collaborator Author

@ghostloda ghostloda Sep 12, 2023

Choose a reason for hiding this comment

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

if exec sealos user is root and other node user name is not root , same this dir not using all nodes.

I'll make some modifications to this code

sshCmd, err := ssh.NewExecCmdFromRoles(c.ClusterDesired, v2.MASTER)
cuisongliu marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
logger.Error("failed to sync workdir: %v", err)
}
err = sshCmd.RunCopy(workDir, workDir)
if err != nil {
logger.Error("failed to sync workdir: %s error, %v", workDir, err)
}
}

// save cluster to file after apply
func (c *Applier) saveClusterFile() {
clusterPath := constants.Clusterfile(c.ClusterDesired.Name)
logger.Debug("save objects into local: %s, objects: %v", clusterPath, c.getWriteBackObjects())
saveErr := yaml.MarshalFile(clusterPath, c.getWriteBackObjects()...)
if saveErr != nil {
logger.Error("failed to serialize into file: %s error, %s", clusterPath, saveErr)
}
}

func (c *Applier) applyAfter() {
c.saveClusterFile()
c.syncWorkdir()
}