hamlet-io / engine

Framework for managing cloud infrastructure via templates. It is part of the broader Hamlet devops framework.
GNU General Public License v3.0
5 stars 5 forks source link

Dynamic loading of fragments #1443

Open roleyfoley opened 3 years ago

roleyfoley commented 3 years ago

Current Behaviour

Fragments provide access to the hamlet engine for users and can be added as part of a CMDB. They are currently implemented as case statement which is assembled as part of the CMDB composite loading process. For each component this case statement is executed and if the fragment id matches the statement the fragment details are executed during the component processing.

While fragments do provide a powerful way to modify your solution to meet the needs of a specific solution their processing is inefficient ( the case statement gets longer and longer ), brittle ( a break in one fragment breaks the whole process ) and they can't be shared or loaded through our dynamic loading processes ( the freemarker file with the case statement is built outside of the engine ) As a result of this they can't be included in Scenarios #1426 which supports including all other input data except for this

Expected Behaviour

Possible Solution

Context

This would align fragments with the rest of our function loading processes and also provide documentation and context to fragments

RossMurr4y commented 3 years ago

Does the name Fragment still match this then? I like your suggested solution, but Fragment sounds like it was named after the "which part of the case statement do you want to run" whereas this new function - that accepts a context and outputs a context - is more of a "context transformation".

Of course they do the same thing but if I was just learning Hamlet, I can't infer much from "Fragment" but something with "Context" in the name that indicates pre-processing context manipulation would allow me to apply pre-existing knowledge from other languages on to this feature.

ml019 commented 3 years ago

A fragment can basically do anything, as @roleyfoley has ably demonstrated.

The name came from the idea of a code fragment - a part of the configuration process but not all of it.

Maybe "snippet" might make more immediate connection for the reader?

roleyfoley commented 3 years ago

We had thought of using snippets for deployment profiles/policies and I think that fits better in that name. I.e. snippet is tiny module ( module covers a whole blueprint where a snippet just covers a components configuration )

Maybe Fragments might be better as Extensions, they do extend the functionality of a component unlike a snippet or a module which implement existing configuration, just in a standardised pattern

ml019 commented 3 years ago

+1 for extensions. Yet another rename but easier to handle in the freemarker world.

RossMurr4y commented 3 years ago

Sounds like we're on to a winner then :)

ml019 commented 2 years ago

@roleyfoley I think this can be closed?