Filtering and mapping nested outputs #19199
Replies: 2 comments 4 replies
-
Yeh this is a tricky one because of the different layers. I think you want something like:
That is first iterate the resources list and apply on the name so that you can return an output<[bool, Service]>, then use |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late answer, I thought I had already posted my solution: chart.resources.apply(lambda resources: pulumi.Output.all(*(
pulumi.Output.all(
ips = svc.status.load_balancer.apply(lambda lb: [ ingress.ip for ingress in lb.ingress or [] ]),
pred = svc.metadata.apply(lambda m: m.name == "cilium-ingress"),
)
for svc in resources
if isinstance(svc, k8s.core.v1.Service)
))).apply(lambda out: reduce(lambda acc, x: acc + (x["ips"] if x["pred"] else []), out, [])), Thanks again, @Frassle, for the help <3 I plan to write a more-ergonomic API for that sort of thing (and I'm now wishing Python had monad comprehensions) which I'll happily share if/when that happens :3 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I'm fairly new to Pulumi, and trying it out to bring up and manage a Kubernetes cluster, as a demo to show at the local Python user group.
Something I'm currently having trouble with, is filtering an
Output[List[k8s.core.v1.Service]]
based onmetadata
and extractstatus
information. To be precise, given achart
, I need to compute (and export as a stack output) something likeHowever,
svc.metadata
andsvc.status
are bothOutput
s of their own, so this doesn't worksvc.status.load_balancer.ingress
cannot directly be iterated onsvc.metadata.name == "cilium-ingress"
is always false, as the left operand is anOutput
object.The closest I got so far is
which produces a list of lists (instead of a flat list) and isn't filtering based on metadata
Beta Was this translation helpful? Give feedback.
All reactions