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

Unify function is generating incorrect output when merging values from trait with default parameters in Kubevela #3623

Open
shivin opened this issue Dec 12, 2024 · 2 comments
Labels
NeedsInfo More information or clarification needed from the user

Comments

@shivin
Copy link

shivin commented Dec 12, 2024

What version of CUE are you using (cue version)?

$ cue version
0.9.2

Does this issue reproduce with the latest stable release?

Didn't try

Testing environment ?

  1. Kubernetes cluster
  2. Vela cli installed
  3. Kubevela installed and running on the Kubernetes cluster

What did you do?

  1. Copy the below contents into comp.cue.
mincomp: {
	alias: ""
	annotations: {}
	attributes: workload: definition: {
		apiVersion: "apps/v1"
		kind:       "Deployment"
	}
	description: ""
	labels: {}
	type: "component"
}

template: {
	output: {
            kind:       "Deployment"
	    volumes: [{
		name:  "myEmpty"
	}]
    }
	outputs: {}
}

  1. Copy the below contents into trait.cue.
"min-trait": {
	type: "trait"
}

template: {
	patch: 
		// +patchKey=name
		volumes: [{
			name: parameter.volumeName
		}]

	parameter: {
		// +usage=name of host mount volume (default datadog)
		volumeName: *"my-default-vol" | string
	}
}

  1. Copy the below contents into app.yaml.
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: website
spec:
  components:
    - name: hello
      type: mincomp
      traits:
        - type: min-trait
  1. Apply the component: vela def apply comp.cue
  2. Apply the trait: vela def apply trait.cue
  3. Dry run the application: vela dry-run -f app.yaml

What did you expect to see?

After running the dry-run command we expect to see the below output:

---
# Application(website) -- Component(hello) 
---

kind: Deployment
metadata:
  annotations: {}
  labels:
    app.oam.dev/appRevision: ""
    app.oam.dev/component: hello
    app.oam.dev/name: website
    app.oam.dev/namespace: default
    app.oam.dev/resourceType: WORKLOAD
    workload.oam.dev/type: mincomp
  name: hello
  namespace: default
volumes:
- name: myEmpty
- name: my-default-vol

---

What did you see instead?

After running the dry-run command we are seeing below output instead:

---
# Application(website) -- Component(hello) 
---

kind: Deployment
metadata:
  annotations: {}
  labels:
    app.oam.dev/appRevision: ""
    app.oam.dev/component: hello
    app.oam.dev/name: website
    app.oam.dev/namespace: default
    app.oam.dev/resourceType: WORKLOAD
    workload.oam.dev/type: mincomp
  name: hello
  namespace: default
volumes:
- name: myEmpty

---

Issue Description ?

Basically volume defined in trait is missing after the merge.
After debugging the kubevela codebase we observed that the kubevela is calling cue's Unify function to do the merging of volumes and it is not generating the expected output causing the above issue.

You can read more about the issue here

@shivin shivin added NeedsInvestigation Triage Requires triage/attention labels Dec 12, 2024
@mvdan
Copy link
Member

mvdan commented Dec 12, 2024

@shivin are you able to share a reproducer that relies solely on the cue tool or a small Go program using CUE's Go APIs? It's significantly harder to understand what's going on if the reproduction steps involve calling a third party tool such as vela, as that involves thousands of lines of code that we are unfamiliar with.

@myitcv myitcv added NeedsInfo More information or clarification needed from the user and removed NeedsInvestigation Triage Requires triage/attention labels Dec 13, 2024
@shivin
Copy link
Author

shivin commented Dec 13, 2024

main.zip

Hi @mvdan

Please find attached the go program which reproduces the issues using cue Go APIs.

On running the program you will see the below output:
kind: "Deployment"
// +patchKey=name
volumes: [{
name: "myEmpty"
}]

To see the expected output you can follow these workaround steps: If you put a comment on line 15 and uncomment line 16 in main.go and then run the program you will see the following output:
kind: "Deployment"
// +patchKey=name
volumes: [{
name: "myEmpty"
}, {
name: "my-default-vol"
}, ...]

Please note that I have used latest cue v0.11.0 for running this program. Please let me know if you need anything else. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInfo More information or clarification needed from the user
Projects
None yet
Development

No branches or pull requests

3 participants