fix(engine): add debug logging when lookup returns empty

When lookup cannot find the requested resource (apierrors.IsNotFound),
add slog.Debug() calls with structured fields (apiVersion, kind,
namespace, name) so that users running helm template --debug can see
why lookup returned an empty map instead of silently swallowing the
not-found result.

Fixes: https://github.com/helm/helm/issues/32101
Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
pull/32205/head
Ogulcan Aydogan 4 months ago
parent 96c152cb1a
commit d7778ff636
No known key found for this signature in database
GPG Key ID: 00C439F668BFC3F6

@ -73,6 +73,12 @@ func newLookupFunction(clientProvider ClientProvider) lookupFunc {
if apierrors.IsNotFound(err) { if apierrors.IsNotFound(err) {
// Just return an empty interface when the object was not found. // Just return an empty interface when the object was not found.
// That way, users can use `if not (lookup ...)` in their templates. // That way, users can use `if not (lookup ...)` in their templates.
slog.Debug("lookup: resource not found",
slog.String("apiVersion", apiversion),
slog.String("kind", kind),
slog.String("namespace", namespace),
slog.String("name", name),
)
return map[string]any{}, nil return map[string]any{}, nil
} }
return map[string]any{}, err return map[string]any{}, err
@ -85,6 +91,11 @@ func newLookupFunction(clientProvider ClientProvider) lookupFunc {
if apierrors.IsNotFound(err) { if apierrors.IsNotFound(err) {
// Just return an empty interface when the object was not found. // Just return an empty interface when the object was not found.
// That way, users can use `if not (lookup ...)` in their templates. // That way, users can use `if not (lookup ...)` in their templates.
slog.Debug("lookup: resource list not found",
slog.String("apiVersion", apiversion),
slog.String("kind", kind),
slog.String("namespace", namespace),
)
return map[string]any{}, nil return map[string]any{}, nil
} }
return map[string]any{}, err return map[string]any{}, err

Loading…
Cancel
Save