diff --git a/provider/pkg/gen/go-templates/configFile.tmpl b/provider/pkg/gen/go-templates/configFile.tmpl index 01eaf27adb..89988a5854 100644 --- a/provider/pkg/gen/go-templates/configFile.tmpl +++ b/provider/pkg/gen/go-templates/configFile.tmpl @@ -87,6 +87,13 @@ func NewConfigFile(ctx *pulumi.Context, return configFile, nil } -func (cf *ConfigFile) GetResource(key string) pulumi.Output { +// GetResource returns a resource defined by a built-in Kubernetes group/version/kind, name and namespace. +// For example, GetResource("v1/Pod", "foo", "") would return a Pod called "foo" from the "default" namespace. +func (cf *ConfigFile) GetResource(gvk, name, namespace string) pulumi.Output { + id := name + if len(namespace) > 0 && namespace != "default" { + id = fmt.Sprintf("%s/%s", namespace, name) + } + key := fmt.Sprintf("%s::%s", gvk, id) return cf.Resources.MapIndex(pulumi.String(key)) } diff --git a/provider/pkg/gen/go-templates/configGroup.tmpl b/provider/pkg/gen/go-templates/configGroup.tmpl index 2e575ea4d4..e6407875dc 100644 --- a/provider/pkg/gen/go-templates/configGroup.tmpl +++ b/provider/pkg/gen/go-templates/configGroup.tmpl @@ -87,6 +87,13 @@ func NewConfigGroup(ctx *pulumi.Context, return configGroup, nil } -func (cf *ConfigGroup) GetResource(key string) pulumi.Output { +// GetResource returns a resource defined by a built-in Kubernetes group/version/kind, name and namespace. +// For example, GetResource("v1/Pod", "foo", "") would return a Pod called "foo" from the "default" namespace. +func (cf *ConfigGroup) GetResource(gvk, name, namespace string) pulumi.Output { + id := name + if len(namespace) > 0 && namespace != "default" { + id = fmt.Sprintf("%s/%s", namespace, name) + } + key := fmt.Sprintf("%s::%s", gvk, id) return cf.Resources.MapIndex(pulumi.String(key)) } diff --git a/provider/pkg/gen/go-templates/yaml.tmpl b/provider/pkg/gen/go-templates/yaml.tmpl index 8b22de943e..ec99fd0e04 100644 --- a/provider/pkg/gen/go-templates/yaml.tmpl +++ b/provider/pkg/gen/go-templates/yaml.tmpl @@ -100,8 +100,6 @@ func yamlDecode(ctx *pulumi.Context, text string, opts ...pulumi.ResourceOption) var ret struct { Result []map[string]interface{} `pulumi:"result"` } - // TODO(joe): not clear how to translate ResourceOptions to InvokeOptions (or even get individual - // settings, e.g. opts.Parent). if err := ctx.Invoke("kubernetes:yaml:decode", &args, &ret); err != nil { return nil, err } diff --git a/sdk/go/kubernetes/yaml/configFile.go b/sdk/go/kubernetes/yaml/configFile.go index 01eaf27adb..89988a5854 100644 --- a/sdk/go/kubernetes/yaml/configFile.go +++ b/sdk/go/kubernetes/yaml/configFile.go @@ -87,6 +87,13 @@ func NewConfigFile(ctx *pulumi.Context, return configFile, nil } -func (cf *ConfigFile) GetResource(key string) pulumi.Output { +// GetResource returns a resource defined by a built-in Kubernetes group/version/kind, name and namespace. +// For example, GetResource("v1/Pod", "foo", "") would return a Pod called "foo" from the "default" namespace. +func (cf *ConfigFile) GetResource(gvk, name, namespace string) pulumi.Output { + id := name + if len(namespace) > 0 && namespace != "default" { + id = fmt.Sprintf("%s/%s", namespace, name) + } + key := fmt.Sprintf("%s::%s", gvk, id) return cf.Resources.MapIndex(pulumi.String(key)) } diff --git a/sdk/go/kubernetes/yaml/configGroup.go b/sdk/go/kubernetes/yaml/configGroup.go index 2e575ea4d4..e6407875dc 100644 --- a/sdk/go/kubernetes/yaml/configGroup.go +++ b/sdk/go/kubernetes/yaml/configGroup.go @@ -87,6 +87,13 @@ func NewConfigGroup(ctx *pulumi.Context, return configGroup, nil } -func (cf *ConfigGroup) GetResource(key string) pulumi.Output { +// GetResource returns a resource defined by a built-in Kubernetes group/version/kind, name and namespace. +// For example, GetResource("v1/Pod", "foo", "") would return a Pod called "foo" from the "default" namespace. +func (cf *ConfigGroup) GetResource(gvk, name, namespace string) pulumi.Output { + id := name + if len(namespace) > 0 && namespace != "default" { + id = fmt.Sprintf("%s/%s", namespace, name) + } + key := fmt.Sprintf("%s::%s", gvk, id) return cf.Resources.MapIndex(pulumi.String(key)) } diff --git a/sdk/go/kubernetes/yaml/yaml.go b/sdk/go/kubernetes/yaml/yaml.go index 9eab07b50b..2b5685cf2c 100644 --- a/sdk/go/kubernetes/yaml/yaml.go +++ b/sdk/go/kubernetes/yaml/yaml.go @@ -141,8 +141,6 @@ func yamlDecode(ctx *pulumi.Context, text string, opts ...pulumi.ResourceOption) var ret struct { Result []map[string]interface{} `pulumi:"result"` } - // TODO(joe): not clear how to translate ResourceOptions to InvokeOptions (or even get individual - // settings, e.g. opts.Parent). if err := ctx.Invoke("kubernetes:yaml:decode", &args, &ret); err != nil { return nil, err } diff --git a/tests/integration/go/yaml/main.go b/tests/integration/go/yaml/main.go index 3786be78b0..1a9603d616 100644 --- a/tests/integration/go/yaml/main.go +++ b/tests/integration/go/yaml/main.go @@ -25,7 +25,7 @@ func main() { } if resources != nil { - hostIP := resources.GetResource("v1/Pod::foo").Apply(func(r interface{}) (interface{}, error) { + hostIP := resources.GetResource("v1/Pod", "foo", "").Apply(func(r interface{}) (interface{}, error) { pod := r.(*corev1.Pod) return pod.Status.HostIP(), nil })