sparse-intern-71089
01/03/2023, 2:21 PMbillowy-army-68599
Is it possible to share the object as it is?Yes, just export the type. In typescript this would be
export const cluster = k8s.Cluster(...
Is it possible to share my own custom ResourceComponentsYou can easily reshare ComponentResources using whatever abstraction mechanism your chosen language uses
To implement that I need to have multiple stacks?Can you elaborate on this question?
rich-branch-48115
01/03/2023, 2:54 PMResourceComponents
between them do I need to have multiple stacks as well?
I'm trying to avoid calling the same ResourceComponent Type with the same resource name in order to share it.
@billowy-army-68599billowy-army-68599
You mean exporting the object?Yes that works too
cluster = k8s.Cluster
pulumi.export("cluster", cluster)
I meant that if I want to have multiple pulumi programs (let’s say 2) that shares ResourceComponents between them do I need to have multiple stacks as well?Yes, each Pulumi program has
n
stacks. So in this case you’d have perhaps two projects:
• cluster
• app
and each one of those projects would have a stack each, maybe called dev
that shares ResourceComponents between themCan you explain what you mean by “sharing” ? referencing the results of one project from another?
rich-branch-48115
01/03/2023, 4:19 PMcluster = k8s.Cluster(...)
pulumi.export("sharedCluster", cluster)
And app wanted to use the cluster with the following:
cluster_stack = StackReference("dev-cluster")
cluster = cluster_stack.get_output("sharedCluster")
# Using the cluster's k8s_provider in another Resource I'm using in here
billowy-army-68599
rich-branch-48115
01/04/2023, 9:21 AMmyCustomCluster = cluster_stack.get_output("sharedCluster")
def create_vcluster():
# This .cluster is k8s.Cluster object.
cluster = myCustomCluster.cluster
VCluster(..., cluster)
....
AttributeError: 'NoneType' object has no attribute 'cluster'
when I'm accessing k8s_provider
that I also save in the custom object, and it's the actual object I need I'm getting the warning:
Code:
myCustomCluster = cluster_stack.get_output("sharedCluster")
def create_vcluster():
# This .cluster is k8s.Cluster object.
k8s_provider = myCustomCluster.k8s_provider
VCluster(..., k8s_provider)
####### Using the k8s_provider:
class VCluster(pulumi.ResourceComponent):
def __init__(..., k8s_provider):
...
k8s.helm.v3.Release(
vcluster_name,
name=vcluster_name,
chart="vcluster",
namespace=VCLUSTER_NAMESPACE,
values=vcluster_values,
repository_opts=k8s.helm.v3.RepositoryOptsArgs(
repo="<https://charts.loft.sh>",
),
opts=pulumi.ResourceOptions(
parent=self,
providers={
"kubernetes": k8s_provider,
},
),
)
...
Warning:
warning: Provider map key kubernetes disagrees with associated provider Calling __str__ on an Output[T] is not supported.
To get the value of an Output[T] as an Output[str] consider:
1. o.apply(lambda v: f"prefix{v}suffix")
See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of Pulumi.. Key will be ignored.
/home/roy/anaconda3/envs/grip/lib/python3.10/site-packages/pulumi/resource.py:703: UserWarning: Provider map key kubernetes disagrees with associated provider Calling __str__ on an Output[T] is not supported.
To get the value of an Output[T] as an Output[str] consider:
1. o.apply(lambda v: f"prefix{v}suffix")
See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of Pulumi.. Key will be ignored.
warnings.warn(message, UserWarning)
@Userbillowy-army-68599