Why does adding a few newlines change the meaning of this where
's closure?
#12843
-
Hello all. I could use a second set of eyes here. Thanks for taking a look. This works like I want it to: {items : [{metadata: {name: foo, creationTimestamp: "2024-05-12T11:23:01Z"}, status: {conditions: [{reason: "PodCompleted"}]}}]}
| get items
| where { |it| ((date now) - ($it.metadata.creationTimestamp | into datetime) > 5min) and ($it.status.conditions | any { |cond| "reason" in $cond and $cond.reason == "PodCompleted"}) }
| get metadata.name
This fails: {items : [{metadata: {name: foo, creationTimestamp: "2024-05-12T11:23:01Z"}, status: {conditions: [{reason: "PodCompleted"}]}}]}
| get items
| where { |it|
((date now) - ($it.metadata.creationTimestamp | into datetime) > 5min)
and ($it.status.conditions | any { |cond| "reason" in $cond and $cond.reason == "PodCompleted"})
}
I just added some newlines, why is it suddenly talking about an external command? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
a few things i have noticed: your you can simplify the | any { |cond| "reason" in $cond and $cond.reason == "PodCompleted" }
| any { |cond| $cond.reason? == "PodCompleted" } you try to get
when applying all these things it works: {items : [{metadata: {creationTimestamp: "2024-05-12T11:23:01Z"}, status: {conditions: [{reason: "PodCompleted"}]}}]}
| get items
| where (
((date now) - ($it.metadata.creationTimestamp | into datetime) > 6hr)
and
($it.status.conditions | any {|cond| $cond.reason? == "PodCompleted" })
)
| each {|it| echo $it.metadata.name? | default testName } as a tip for future debugging: remove code until it works and then readd code or add dummies until it breaks again: just removing one condition and the |
Beta Was this translation helpful? Give feedback.
-
@Jan9103 helped me see what is going on here. I ended up writing an issue for it: #12845 |
Beta Was this translation helpful? Give feedback.
a few things i have noticed:
your
and
is probably missing braces on the right sideyou can simplify the
any
. the following ones are equivalent:you try to get
$it.metadata.name
, which does not exist (-> i have added a| default testName
for my testing).where
is a bit special in nushell and does not require a closure (brackets are enough).when applying all these things it works: