This message was deleted.
# general
s
This message was deleted.
b
Is it possible to share the object as it is?
Yes, just export the type. In typescript this would be
Copy code
export const cluster = k8s.Cluster(...
Is it possible to share my own custom ResourceComponents
You 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?
r
What do you mean by exporting the type? You mean exporting the object? (I'm using python but it does not really matter) When you say "reshare" Do you mean like calling the same type (my custom ResourceComponent type) with the same resource name and then just get it? Regarding the multiple stacks, I'm not sure that I have understood pulumi's architecture fully. 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? I'm trying to avoid calling the same ResourceComponent Type with the same resource name in order to share it. @billowy-army-68599
b
You mean exporting the object?
Yes that works too
Copy code
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 them
Can you explain what you mean by “sharing” ? referencing the results of one project from another?
r
@billowy-army-68599 My meaning of "Sharing" is exactly what you've said. If cluster project is doing the following:
Copy code
cluster = k8s.Cluster(...)
pulumi.export("sharedCluster", cluster)
And app wanted to use the cluster with the following:
Copy code
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
b
Yea that’s a very common pattern, are you having issues with it?
r
The things is that I'm getting an error when trying to access:
Copy code
myCustomCluster = cluster_stack.get_output("sharedCluster")

def create_vcluster():
    # This .cluster is k8s.Cluster object.
    cluster = myCustomCluster.cluster
    VCluster(..., cluster)
Copy code
....
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:
Copy 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:
Copy code
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)
@User
b
instead of exporting the entire cluster object, if you only need the provider, just export that. That’ll simplify things a lot.