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

Retry delay one kcl error? #184

Open
dennybaa opened this issue Nov 1, 2024 · 3 comments
Open

Retry delay one kcl error? #184

dennybaa opened this issue Nov 1, 2024 · 3 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@dennybaa
Copy link

dennybaa commented Nov 1, 2024

Hello @Peefy,

I've been learning how to use KCL function. And it's great thanks a lot)! But I've bumped into not very neat behavior, if KCL exits with an error function is immediately reevaluated and this pollutes info logs. I wonder if this case is specific to the KCL function only or it's crossplane composite functions architecture feature. Btw I haven't noticed this type of behaviour with patch-and-transform function.

Here's the example:

_groupPolicies = option("params").groupPolicies
_spec = option("params").oxr.spec
# Pick vault provider
_provider = "iaas-security-${_spec.env}-vault"
_outputs = option("params").ocds["datasource"]?.Resource?.status?.atProvider?.outputs
_items = []

if _outputs?.group_id:
    # Effectevly wait for a composed resource to appear
    _items = [{
        **_groupPolicies
        metadata.annotations: {"krm.kcl.dev/composition-resource-name" = option("params").name}
        spec.providerConfigRef.name = _provider
        spec.forProvider: {
            policies = _spec.policies
            groupId = _outputs?.group_id
        }
    }]

items = _items

To suppress immediate reevaluation and logs pollution I have to manually guard resource creation. Is this expected behavior?

@dennybaa dennybaa added the enhancement New feature or request label Nov 1, 2024
@Peefy
Copy link
Collaborator

Peefy commented Nov 1, 2024

Have you tried the function-go-templating? The logic of retry is not determined by KCL itself, and I seem to have not found how to set the retry time in the function.

@dennybaa
Copy link
Author

dennybaa commented Nov 4, 2024

No, I haven't tried( Let's try to ask @ytsarev . Yury would you mind please sharing your suggestion? What's the best way to handle the delay, should it be inside the KCL function implementation, or maybe the function should return 0 code? The later of course would be odd, however if functions successfully exist crossplane doesn't immediately re-evaluate them, kinda odd mitigation...

Thank you!

@ytsarev
Copy link
Contributor

ytsarev commented Nov 4, 2024

We end up using https://github.com/crossplane-contrib/function-sequencer together with the function-kcl for sequenced creation. Example: https://github.com/upbound/configuration-aws-eks/blob/main/apis/kcl/generate.k#L42-L72

@Peefy Peefy added the question Further information is requested label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants