Hello community ! Quick question: I’d like to add...
# kubernetes
f
Hello community ! Quick question: I’d like to add labels to
default namespace
eg. istio injection label. How can I do that ?
g
You can import the Namespace into a Pulumi stack and then make updates to it. See https://www.pulumi.com/blog/adopting-existing-cloud-resources-into-pulumi/#adopting-existing-resources for details. Import:
Copy code
const ns = new k8s.core.v1.Namespace("default", { metadata: { name: "default" }}, {
    import: "default",
})
Update:
Copy code
const ns = new k8s.core.v1.Namespace("default", { metadata: { name: "default", annotations: {foo: "bar"} }})
👍 1
Copy code
$ kubectl get ns default -o yaml
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    foo: bar
    <http://kubectl.kubernetes.io/last-applied-configuration|kubectl.kubernetes.io/last-applied-configuration>: |
      {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{"foo":"bar"},"name":"default"}}
  creationTimestamp: "2020-03-03T22:32:04Z"
  name: default
  resourceVersion: "702728"
  selfLink: /api/v1/namespaces/default
  uid: 34ac29f3-7eb1-4f48-b7a0-504f41cf02a2
spec:
  finalizers:
  - kubernetes
status:
  phase: Active
f
@gorgeous-egg-16927 I tried what you suggested above.
Copy code
const defaultns = new k8s.core.v1.Namespace("default", {
    metadata: { 
        name: "default", 
        labels: { 
            "istio-injection":"enabled" } 
        }
}, {provider: k8sProvider, import: "default"});
but am getting error
Copy code
kubernetes:core:Namespace (default):
    warning: inputs to import do not match the existing resource; importing this resource will fail
"default"
is the ID needed to import the default namespace from k8s right ? or how can I get the ID. Thanks 🙏
g
The resource definition has to match what’s already there on import. After it’s imported, you can change it (add labels, etc). Guessing the error is due to the
istio-injection
label
✔️ 1
f
That works !
how do I apply the label to the imported resource ?
g
Once you import the resource, Pulumi takes ownership of it, so any changes you make in the program definition are applied on update. (i.e., add the labels to the resource definition and run an update)
f
I got it. So this needs to be done on 2 steps.
1. import the namespace 2. add label and run
pulumi up
👍 1
is there a way to do it in one step ?
g
Not currently. https://github.com/pulumi/pulumi-kubernetes/issues/264 is related, and we’re thinking about how to better support this type of scenario in the future.
f
Thanks for the clarifications : )
👍 1