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

Values written in context in first step is not available in the next #200

Closed
spastorclovr opened this issue Nov 22, 2024 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@spastorclovr
Copy link

What happened?

Step 1 of my function is writting to the pipeline context like so

  _ctx = option("params").ctx
  _ctx.namespace = "mynamespace"

I can display the value of option("params").ctx inside the step1 but not in a step further down with the following code

 _ctx = option("params").ctx
 items = [{ctx = _ctx}]

the context is then empty.

What environment did it happen in?

Function version: 0.10.10

@spastorclovr spastorclovr added the bug Something isn't working label Nov 22, 2024
@Peefy
Copy link
Collaborator

Peefy commented Nov 25, 2024

Hello, could you please the full code of the step1 and step2?

@spastorclovr
Copy link
Author

Sorry @Peefy for not including this before.
Here is the steps as defined in my composition

apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: generic-app-definition
spec:
  compositeTypeRef:
    apiVersion: apps.xxxx.tech/v1alpha1
    kind: XRApp
  mode: Pipeline
  pipeline:
  - step: step1
    functionRef:
      name: kcl-function
    input:
      apiVersion: krm.kcl.dev/v1alpha1
      kind: KCLInput
      spec:
        dependencies: |
          k8s="1.31"
          crossplane-provider-kubernetes="0.9.2"
        source: |
          _ctx = option("params").ctx
          _ctx.namespace = "mynamespace"
          object = {
             apiVersion: "nopexample.org/v1"
             metadata.name = "object from step1"
             metadata.namespace = _ctx.namespace
             spec = {
             }
          }
          items = [object]
          
   - step: step2
    functionRef:
      name: kcl-function
    input:
      apiVersion: krm.kcl.dev/v1alpha1
      kind: KCLInput
      spec:
        dependencies: |
          k8s="1.31"
          crossplane-provider-kubernetes="0.9.2"
        source: |
          _ctx = option("params").ctx
          object = {
             apiVersion: "nopexample.org/v1"
             metadata.name = "object from step2"
             metadata.namespace = _ctx.namespace
             spec = {
             }
          }

          items = [object]

The output from crossplane render

---
apiVersion: apps.chainstar.tech/v1alpha1
kind: App
metadata:
  name: myapp
status:
  conditions:
  - lastTransitionTime: "2024-01-01T00:00:00Z"
    message: 'Unready resources: object from step1, object from step2'
    reason: Creating
    status: "False"
    type: Ready
---
apiVersion: nopexample.org/v1
metadata:
  annotations:
    crossplane.io/composition-resource-name: object from step1
  generateName: myapp-
  labels:
    crossplane.io/composite: myapp
  name: object from step1
  namespace: mynamespace
  ownerReferences:
  - apiVersion: apps.chainstar.tech/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: App
    name: myapp
    uid: ""
spec: {}
---
apiVersion: nopexample.org/v1
metadata:
  annotations:
    crossplane.io/composition-resource-name: object from step2
  generateName: myapp-
  labels:
    crossplane.io/composite: myapp
  name: object from step2
  ownerReferences:
  - apiVersion: apps.chainstar.tech/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: App
    name: myapp
    uid: ""
spec: {}

☝️ I would expect a the "mynamespace" value in the metadata.namespace property from "Object from step2"

@Peefy
Copy link
Collaborator

Peefy commented Nov 25, 2024

ctx is readonly, you can return it through items = [object, _ctx]

@spastorclovr
Copy link
Author

Sorry @Peefy I don't get it. I am trying to use the content of the ctx from one Step to another one.
Do I need to return it into items to be able to use it in another step? (I actually tried that but it does not work) .
I am feeling I am not seeing the elephant in the room here. Apologies if that's the case ..

@Peefy
Copy link
Collaborator

Peefy commented Nov 27, 2024

cc @zong-zhe

@Wompipomp
Copy link
Contributor

Hi @spastorclovr, I think writing to context is still not supported in KCL, see #134
You can read it in KCL but you can't return anything back for now.

@spastorclovr
Copy link
Author

Thx! Would be very useful to have that specified in the documentation (that we can read but not write) for the time being.

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