https://pulumi.com logo
#getting-started
Title
# getting-started
s

straight-painter-33893

01/12/2022, 2:23 PM
Hi Everyone, I hope this is the right channel to ask this question, please let me know if it is off topic. I need to create a package with a set of components that bundles the installation of multiple helm charts and k8s manifests. Right now, following the getting-started guide, I have a package with one component installing 2 helm charts and 1 k8s manifest. I generated the SDKs and I have an example using the go SDK, but I whenever I
pulumi up
it, it fails at the stage when my component is invoked. The error I get is
Copy code
+   └─ pulumi:providers:kubernetes  k8sprovider  create     
 
Diagnostics:
  pulumi:pulumi:Stack (grafana-dev):
    error: an unhandled error occurred: program exited with non-zero exit code: 1
 
    panic: reflect: NumField of non-struct type pulumi.Output
    +   └─ pulumi:providers:kubernetes  k8sprovider  create     
goroutine 15 [running]:
    reflect.(*rtype).NumFiel 
d(0x18437a0, 0x1b70560)
    	/usr/lib/golang/src/reflectDiagnostics:
/type.go:976 +0xb7
    <http://github.com|github.com>  pulumi:pulumi:Stack (grafana-dev):
/pulumi/pulumi/sdk/v3/go/pulumi.newOutput(0xc00062a118, 0x1ddd120, 0x18437a0, 0    error: an unhandled error occurred: program exited with non-zero exit code: 1
xc00053c200, 0x1, 0x1, 0x1ddd101, 0x18437a0) 

    	/var/home/patriziobruno/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/types.go:288 +0xfb
    <http://github.com/pulumi/pulumi/sdk/|github.com/pulumi/pulumi/sdk/>    panic: reflect: NumField of non-struct type pulumi.Output
v3/go/pulumi.(*Context).newOutput(...)
    	/var/hom    goroutine 15 [running]:
e/patriziobruno/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.    reflect.(*rtype).NumField(0x18437a0, 0x1b70560)
1/go/pulumi/context.go:1    	/usr/lib/golang/src/reflect/type.go:976 +0xb7
499
    <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>    <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.newOutput(0xc00062a118|github.com/pulumi/pulumi/sdk/v3/go/pulumi.newOutput(0xc00062a118>, 0x1ddd120, 0x18437a0, 0xc00053c200, 0x1, 0x1, 0x1ddd101, 0x18437a0)
.(*Context).makeResourceState(0xc00062a000, 0x1ba2fd0, 0x1f, 0xc0003ee433, 0xd, 0x1dd1370, 0xc000634000, 0xc0003442d0, 0x0, 0x0, ...)
    	/var/home/patriziobruno/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/context.go:1057 +0x728
    <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).registerResource(0xc00062a000|github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).registerResource(0xc00062a000>, 0x1ba2fd0, 0x1f, 0xc0003ee433, 0xd, 0x0, 0x0, 0x1dd1370, 0xc000634000, 0x0, ...)
    	/var/home/patriziobruno/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/context.go:776 +0x585
      	/var/home/xxxxx/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/types.go:288 +0xfb
  <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).RegisterResource(...)|github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).RegisterResource(...)>
    <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).newOutput(...)|github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).newOutput(...)>
    	/var/home/patriziobruno/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/context.go:669
       	/var/home/xxxxx/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/context.go:1499
 <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).Reg|github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).Reg>    <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).makeResourceState|github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).makeResourceState>(0xc00062a000, 0x1ba2fd0, 0x1f, 0xc0003ee433, 0xd, 0x1dd1370, 0xc000634000, 0xc0003442d0, 0x0, 0x0, ...)
isterComponentResource(...)
    	/var/home/patriziobruno/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/context.go:859
    	/var/home/xxxxx/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/context.go:1057 +0x728
    <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).registerResource(0xc00062a000|github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).registerResource(0xc00062a000>, 0x1ba2fd0, 0x1f, 0xc0003ee433, 0xd, 0x0, 0x0, 0x1dd1370, 0xc000634000, 0x0, ...)
    	/var/home/xxxxx/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/context.go:776 +0x585
    <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).RegisterResource(...)|github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).RegisterResource(...)>
    	/var/home/xxxxx/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/context.go:669
    <http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).RegisterComponentResource(...)|github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).RegisterComponentResource(...)>
    	/var/home/xxxxx/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.21.1/go/pulumi/context.go:859
    
    error: program failed: waiting for RPCs: rpc error: code = Unavailable desc = transport is closing
    exit status 1
b

billowy-army-68599

01/12/2022, 3:07 PM
lease share your code
s

straight-painter-33893

01/12/2022, 3:32 PM
This is the component, the rest of the code is as the template at https://github.com/pulumi/pulumi-component-provider-go-boilerplate
Copy code
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     <http://www.apache.org/licenses/LICENSE-2.0>
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package provider

