crossplane-contrib / function-kcl

Crossplane Composition Functions using KCL Programming Language
Apache License 2.0
34 stars 13 forks source link

Missing desired resources when metadata.name is missing or same for multiple resources #119

Open sschne opened 1 month ago

sschne commented 1 month ago

What happened?

When having multiple desired resources with the same metadata.name or metadata.name is omitted, only the last resource will be returned from the function

How can we reproduce it?

Take e.g. examples/resources/network and remove metadata.name from both resources to be generated.

What environment did it happen in?

Function version: v0.9.0

Peefy commented 1 month ago

Thanks for the feedback. At present, different resource names need to be set according to the following method. image

Perhaps we can add necessary name checks to crossplane function-kcl, PRs welcome!

sschne commented 1 month ago

Ok i totally overlooked that one, sorry for that. A check would be good, i will try to come up with a PR. What i also noticed that the annotation only works for target "Default", but not for target "Resources", which should also be supported, right?

Peefy commented 1 month ago

Yes, all targets should be supported, thank you very much for your contribution! ❤️

patpicos commented 1 month ago

I ran into a similar issue yesterday. I was generating 2 resources, with different api/kind, but with same metadata.name, the last one won.

# Resource One
              apiVersion = "projects.gitlab.crossplane.io/v1alpha1"
              kind = "Group"

              metadata.name = "{}-{}".format(isv,cnf)

# Resource Two
              apiVersion = "projects.gitlab.crossplane.io/v1alpha1"
              kind = "Project"

              metadata.name = "{}-{}".format(isv,cnf)

# Result: only the resource #2 would be generated.

Behavior wise, it would be good to have the granularity at the api/kind/name or at the very least warn the developer that a resource has been overwritten when rendering/testing.