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
404 stars 115 forks source link

ConfigGroup (V2) resources aren't useable in Pulumi Go SDK #2910

Open EronWright opened 5 months ago

EronWright commented 5 months ago

What happened?

I tried to write a Go SDK program that post-processes the resources produced by yamlv2.ConfigGroup. I found that the array elements aren't coercible to pulumi.Resource nor to *corev1.ConfigMap (the concrete resource type).

Example

package main

import (
    corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
    yamlv2 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/yaml/v2"
    "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        example, err := yamlv2.NewConfigGroup(ctx, "example", &yamlv2.ConfigGroupArgs{
            Objs: pulumi.Array{
                pulumi.Map{
                    "apiVersion": pulumi.String("v1"),
                    "kind":       pulumi.String("ConfigMap"),
                    "metadata": pulumi.Map{
                        "name": pulumi.String("my-map"),
                    },
                },
            },
        })
        if err != nil {
            return err
        }

        _ = example.Resources.Index(pulumi.Int(0)).ApplyT(func(r any) error {
            res := r.(pulumi.Resource) // <-- BUG: r is not a "pulumi.Resource"
            ctx.Log.Info("Hello World", &pulumi.LogArgs{Resource: res})

            configMap := r.(*corev1.ConfigMap) // <-- BUG: r is a "corev1.ConfigMap" not a "*corev1.ConfigMap"
            ctx.Export("configMapUid", configMap.Metadata.Uid())
            return nil
        })

        return nil
    })
}

Output of pulumi about

CLI          
Version      3.108.1
Go Version   go1.22.0
Go Compiler  gc

Plugins
NAME        VERSION
go          unknown
kubernetes  4.10.0

Host     
OS       darwin
Version  13.5.1
Arch     arm64

Additional context

Root cause issue: https://github.com/pulumi/pulumi/issues/15788

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).

EronWright commented 5 months ago

A fix is under development in pu/pu for how resource reference outputs are handled: https://github.com/pulumi/pulumi/pull/15795/commits/8cd0a87cd7294ed10bc86112b29ea2a00451a1ed

Also a pulumi.json/#Resource schema type will be introduced, such that the resources output property have a pulumi.ResourceArrayOutput type.

Once these are done, then we'll update the provider to use the Resource type: https://github.com/pulumi/pulumi-kubernetes/pull/2918