Skip to content
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

deferrable epp function simplifying deferred templates #1253

Merged
merged 5 commits into from
Jul 21, 2022

Conversation

binford2k
Copy link
Contributor

No description provided.

This function will detect when it's passed a deferred function and will
effectively defer itself rather than rendering a template directly. It
does this by either returning a deferred inline_epp function with the
template source and variables compiled into the catalot, or by rendering
directly with epp and just returning that output.
@binford2k binford2k requested a review from a team as a code owner July 1, 2022 20:52
@reidmv
Copy link
Contributor

reidmv commented Jul 1, 2022

I think this is the right UX for the purpose; basically an arg-for-arg wrapper for epp(). 👍


Wild future improvement idea:

If we like this idea, there's a possibility we could modify the internals a bit to sub out the deferred arguments for %<deferred_1>s, %<deferred_2>s, and so forth, run the epp() with those subs, then return a Deferred['sprintf', [$deferred_args_hash]] – do this instead of returning a Deferred['inline_epp' ...]. If we did that, we might eliminate the template and variable scope constraints this implementation warns against.

@binford2k binford2k changed the title [WIP] deferrable epp function simplifying deferred templates deferrable epp function simplifying deferred templates Jul 14, 2022
chelnak
chelnak previously approved these changes Jul 15, 2022
@chelnak chelnak self-requested a review July 15, 2022 08:48
@chelnak
Copy link
Contributor

chelnak commented Jul 15, 2022

@binford2k Looks like you have a failing lint check

functions/deferrable_epp.pp - ERROR: there should be a single newline at the end of a manifest on line 19 (check: manifest_whitespace_double_newline_end_of_file)

Also I wonder if we should have a spec test for this?

end
it {
foo = Puppet::Pops::Types::TypeFactory.deferred.create('join', [1,2,3])
is_expected.to run.with_params('mymod/template.epp', {'foo' => foo }) #.and_return(a_kind_of Puppet::Pops::Evaluator::DeferredValue)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshcooper I couldn't quite get the return type here. Suggestions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. I figured out the return type and submitted an rspec-puppet PR to actually allow this matcher to work.

puppetlabs/rspec-puppet#24

@chelnak chelnak merged commit 4dd6a6d into puppetlabs:main Jul 21, 2022
@pmcmaw pmcmaw added the feature label Jul 21, 2022
waipeng added a commit to waipeng/puppetlabs-kubernetes that referenced this pull request May 28, 2024
PR puppetlabs#637 uses stdlib::deferrable_epp that is only available in v8.4.0[1]

[1] puppetlabs/puppetlabs-stdlib#1253

Change-Id: I455cec0ec1c6a2ec63b2ab0c19b2b7a2119f2f26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants