refactor(two_pass_renderer): remove unused imports and functions
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
		
							parent
							
								
									a783ae1242
								
							
						
					
					
						commit
						f400bed3a5
					
				|  | @ -5,8 +5,6 @@ import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/google/go-cmp/cmp" |  | ||||||
| 
 |  | ||||||
| 	"github.com/helmfile/helmfile/pkg/environment" | 	"github.com/helmfile/helmfile/pkg/environment" | ||||||
| 	"github.com/helmfile/helmfile/pkg/state" | 	"github.com/helmfile/helmfile/pkg/state" | ||||||
| 	"github.com/helmfile/helmfile/pkg/tmpl" | 	"github.com/helmfile/helmfile/pkg/tmpl" | ||||||
|  | @ -21,52 +19,6 @@ func prependLineNumbers(text string) string { | ||||||
| 	return buf.String() | 	return buf.String() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (r *desiredStateLoader) renderPrestate(firstPassEnv, overrode *environment.Environment, baseDir, filename string, content []byte) (*environment.Environment, *state.HelmState) { |  | ||||||
| 	initEnv, err := firstPassEnv.Merge(overrode) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return firstPassEnv, nil |  | ||||||
| 	} |  | ||||||
| 	tmplData := state.NewEnvironmentTemplateData(*initEnv, r.namespace, map[string]any{}) |  | ||||||
| 	firstPassRenderer := tmpl.NewFirstPassRenderer(baseDir, tmplData) |  | ||||||
| 
 |  | ||||||
| 	// parse as much as we can, tolerate errors, this is a preparse
 |  | ||||||
| 	yamlBuf, err := firstPassRenderer.RenderTemplateContentToBuffer(content) |  | ||||||
| 	if err != nil { |  | ||||||
| 		r.logger.Debugf("first-pass rendering input of \"%s\":\n%s", filename, prependLineNumbers(string(content))) |  | ||||||
| 		r.logger.Debugf("template syntax error: %v", err) |  | ||||||
| 		if yamlBuf == nil { // we have a template syntax error, let the second parse report
 |  | ||||||
| 			return firstPassEnv, nil |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	yamlData := yamlBuf.String() |  | ||||||
| 	r.logger.Debugf("first-pass rendering output of \"%s\":\n%s", filename, prependLineNumbers(yamlData)) |  | ||||||
| 
 |  | ||||||
| 	// Work-around for https://github.com/golang/go/issues/24963
 |  | ||||||
| 	sanitized := strings.ReplaceAll(yamlData, "<no value>", "") |  | ||||||
| 
 |  | ||||||
| 	if len(yamlData) != len(sanitized) { |  | ||||||
| 		msg := "replaced <no value>s to workaround https://github.com/golang/go/issues/24963 to address https://github.com/roboll/helmfile/issues/553:\n%s" |  | ||||||
| 		r.logger.Debugf(msg, cmp.Diff(yamlData, sanitized)) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	c := r.underlying() |  | ||||||
| 	c.Strict = false |  | ||||||
| 	// create preliminary state, as we may have an environment. Tolerate errors.
 |  | ||||||
| 	prestate, err := c.ParseAndLoad([]byte(sanitized), baseDir, filename, r.env, true, false, firstPassEnv, overrode) |  | ||||||
| 	if err != nil { |  | ||||||
| 		if _, ok := err.(*state.StateLoadError); ok { |  | ||||||
| 			r.logger.Debugf("could not deduce `environment:` block, configuring only .Environment.Name. error: %v", err) |  | ||||||
| 		} |  | ||||||
| 		r.logger.Debugf("error in first-pass rendering: result of \"%s\":\n%s", filename, prependLineNumbers(yamlBuf.String())) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if prestate != nil { |  | ||||||
| 		firstPassEnv = &prestate.Env |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return firstPassEnv, prestate |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| type RenderOpts struct { | type RenderOpts struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue