New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(pkg/engine): introduce RenderWithClientProvider #12617
Conversation
ed156e1
to
ed3ea03
Compare
pkg/engine/lookup_func.go
Outdated
// This is suboptimal but the best kind->resource translation we can do without a discovery client. | ||
gvr, _ := meta.UnsafeGuessKindToResource(schema.FromAPIVersionAndKind(apiVersion, kind)) | ||
namespaced := true // we infer this from the namespace argument to the lookup function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we detail what is happening here please. Any limitations of this functionality? And how come we can't use the resources gvk when invoked from the lookup
function.
(the three levels of function closures are bending my brain a little; I think I might be missing something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this more, if a non-Helmtest user started to use this RenderWithDynamicClient
interface, they might (I think likely) be surprised by the meta.UnsafeGuessKindToResource
usage here. Given my (admittedly superficial) understanding, that this function is trying to "guess" the resource name from the Version, Kind info (meta.UnsafeGuessKindToResource source).
It seems to me, that it would be better to hoist the clientProviderFunc
functionality to external Render
interface? Rather than passing in a dynamic client, which gets only some of the way. Then needing to build in a workaround to use it.
Something like:
func RenderWithClientLookupFunc(chrt *chart.Chart, values chartutil.Values, clientLookupFunc ClientLookupFunc) (map[string]string, error) {
return Engine{
clientLookupFunc: ClientLookupFunc,
}.Render(chrt, values)
}
...
if e.clientLookupFunc != nil {
funcMap["lookup"] = return newLookupFunction(clientLookupFunc)
}
edit: Is there perhaps a better name than RenderWithClientLookupFunc
? I choose the obvious here for the example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gjenkins8 thank you for the prompt review! You formulated clearly the concerns I had myself floating somewhere on the edge of my perception 😅
I updated the PR to follow your advice. This also has the advantages of:
- not introducing any new function closures, at the expense of adding a new
struct
-based type, which I think is an acceptable overhead in this place, - eradicating the somewhat dubious
UnsafeGuessKindToResource
call to the helmtest codebase, where it's appropriate.
Signed-off-by: Marcin Owsiany <porridge@redhat.com>
ed3ea03
to
bfec4ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTMe, will ask another maintainer to review. Thanks for updating the PR
return Engine{ | ||
config: config, | ||
clientProvider: &clientProvider, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! IMHO it is great to be able to re-write the existing implementation in terms of this new, more generic, interface
@porridge There are no tests with this. Are the existing tests sufficient? How can I manually validate this? |
Signed-off-by: Marcin Owsiany <porridge@redhat.com>
@gjenkins8 @joejulian tests added. I think they now cover everything that is testable without having a real API server connection. PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
What this PR does / why we need it:
In order to fully test charts that use the
lookup
function in environments that do not provide a kube API server (e.g. with helmtest), we need to inject a (fake) kubernetes client to the engine.This change adds a
RenderWithClientProvider
function parallel to the already existing (somewhat unfortunately named)RenderWithClient
, to make this possible.Special notes for your reviewer:
Existing functionality is untouched.
If applicable:
lookup
template function still works, by running a locally builthelm
binary against a chart which uses this functionality, on akind
clusterStatement coverage with tests:
engine.go
files.go
funcs.go
lookup_func.go