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

cmd/cue: trim output differs with defaulted extendable list and k8s constraints #1294

Open
robjtede opened this issue Oct 9, 2021 · 2 comments
Labels
NeedsFix trim This issue is related to trim.
Milestone

Comments

@robjtede
Copy link

robjtede commented Oct 9, 2021

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

$ cue version
cue version 0.4.0 darwin/amd64

What did you do?

I was searching for a way to merge lists that exist on the same key-path and came up with this ineffective attempt (still havent found one). Happened to run a trim on it.

// ./test.cue

import apps_v1 "k8s.io/api/apps/v1"

deployment: [string]: apps_v1.#Deployment // works if line removed
deployment: [string]: spec: template: spec: containers: [...{
	env: [...] | *[
		{name: "version", value: "value"},
		{name: "-", value:       "-"}, // works if line removed
		...,
	]
}]

deployment: ancile: spec: template: spec: containers: [{
	env: [
		{name: "version", value: "value"},
	]
}]
cue trim test.cue

What did you expect to see?

No error.

What did you see instead?

$ cue trim test.cue
  {
      deployment: {
          ancile: {
              metadata?: {}
              spec: {
                  replicas?: null | int32
                  selector?: null | {}
                  template: {
                      metadata?: {}
                      spec: {
                          volumes?: []
                          initContainers?: []
                          containers: [
                              {
                                  ... // 5 identical elements
                                  ports?: []
                                  envFrom?: []
                                  env: [
                                      {
-                                         name: "version"
+                                         name: string
                                          value: "value"
                                          valueFrom?: null | {}
                                      }
                                  ]
                                  resources?: {}
                                  volumeMounts?: []
                                  ... // 12 identical elements
                              }
                          ]
                          ephemeralContainers?: []
                          restartPolicy?: string
                          ... // 30 identical elements
                      }
                  }
                  strategy?: {}
                  minReadySeconds?: int32
                  ... // 3 identical elements
              }
              kind?: string
              status?: {}
              ... // 1 identical elements
          }
      }
  }
Aborting trim, output differs after trimming. This is a bug! Use -i to force trim.

Forcing the trim results in this. Note the missing env var name.

// ./test.cue

import apps_v1 "k8s.io/api/apps/v1"

deployment: [string]: apps_v1.#Deployment // works if line removed
deployment: [string]: spec: template: spec: containers: [...{
	env: [...] | *[
		{name: "version", value: "value"},
		{name: "-", value:       "-"}, // works if line removed
		...,
	]
}]

deployment: ancile: spec: template: spec: containers: [{
	env: [
		{value: "value"},
	]
}]

Trim works if one or the other of the marked lines are removed.

@robjtede robjtede added NeedsInvestigation Triage Requires triage/attention labels Oct 9, 2021
@mpvl
Copy link
Member

mpvl commented Oct 26, 2021

The issue here is that trim picks the default value, even though that option will be deleted during unification.

@mpvl mpvl added NeedsFix trim This issue is related to trim. and removed NeedsInvestigation Triage Requires triage/attention labels Oct 26, 2021
@mpvl mpvl added this to the v0.4.x milestone Oct 26, 2021
@myitcv myitcv changed the title trim output differs with defaulted extendable list and k8s constraints cmd/cue: trim output differs with defaulted extendable list and k8s constraints Nov 19, 2021
@myitcv
Copy link
Member

myitcv commented Apr 27, 2023

Dropping the now meaningless v0.4.x milestone. We have relabelled this from trim to roadmap/trim to indicate that a fix for this issue (and indeed all trim issues) requires a more substantial piece of work.

@myitcv myitcv modified the milestones: v0.4.x, trim-redesign Apr 27, 2023
@myitcv myitcv added the zGarden label Jun 13, 2023
@mvdan mvdan removed the zGarden label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix trim This issue is related to trim.
Projects
None yet
Development

No branches or pull requests

4 participants