crossplane-contrib / function-environment-configs

A function building the environment from EnvironmentConfigs
Apache License 2.0
15 stars 4 forks source link

Array Envs -- Not Merged Envs #20

Closed reedjosh closed 7 months ago

reedjosh commented 8 months ago

What problem are you facing?

I would really like to select envs and then be able to create an object for each env I find.

Currently each env I find gets merged which necessitates a unique starting node for each env I want to create.

So for k8s cluster I'd do something like: envconfig for cluster1

cluster1:
    data:
       all the things

envconfig for cluster2


cluster2:
    data:
       all the things 

Purely to make each node unique.

How could this Function help solve your problem?

If this function could fill an array of all found envconfigs then I could range over them in a go template function or similar.

So maybe optionally we could enable an additional key indexable like index .context "apiextensions.crossplane.io/environments" plural which is just an unmerged array of environments selected.

Again, we could also make this totally optional and off by default.

That way memory and performance concerns are on the end user.

I personally would use this with a relatively small maxMatch.

Thank you! These functions are completely rad.

I only just got this one up and running locally tonight, and it's real fun to play with.

I could even attempt a PR if you'd like.

phisco commented 8 months ago

That would be the job of a more generic function-extra-resources or something. The primary goal of this function was to reimplement the in-tree implementation as much as possible, so I don't think it's in scope. Then environments instead of environment would be a recipe for a lot of typos 😂

reedjosh commented 8 months ago

That would be the job of a more generic function-extra-resources or something.

I see, that's fair enough. Anybody started that work yet that you know of? Any advice if I were to start working on it myself. I've done my fair share of k8s operator work before.

Any advice on how to handle the generic kinds?

To me being able to dynamically generate resources from others is kind of a killer feature that Crossplane seems to be missing ATM. That said I am still fairly new to all of the trickery one can get up to.

Then environments instead of environment would be a recipe for a lot of typos 😂

Sure, it was just off the top of my head. Could be uniqueEnvs or whatever really. But seems moot ATM anyway I suppose.

phisco commented 8 months ago

Not that I know of. I would be more than happy to help you out if you wanted to work on it!

This function would definitely be a good starting point, but the API would need to be changed to allow specifying also an apiversion and kind in addition to labels and names as this one does. And then it would need to just inject the retrieved resources under some key in the context, instead merging them. It would be hard to use such content from less powerful functions, but for example function-go-templating could easily access it.

Feel free to reach out on slack if you want to discuss it further! 🙏

reedjosh commented 8 months ago

Okay, forked function template for now and just now starting to play with it. https://github.com/reedjosh/function-generic-resources

Will try to grant you dev and or maintainer perms there shortly -- though if you want to start this in some other way or location that's cool too.

Will ping on Slack. Looking forward to it!

phisco commented 8 months ago

Awesome! If we agree on a good name I can setup a repo on crossplane-contrib for it and grant you permissions! function-generic-resources is maybe a bit too generic 😅 function-extra-resources might be a bit too tied to the underlying feature 🤔

phisco commented 7 months ago

This can now be achieved with https://github.com/crossplane-contrib/function-extra-resources, thanks @reedjosh for making it happen!