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

Ability to import different kcl files based on parameters #204

Open
irizzant opened this issue Dec 6, 2024 · 2 comments
Open

Ability to import different kcl files based on parameters #204

irizzant opened this issue Dec 6, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@irizzant
Copy link

irizzant commented Dec 6, 2024

What happened?

I'd like to specify a channel parameter that can be read in my Composition file, and decide what file to import basing on that parameter.
Something like:

apiVersion: krm.kcl.dev/v1alpha1
kind: KCLInput
metadata:
  annotations:
    "krm.kcl.dev/default_ready": "True"
  name: basic
spec:
  source: |
    import file

    if _option("params")?.oxr?.spec.parameters.channel:
       file.read(_option("params")?.oxr?.spec.parameters.channel + "/something.yaml"
    else:
       file.read("default/somethingElse.yaml")

but maybe it's not feasible.

How can we reproduce it?

What environment did it happen in?

Function version:

@irizzant irizzant added the bug Something isn't working label Dec 6, 2024
@Peefy
Copy link
Collaborator

Peefy commented Dec 7, 2024

cc @zong-zhe

@irizzant
Copy link
Author

irizzant commented Dec 31, 2024

I think I actually found one way to implement something similar by looking at the code here.

That code generates an array of Compositions, in the example above they could be one for each value of the channel parameter.

Then the actual Composition selection happens using these labels and Composition Revision by specifying a compositionRevisionSelector.matchLabels in the Claim.

Also, I if I define 2 KCL files, let's say:

  • first.k
  • second.k

and I put this content into both:
test = "test"
Visual Studio Code KCL extension shows an error:

The variable 'test' is declared here(ImmutableError)
second.k(1, 1): Can not change the value of 'test', because it was declared immutable
test: str

This tricked me into believing that I was doing it the wrong way. In reality this is not an error at all if you make sure that only one of these files is selected at runtime.

That being said, I'd still like to know if there is a better way to accomplish this other than the one I showed above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants