https://pulumi.com logo
#golang
Title
# golang
g

green-motorcycle-58080

08/13/2021, 12:30 PM
@mammoth-honey-6147 I've had some success with breaking things out for instance I have a function with the signature
Copy code
func monitoring(ctx *pulumi.Context, k8sProvider *providers.Provider) error {...}
and call it happily within the pulumi.Run func with
Copy code
if err = monitoring(ctx, k8sProvider); err != nil {
	return err
}
m

mammoth-honey-6147

08/13/2021, 12:31 PM
Ooh, interesting. Thanks a lot for this, appreciated
👍 1
within your monitoring function do you run another pulumi.run or just interact with the types directly?
g

green-motorcycle-58080

08/13/2021, 12:34 PM
Interact directly 🙂
m

mammoth-honey-6147

08/13/2021, 12:39 PM
Nice. What do you use the ctx for in that function, output?
g

green-motorcycle-58080

08/13/2021, 12:42 PM
Not sure what you mean by output? As you can see on the function signature, we passed in *pulumi.Context
Do you mean the context here? That's the context from the pulumi.Run func
Copy code
if err = monitoring(ctx, k8sProvider); err != nil {
	return err
}
m

mammoth-honey-6147

08/13/2021, 12:53 PM
yeah, so you pass ctx to your monitoring function, what do you do with it if you're accessing the types directly?
I was assuming you were doing something like ctx.Export
g

green-motorcycle-58080

08/13/2021, 12:54 PM
Maybe I'm misunderstanding what you mean by accessing the types directly? In my monitoring function I have something like
Copy code
ns := pulumi.String("monitoring")
	_, err := corev1.NewNamespace(ctx, "monitoring", &corev1.NamespaceArgs{
		Metadata: &metav1.ObjectMetaArgs{
			Name: ns,
		},
	}, pulumi.Provider(k8sProvider))
	if err != nil {
		return err
	}

	prom, err := helm.NewChart(ctx, "prometheus", helm.ChartArgs{
		Chart: pulumi.Sprintf("prometheus"),
		FetchArgs: helm.FetchArgs{
			Repo: pulumi.Sprintf("<https://prometheus-community.github.io/helm-charts>"),
		},
		Namespace: ns,
	},
		pulumi.Provider(k8sProvider),
	)
	if err != nil {
		return err
	}
I haven't tried exporting anything in a child function, though I think it should work
m

mammoth-honey-6147

08/13/2021, 1:05 PM
Ahh so you're creating the resources in that function, now I understand
I probably need more coffee, my bad. Thank you 🙂
g

green-motorcycle-58080

08/13/2021, 1:22 PM
No worries 😄
I'm planning on open sourcing this project. Sounds like it could be useful to some people as a starting point
m

mammoth-honey-6147

08/13/2021, 1:29 PM
Definitely 👍
3 Views