pulumi / pulumi-kubernetes

A Pulumi resource provider for Kubernetes to manage API resources and workloads in running clusters
https://www.pulumi.com/docs/reference/clouds/kubernetes/
Apache License 2.0
409 stars 117 forks source link

Using pulumi.DependsOnInput with chart.Ready doesn't respect Get calls #2789

Open blaargh opened 9 months ago

blaargh commented 9 months ago

What happened?

The dependsOnInput(chart.Ready) does not have the expected effect on Get calls.

The example errors during the preview with error: Preview failed: resource 'namespace/ingress' does not exist.

I see in the documentation it works with creating new resources, is it not supposed to work with a lookup? Or am I doing something wrong?

Example

chart, err := helm.NewChart(ctx, "chartName", helm.ChartArgs{
      Chart:     pulumi.String("chart"),
      Namespace: pulumi.String("namespace"),
}, nil, pulumi.Provider(k8sProvider))

if err != nil {
  log.Panic(err)
}

ingress, err := v1.GetIngress(ctx, "ingress", pulumi.ID("namespace/ingress"), nil, pulumi.DependsOnInputs(chart.Ready), pulumi.Provider(k8sProvider))
if err != nil {
  log.Panic(err)
}

hostname := ingress.Status.ApplyT(func(status *v1.IngressStatus) (string, error) {
    if len(status.LoadBalancer.Ingress) > 0 {
        return *status.LoadBalancer.Ingress[0].Hostname, nil
   }
   return "", nil
}).(pulumi.StringOutput)

Output of pulumi about

CLI Version 3.102.0 Go Version go1.21.6 Go Compiler gc

Plugins NAME VERSION archive 0.0.3 aws 6.0.2 go unknown kubernetes 4.6.1

Host OS darwin Version 14.2.1 Arch arm64

This project is written in go: executable='/usr/local/go/bin/go' version='go version go1.21.5 darwin/arm64'

Current Stack: stack Found no resources associated with stack

Found no pending operations associated with stack

Backend Name https://pulumi-api.io URL User user Organizations user, org Token type personal

Dependencies: NAME VERSION github.com/pulumi/pulumi-aws/sdk/v6 6.0.2 github.com/pulumi/pulumi-kubernetes/sdk/v4 4.6.1 github.com/pulumi/pulumi/sdk/v3 3.96.2 gopkg.in/yaml.v2 2.4.0

Pulumi locates its logs in /var/folders/z6/f71rd_rj49b6vf2qf_kfth7c0000gn/T/ by default

Additional context

No response

Contributing

Vote on this issue by adding a šŸ‘ reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

blaargh commented 9 months ago

Additional Info:

Using helm.Release and dependsOn instead of dependsOnInputs doesn't work either. As this helm chart is for deployment of an ALB resource on AWS (via Ingress with annotations), I also tried fetching the ALB directly with lb.LookupLoadbalancer and dependsOn, but it also doesn't work.

In the meantime, I also updated all relevant libraries (pulumi, pulumi-aws, pulumi-kubernetes) to their latest version, which didn't help either.

mjeffryes commented 9 months ago

Thanks for filing this @blaargh. As indicated in the docs for kubernetes.helm.sh.v3.Chart | Pulumi Registry; using dependsOnInputs with chart.Ready is the recommended approach. Unfortunately, I think the issue here is that the the preview step is failing because it attempts to do the read even though the chart has not been deployed yet (because we're still in preview!).

As a workaround for now, you might try pulumi update --skip-preview to skip the preview step and see if it successfully deploys the chart and finds the ingress.

blaargh commented 9 months ago

Thanks for acknowledging the issue! For now, I moved the creation of this resource in its own project, and just assume its there and ready in other projects. This forces me to have an order of precedence when applying all projects, but that's no issue. I'd rather have the preview actually do stuff like lookups, instead of the Terraform alternative, where nothing happens during a plan, which leads to much worse workarounds.

Still, would be great if preview was able to respect all variations of dependsOn in the future.

EronWright commented 2 weeks ago

@blaargh has wise words on the tradeoff between accuracy and convenience in preview.