Unverified Commit ace764ea authored by cuisongliu's avatar cuisongliu Committed by GitHub
Browse files

feature(main): add TryParse for loadClusterfile (#2017) (#2020)

Signed-off-by: default avatarcuisongliu <cuisongliu@qq.com>
Signed-off-by: default avatarcuisongliu <cuisongliu@qq.com>
Signed-off-by: default avatarcuisongliu <cuisongliu@qq.com>
No related merge requests found
Showing with 24 additions and 10 deletions
+24 -10
......@@ -126,8 +126,11 @@ func (c *Applier) updateStatus(err error) {
func (c *Applier) reconcileCluster() error {
//sync newVersion pki and etc dir in `.sealos/default/pki` and `.sealos/default/etc`
processor.SyncNewVersionConfig(c.ClusterDesired)
if err := c.installApp(c.RunNewImages); err != nil {
return err
logger.Debug("run new images: %+v", c.RunNewImages)
if len(c.RunNewImages) != 0 {
if err := c.installApp(c.RunNewImages); err != nil {
return err
}
}
mj, md := iputils.GetDiffHosts(c.ClusterCurrent.GetMasterIPAndPortList(), c.ClusterDesired.GetMasterIPAndPortList())
nj, nd := iputils.GetDiffHosts(c.ClusterCurrent.GetNodeIPAndPortList(), c.ClusterDesired.GetNodeIPAndPortList())
......
......@@ -20,6 +20,8 @@ import (
"os"
"strings"
"github.com/labring/sealos/pkg/utils/logger"
"helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/getter"
......@@ -69,17 +71,24 @@ func (c *ClusterFile) loadClusterFile() ([]byte, error) {
if err != nil {
return nil, err
}
logger.Debug("loadClusterFile loadRenderValues: %+v", mergeValues)
data := map[string]interface{}{
"Values": mergeValues,
}
tpl, err := template.Parse(string(body))
if err != nil {
return nil, err
}
logger.Debug("loadClusterFile body: %+v", string(body))
out := bytes.NewBuffer(nil)
if err := tpl.Execute(out, data); err != nil {
return nil, err
tpl, isOk, err := template.TryParse(string(body))
if isOk {
if err != nil {
return nil, err
}
if err := tpl.Execute(out, data); err != nil {
return nil, err
}
} else {
out.Write(body)
}
for i := range c.customConfigFiles {
configData, err := fileutil.ReadAll(c.customConfigFiles[i])
if err != nil {
......
......@@ -27,8 +27,10 @@ func init() {
Funcs(funcMap())
}
func Parse(text string) (*template.Template, error) {
return defaultTpl.Parse(text)
func TryParse(text string) (*template.Template, bool, error) {
tmp, err := defaultTpl.Parse(text)
isFailed := err != nil && err.Error() == "html/template: cannot Parse after Execute"
return tmp, !isFailed, err
}
func ParseFiles(filenames ...string) (*template.Template, error) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment