@@ -189,13 +189,34 @@ func IsChartNotFound(err error) bool {
189189 return ok
190190}
191191
192- func getImageReferences (chartURI string , vals map [string ]interface {}) ([]string , error ) {
192+ // getImageReferences renders the templates for chartURI and extracts
193+ // imageReferences from the template output, using vals as necessaary.
194+ //
195+ // Note that template rendering doesn't technically need a remote cluster, but
196+ // the chart's constraints are still validated against mocked cluster
197+ // information. For this reaosn, serverKubeVersionString must produce a valid
198+ // semantic version corresponding to a kubeVersion within the chart's
199+ // constraints as defined in Chart.yaml.
200+ func getImageReferences (chartURI string , vals map [string ]interface {}, serverKubeVersionString string ) ([]string , error ) {
201+ // We'll start with DefaultCapabilities, but we'll really only use the
202+ // kubeVersion of this when rendering manifests because Helm replaces the
203+ // action config's capabilities for client-only execution.
204+ caps := chartutil .DefaultCapabilities .Copy ()
205+
206+ kubeVersion , err := chartutil .ParseKubeVersion (serverKubeVersionString )
207+ if err != nil {
208+ return nil , fmt .Errorf ("%s: %w" , "unable to render manifests and extract images due to invalid kubeVersion in server capabilities" , err )
209+ }
210+
211+ caps .KubeVersion = * kubeVersion
212+
193213 actionConfig := & action.Configuration {
194214 Releases : nil ,
195215 KubeClient : & kubefake.PrintingKubeClient {Out : io .Discard },
196- Capabilities : chartutil . DefaultCapabilities ,
216+ Capabilities : caps ,
197217 Log : func (format string , v ... interface {}) {},
198218 }
219+
199220 mem := driver .NewMemory ()
200221 mem .SetNamespace ("TestNamespace" )
201222 actionConfig .Releases = storage .Init (mem )
0 commit comments