From 4f1740e3c02344e2467279a803e8e6bff46b6c64 Mon Sep 17 00:00:00 2001 From: Matheus Pimenta Date: Fri, 13 Oct 2023 13:44:26 +0100 Subject: [PATCH] Print debug-level log for DNS lookups when disabled Signed-off-by: Matheus Pimenta --- pkg/action/action.go | 20 +++++++------------- pkg/engine/engine.go | 5 +++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/action/action.go b/pkg/action/action.go index 5693f4838..b4eaf361e 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -118,28 +118,22 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values chartutil.Valu } } - var files map[string]string - var err2 error - // A `helm template` should not talk to the remote cluster. However, commands with the flag //`--dry-run` with the value of `false`, `none`, or `server` should try to interact with the cluster. // It may break in interesting and exotic ways because other data (e.g. discovery) is mocked. + var e engine.Engine if interactWithRemote && cfg.RESTClientGetter != nil { restConfig, err := cfg.RESTClientGetter.ToRESTConfig() if err != nil { return hs, b, "", err } - e := engine.New(restConfig) - e.EnableDNS = enableDNS - files, err2 = e.Render(ch, values) - } else { - var e engine.Engine - e.EnableDNS = enableDNS - files, err2 = e.Render(ch, values) + e = engine.New(restConfig) } - - if err2 != nil { - return hs, b, "", err2 + e.EnableDNS = enableDNS + e.Log = cfg.Log + files, err := e.Render(ch, values) + if err != nil { + return hs, b, "", err } // NOTES.txt gets rendered like all the other files, but because it's not a hook nor a resource, diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 150be16b7..37e29c859 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -44,6 +44,8 @@ type Engine struct { config *rest.Config // EnableDNS tells the engine to allow DNS lookups when rendering templates EnableDNS bool + // Log is used for printing logs. + Log func(string, ...interface{}) } // New creates a new instance of Engine using the passed in rest config. @@ -202,6 +204,9 @@ func (e Engine) initFunMap(t *template.Template, referenceTpls map[string]render // an empty string. if !e.EnableDNS { funcMap["getHostByName"] = func(name string) string { + if e.Log != nil { + e.Log("DNS lookup is disabled by default. If you understand the security implications, check the documentation for how to enable DNS lookups in templates") + } return "" } }