Skip to content

Commit

Permalink
🐛 fix env merge for sealos run (#4144)
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <cuisongliu@qq.com>
  • Loading branch information
cuisongliu committed Oct 23, 2023
1 parent 4057aac commit 311213a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
9 changes: 0 additions & 9 deletions pkg/clusterfile/pre_process.go
Expand Up @@ -17,8 +17,6 @@ package clusterfile
import (
"bytes"
"errors"
"os"
"strings"

"helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/getter"
Expand Down Expand Up @@ -48,13 +46,6 @@ func (c *ClusterFile) Process() (err error) {
}
c.once.Do(func() {
err = func() error {
for i := range c.customEnvs {
kv := strings.SplitN(c.customEnvs[i], "=", 2)
if len(kv) == 2 {
logger.Debug("set env: %s=%s", kv[0], kv[1])
_ = os.Setenv(kv[0], kv[1])
}
}
clusterFileData, err := c.loadClusterFile()
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions pkg/guest/guest.go
Expand Up @@ -42,7 +42,7 @@ func NewGuestManager() (Interface, error) {
}

func (d *Default) Apply(cluster *v2.Cluster, mounts []v2.MountImage, targetHosts []string) error {
envWrapper := env.NewEnvProcessor(cluster)
envGetter := env.NewEnvProcessor(cluster)
execer := ssh.NewSSHByCluster(cluster, true)

for i, m := range mounts {
Expand All @@ -51,7 +51,7 @@ func (d *Default) Apply(cluster *v2.Cluster, mounts []v2.MountImage, targetHosts
eg, ctx := errgroup.WithContext(context.Background())
for j := range targetHosts {
node := targetHosts[j]
envs := envWrapper.Getenv(node)
envs := maps.MergeMap(m.Env, envGetter.Getenv(node))
cmds := formalizeImageCommands(cluster, i, m, envs)
eg.Go(func() error {
return execer.CmdAsyncWithContext(ctx, node,
Expand All @@ -64,7 +64,7 @@ func (d *Default) Apply(cluster *v2.Cluster, mounts []v2.MountImage, targetHosts
}
case m.IsApplication():
// on run on the first master
envs := envWrapper.Getenv(cluster.GetMaster0IP())
envs := maps.MergeMap(m.Env, envGetter.Getenv(cluster.GetMaster0IP()))
cmds := formalizeImageCommands(cluster, i, m, envs)
if err := execer.CmdAsync(cluster.GetMaster0IPAndPort(),
stringsutil.RenderShellFromEnv(strings.Join(cmds, "; "), envs),
Expand Down

0 comments on commit 311213a

Please sign in to comment.