hey peeps... I can't find this in a search (here ...
# kubernetes
a
hey peeps... I can't find this in a search (here or on the web) with an answer to my problem. I have 2 pulumi applications that run and install a business app into kubernetes. Both of these apps go into the same k8s namespace. I would like to be able to run either app first, have it create the namespace, and the other will be able to find it and use it.
Copy code
var namespace = new k8s.core.v1.Namespace(defaultNamespaceName, {
    metadata: {
        name: defaultNamespaceName,
    }
}, { provider: config.k8sProvider, import: "releasesplatform" });
This does not work. Possibly I have the import id incorrect?
Copy code
var namespace = new k8s.core.v1.Namespace(defaultNamespaceName, {
    metadata: {
        name: defaultNamespaceName,
    }
}, { provider: config.k8sProvider, id: "releasesplatform" });
Does not work. again, perhaps an Id problem?
Copy code
var namespace = k8s.core.v1.Namespace.get(defaultNamespaceName, defaultNamespace);
if (namespace == null) {
   // create namespace
}
Doesn't seem to work to get the existing resource either. My code always tries to create. I'm not sure what
get
returns if nothing exists though. Intellisense says it should be a
namespace
typed object, but might be a promise which would not be null. Anyway, wondering if anyone else has solved this problem of creating a k8s namespace in one app, and trying to find it in another.
b
hey, I'm assuming here you're using the word "app" to reference a Pulumi app? I would use a stack reference here. You don't want to use an import statement because then you'll have two pulumi apps managing the same namespace. https://www.pulumi.com/docs/intro/concepts/organizing-stacks-projects/#inter-stack-dependencies
a
Thanks @billowy-army-68599 for the reply! I could use a stack reference, but that would require "something" to run first, to create the reference in the first place. What I'm probably trying to do is not aligned with the "pulumi" approach because you wouldn't know deterministically what stack a resource (in this example, a k8s namespace) was created in.
We do create our core infra (cluster) in one stack and deploy apps into the cluster in other stacks, which all depend on the cluster stack and the kube config created in it.
b
my personal suggestion is to put the NS creation into a third distinct stack and always run that first, but that maybe not what you want
a
I was expecting that I would have to do that. Then we know deterministically where the ns was created. I just was hoping more for an idempotent operation that just makes sure the ns exists, regardless of where it was created.