diff --git a/cmd/sealos/cmd/gen.go b/cmd/sealos/cmd/gen.go index 786e27a1923..c0180330929 100644 --- a/cmd/sealos/cmd/gen.go +++ b/cmd/sealos/cmd/gen.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/cobra" "github.com/labring/sealos/pkg/apply" + "github.com/labring/sealos/pkg/utils/logger" ) var exampleGen = ` @@ -65,6 +66,7 @@ func newGenCmd() *cobra.Command { var outputWriter io.WriteCloser switch out { case "", "stdout": + logger.Info("if you want to save the output of gen command, use '--output' option instead of redirecting to file") outputWriter = os.Stdout default: outputWriter, err = os.Create(out) diff --git a/pkg/apply/args.go b/pkg/apply/args.go index 31b98bf993e..d5ec84182a2 100644 --- a/pkg/apply/args.go +++ b/pkg/apply/args.go @@ -65,7 +65,7 @@ type RunArgs struct { func (arg *RunArgs) RegisterFlags(fs *pflag.FlagSet) { arg.Cluster.RegisterFlags(fs, "run with", "run") arg.SSH.RegisterFlags(fs) - fs.StringSliceVarP(&arg.CustomEnv, "env", "e", []string{}, "environment variables to set during command execution") + fs.StringSliceVarP(&arg.CustomEnv, "env", "e", []string{}, "environment variables to be set for images") fs.StringSliceVar(&arg.CustomCMD, "cmd", []string{}, "override CMD directive in images") fs.StringSliceVar(&arg.CustomConfigFiles, "config-file", []string{}, "path of custom config files, to use to replace the resource") } @@ -80,7 +80,7 @@ type Args struct { func (arg *Args) RegisterFlags(fs *pflag.FlagSet) { fs.StringSliceVar(&arg.Values, "values", []string{}, "values file to apply into Clusterfile") fs.StringSliceVar(&arg.Sets, "set", []string{}, "set values on the command line") - fs.StringSliceVar(&arg.CustomEnv, "env", []string{}, "environment variables to set during command execution") + fs.StringSliceVar(&arg.CustomEnv, "env", []string{}, "environment variables to be set for images") fs.StringSliceVar(&arg.CustomConfigFiles, "config-file", []string{}, "path of custom config files, to use to replace the resource") } diff --git a/pkg/apply/gen.go b/pkg/apply/gen.go index 3747280e7db..dd13558eab5 100644 --- a/pkg/apply/gen.go +++ b/pkg/apply/gen.go @@ -26,6 +26,7 @@ import ( "github.com/labring/sealos/pkg/runtime/factory" "github.com/labring/sealos/pkg/types/v1beta1" "github.com/labring/sealos/pkg/utils/iputils" + "github.com/labring/sealos/pkg/utils/logger" ) func NewClusterFromGenArgs(cmd *cobra.Command, args *RunArgs, imageNames []string) ([]byte, error) { @@ -43,6 +44,11 @@ func NewClusterFromGenArgs(cmd *cobra.Command, args *RunArgs, imageNames []strin if err := c.runArgs(cmd, args, imageNames); err != nil { return nil, err } + if flagChanged(cmd, "env") { + logger.Info("setting global envs for cluster, will be used in all run commands later") + v, _ := cmd.Flags().GetStringSlice("env") + cluster.Spec.Env = append(cluster.Spec.Env, v...) + } img, err := genImageInfo(imageNames[0]) if err != nil { diff --git a/pkg/clusterfile/clusterfile.go b/pkg/clusterfile/clusterfile.go index 95063f86912..100adeb837d 100644 --- a/pkg/clusterfile/clusterfile.go +++ b/pkg/clusterfile/clusterfile.go @@ -31,7 +31,6 @@ type ClusterFile struct { customValues []string customSets []string customEnvs []string - setDefaults bool cluster *v2.Cluster configs []v2.Config @@ -61,12 +60,6 @@ func (c *ClusterFile) GetRuntimeConfig() runtime.Config { type OptionFunc func(*ClusterFile) -func WithSetDefaults(v bool) OptionFunc { - return func(c *ClusterFile) { - c.setDefaults = v - } -} - func WithCustomConfigFiles(files []string) OptionFunc { return func(c *ClusterFile) { c.customConfigFiles = files diff --git a/pkg/clusterfile/pre_process.go b/pkg/clusterfile/pre_process.go index e1c7a5351a0..cf561d8ca0c 100644 --- a/pkg/clusterfile/pre_process.go +++ b/pkg/clusterfile/pre_process.go @@ -17,8 +17,6 @@ package clusterfile import ( "bytes" "errors" - "os" - "strings" "helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/getter" @@ -45,12 +43,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 { - _ = os.Setenv(kv[0], kv[1]) - } - } clusterFileData, err := c.loadClusterFile() if err != nil { return err @@ -161,7 +153,7 @@ func (c *ClusterFile) DecodeRuntimeConfig(data []byte) error { if cfg != nil { c.runtimeConfig = cfg } else { - kubeadmConfig, err := types.LoadKubeadmConfigs(string(data), c.setDefaults, decode.CRDFromString) + kubeadmConfig, err := types.LoadKubeadmConfigs(string(data), false, decode.CRDFromString) if err != nil { return err }