Hi, I am trying to create a Kubernetes namespace i...
# getting-started
c
Hi, I am trying to create a Kubernetes namespace in Python code but can't seem to find a way to get pulumi to actually use the namespace name I would like rather then the generated name. This is important as the namespace must be exactly "snyk-monitor" and not "snyk-monitor-randomdata". My code is as follows how can I change this so that the K8s namepsace created in the cluster is actually "snyk-monitor" itself
Copy code
monitor_namespace = Namespace (resource_name='snyk-monitor')
p
you have to place that under
metadata
(gimme me a sec)
c
Yeah are you able to provide an example as I can see that in the docs but can't figure out the syntax. I am not a python developer unfortunately
p
Copy code
import pulumi_kubernetes as pulumi_k8s

monitor_namespace = pulumi_k8s.core.v1.Namespace(
  "snyk-monitor",
  metadata=pulumi_k8s.meta.v1.ObjectMetaArgs(
    name="snyk-monitor",
  ),
)
you can put simple dict instead of
pulumi_k8s.meta.v1.ObjectMetaArgs
but I like my things “strongly typed” wherever possible 🙂
Copy code
monitor_namespace = pulumi_k8s.core.v1.Namespace(
  "snyk-monitor",
  metadata={
    "name": "snyk-monitor",
  },
)
If you wonder why I don’t have
resource_name
as in your example, that’s because it’s the first argument in all pulumi resources so you can pass it as positional argument (first one) or as key-value as you did.
👍 1
c
Yep I just had the syntax wrong. Thanks so much @prehistoric-activity-61023 it's clear now it will work for me
Copy code
+ pulumi:pulumi:Stack: (create)
    [urn=urn:pulumi:dev::gcp-K8s-integration-demo::pulumi:pulumi:Stack::gcp-K8s-integration-demo-dev]
    + kubernetes:core/v1:Namespace: (create)
        [urn=urn:pulumi:dev::gcp-K8s-integration-demo::kubernetes:core/v1:Namespace::snyk-monitor]
        [provider=urn:pulumi:dev::gcp-K8s-integration-demo::pulumi:providers:kubernetes::default_3_13_0::04da6b54-80e4-46f7-96ec-b56ff0331ba9]
        apiVersion: "v1"
        kind      : "Namespace"
        metadata  : {
            labels: {
                <http://app.kubernetes.io/managed-by|app.kubernetes.io/managed-by>: "pulumi"
            }
            name  : "snyk-monitor"
        }
🙌 1