import (
	helmv3 "<http://github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/helm/v3|github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/helm/v3>"
	"<http://github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml|github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

// GrafanaAgentArgs : The set of arguments for creating a GrafanaAgent component resource.
type GrafanaAgentArgs struct {
	// Namespace for the agent deployment
	Namespace pulumi.StringInput `pulumi:"namespace"`
	Name      pulumi.StringInput `pulumi:"name"`
}

// The GrafanaAgent component resource.
type GrafanaAgent struct {
	pulumi.ResourceState

	Agent       pulumi.Output
	Operator    pulumi.Output
	BaseMetrics pulumi.Output
}

// NewGrafanaAgent creates a new GrafanaAgent component resource.
func NewGrafanaAgent(ctx *pulumi.Context,
	name string, args *GrafanaAgentArgs, opts ...pulumi.ResourceOption) (*GrafanaAgent, error) {
	if args == nil {
		args = &GrafanaAgentArgs{Namespace: pulumi.String("default")}
	} else {
		if ns, ok := args.Namespace.(pulumi.String); ok {
			if len(ns) == 0 {
				args.Namespace = pulumi.String("default")
			}
		}
	}

	ctx.Log.Debug("register component", &pulumi.LogArgs{})
	component := &GrafanaAgent{}
	err := ctx.RegisterComponentResource("observers:index:GrafanaAgent", name, component, opts...)
	if err != nil {
		return nil, err
	}

	operator, err := helmv3.NewChart(ctx, "grafana-agent-operator", helmv3.ChartArgs{
		Repo:      pulumi.String("grafana"),
		Chart:     pulumi.String("grafana-agent-operator"),
		Namespace: args.Namespace,
		FetchArgs: helmv3.FetchArgs{
			Repo: pulumi.String("<https://grafana.github.io/helm-charts>"),
		},
	}, append([]pulumi.ResourceOption{pulumi.Parent(component)}, opts...)...)
	if err != nil {
		return nil, err
	}

	agent, err := yaml.NewConfigFile(ctx, "grafana-agent", &yaml.ConfigFileArgs{
		File: "guestbook-all-in-one.yaml",
		Transformations: []yaml.Transformation{
			func(state map[string]interface{}, opts ...pulumi.ResourceOption) {
				state["spec"].(map[string]interface{})["prometheus"].(map[string]interface{})["externalLabels"].(map[string]interface{})["cloud_project"] = args.Name
			},
		},
	}, append([]pulumi.ResourceOption{pulumi.Parent(component), pulumi.DependsOn([]pulumi.Resource{operator})}, opts...)...)
	if err != nil {
		return nil, err
	}

	baseMetrics, err := helmv3.NewChart(ctx, "kube-state-metrics", helmv3.ChartArgs{
		Repo:      pulumi.String("prometheus-community"),
		Chart:     pulumi.String("kube-state-metrics"),
		Namespace: args.Namespace,
		FetchArgs: helmv3.FetchArgs{
			Repo: pulumi.String("<https://prometheus-community.github.io/helm-charts>"),
		},
	}, append([]pulumi.ResourceOption{pulumi.Parent(component), pulumi.DependsOn([]pulumi.Resource{operator})}, opts...)...)
	if err != nil {
		return nil, err
	}

	ctx.Log.Debug("get operator resource", &pulumi.LogArgs{})
	operatorResource := args.Namespace.ToStringOutput().ApplyT(func(ns string) pulumi.Output {
		return operator.GetResource("apps/v1/Deployment", "grafana-agent-operator", ns)
	})
	ctx.Log.Debug("get agent resource", &pulumi.LogArgs{})
	agentResource := args.Namespace.ToStringOutput().ApplyT(func(ns string) pulumi.Resource {
		return agent.GetResource("<http://monitoring.grafana.com/v1alpha1/GrafanaAgent|monitoring.grafana.com/v1alpha1/GrafanaAgent>", "grafana-agent", ns)
	})
	ctx.Log.Debug("get base metrics resource", &pulumi.LogArgs{})
	baseMetricsResource := args.Namespace.ToStringOutput().ApplyT(func(ns string) pulumi.Output {
		return baseMetrics.GetResource("<http://monitoring.coreos.com/v1/ServiceMonitor|monitoring.coreos.com/v1/ServiceMonitor>", "kube-state-metrics", ns)
	})
	ctx.Log.Debug("got all resources", &pulumi.LogArgs{})

	component.Agent = agentResource
	component.Operator = operatorResource
	component.BaseMetrics = baseMetricsResource
	ctx.Log.Debug("before registering output", &pulumi.LogArgs{})
	if err := ctx.RegisterResourceOutputs(component, pulumi.Map{
		"agent":       agentResource,
		"operator":    operatorResource,
		"baseMetrics": baseMetricsResource,
	}); err != nil {
		return nil, err
	}
	ctx.Log.Debug("after registering output", &pulumi.LogArgs{})

	return component, nil
}
b

billowy-army-68599

01/12/2022, 3:39 PM
Ah I see, it's hard to tell from here, but these types don't look correct to me:
Copy code
Agent       pulumi.Output
	Operator    pulumi.Output
	BaseMetrics pulumi.Output
s

straight-painter-33893

01/12/2022, 3:49 PM
I tried removing all of them
and still got the same error
none of the debug messages are ever printed
@billowy-army-68599 thanks for your support, I've found the problem. It was my mistake, I was updating the provider, but not publishing it, so I kept testing with the same version having all of those abstract output properties
and you're right it's the abstract properties the problem
b

billowy-army-68599

01/12/2022, 4:49 PM
awesome! if you need help getting this into the reigstry when it's done, let me know!
1
s

straight-painter-33893

01/24/2022, 10:50 AM
Hi @billowy-army-68599, I'd love to have this into "a" registry, I'm not sure it'd be ok for my company to put it in a public one. Is there a way to distribute the package/provider using a private registry?
7 Views