This message was deleted.
# general
s
This message was deleted.
s
Try this, it’s some code I got from @billowy-army-68599 to do exactly what you’re describing. I haven’t tested it, but it should work. I believe it’s intended to be used with our EKS component:
Copy code
// Save a kube provider for later use
kubeconfig := cluster.Kubeconfig.ApplyT(func(k interface{}) (string, error) {
	data, err := json.Marshal(k)
	if err != nil {
		return "", fmt.Errorf("kubeconfig is not a string")
	}
	return string(data), nil
}).(pulumi.StringOutput)

kubeProvider, err := kubernetes.NewProvider(ctx, awsCluster.Name, &kubernetes.ProviderArgs{
	Kubeconfig: kubeconfig,
})
h
That’s really helpful, thanks! One question though, where is
awsCluster
coming from? I see you reference
cluster
and
awsCluster
. Are they are the same cluster object being created with
newCluster
?
s
Yeah, that’s probably a bug. 🐛 AIUI, you should be referencing the same cluster object in both places.
h
Oh it may not matter since
awsCluster.Name
is just the provider name. I can hard code that to a string. Thanks!
This may be diving a bit deep into the weeds, but when I create k8s resources with the passed provider, why can’t I pass
nil
when I’m using my local (minikube) setup?
Example:
Copy code
_, err = corev1.NewNamespace(ctx, namespace, &corev1.NamespaceArgs{
		Metadata: &metav1.ObjectMetaArgs{
			Name: pulumi.String("dev"),
		},
	}, pulumi.Provider(provider))
“panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x16c4b00]”
go seems to think this is a perfectly legal statement, but maybe the library isn’t checking for nil?
s
That sounds like a bug, please file an issue (if you don’t mind)
👍 1