-
I've started experimenting with cue recently, and while working in a flat directory things seem to work as expected, but when I introduce any sort of hierarchy everything starts behaving weird, and I can't wrap my head around it.
main.cue
same.cue
tester/tester.cue
sub/sub.cue
My mental model was that everything inside a package is a giant set, every file will eventually merge. But in reality, it seems, that I'm getting a set of divergent outputs:
So, it brings a bunch of questions: Does cue only work with flat file structure? If every file is marked as being part of the package, why is behavior different? My guess is that files that are not a part of same hierarchy will never merge, and every subfolder produces its own merge with the root. I was planning to build a validator with data at the leafs, schema validators and cross leaf checks at the top, but it doesn't work. Then, what is a proper way to build it? How do I express constraints that work between multiple different leafs? And how do I get a single unified output? P.S. Merry Christmas! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I think I've found a similar issue: #1652 and slowly re-read https://cuelang.org/docs/concepts/packages/#file-organization about Instances. As per @myitcv request I would like to mark it as “this really does fit/work”. I'll describe my use-case: I'm trying to build a single source of truth for configs in Bazel driven monorepo. That means every cluster, app, Kubernetes resource should be there, in one big hermetic and consistent package. So that after I run I think I can express most of the constraints with CUE, but everything package wise seems to work against me. It's definitely not an option to have hundreds or thousands files in a single flat directory. Creating a single vertical chain of directories is a bit weird, but also potentially bug prone, it requires everybody on the team to have perfect understanding of how Instances work, otherwise they can accidentally introduce a new one and be left with “why doesn't it work?” situation (like me before). This leaves me with not that many options, either I use Go API to artificially flatten the hierarchy or create some Bazel rules to do the same. Both options seem to be more involved than I've expected. I might have missed some flag that makes everything work 🤷 It doesn't look like there are a lot of examples with similar cases in open source either. I'd also like to point out that Instances behavior is unintuitive and potentially very bug prone. As a newcomer to CUE it leaves me with code that looks ok, passes vet, but shouldn't. Only after tinkering with a lot of reduced cases you can discover what's actually going on. I fully expect, that if I to introduce multi instanced version to our repo, someone will eventually write a policy that validates only a subset of data, and we will have an outage. I hope that I described our use case well enough, and it would help smooth the experience for similar cases. Feel free to ask additional questions. I'm planning to check out Go API later this week, and hope that it's gonna work out. |
Beta Was this translation helpful? Give feedback.
-
Just an update: this line produces result I was look for: The same result can be archive using Go API https://cuetorials.com/go-api/loading/ |
Beta Was this translation helpful? Give feedback.
-
Looking for similar answers here but also — why can't cue eval/vet just look in subfolders for package files? |
Beta Was this translation helpful? Give feedback.
Just an update: this line produces result I was look for:
cue vet $(find . -not -path "./cue.mod/**/*" -name "*.cue") -c
The same result can be archive using Go API https://cuetorials.com/go-api/loading/