How to remove null values? #2433
Unanswered
mario-steinhoff-gcx
asked this question in
Q&A
Replies: 1 comment
-
|
Building upon this comment, I came up with this: #isValueStruct: {
value: _
result: ((value & {}) | *_|_) != _|_
}
#isValueNull: {
value: _
result: ((value & null) | *_|_) != _|_
}
#OmitNull: {
orig: {}
result: {...}
result: {
for k, v in orig {
let valueIsStruct = (#isValueStruct & {value: v}).result
let valueIsNull = (#isValueNull & {value: v}).result
if valueIsStruct {
"\(k)": (#OmitNull & {orig: v}).result
}
if !valueIsStruct && !valueIsNull {
"\(k)": v
}
}
}
}Example: https://cuelang.org/play/?id=UHbZl6jGCRQ#cue@export@cue Unfortunately when applied to my example argocd helm chart, it adds around 2 seconds to the execution time, e.g. without omitting nulls: with omitting nulls: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I use cue for kubernetes configuration and want to render helm charts via
helm templateand validate the resulting manifests against the cue-based kubernetes schema.Rendering the template works and I can import manifests from helm stdout via
yaml.UnMarshalStream().Some helm charts (argocd in this example) produce YAML with empty keys because they are using this pattern, where the field itself is not additionally guarded by an if block:
Which renders to:
After I run it through yaml umarshalling and marshalling like this:
I get this result:
But the generated cue schema for annotations looks like this:
And of course null is not a struct with string fields so it doesnt validate in cue but its still accepted by the kubernetes API server.
In jsonnet there is
std.prune()to remove null fields, is there a way to solve this with cue?Beta Was this translation helpful? Give feedback.
All reactions