https://pulumi.com logo
#kubernetes
Title
# kubernetes
f

famous-bear-66383

03/30/2020, 8:29 AM
Hello community ! Quick question: I’d like to add labels to
default namespace
eg. istio injection label. How can I do that ?
g

gorgeous-egg-16927

03/30/2020, 7:13 PM
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

famous-bear-66383

06/04/2020, 3:48 PM
@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

gorgeous-egg-16927

06/04/2020, 3:56 PM
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

famous-bear-66383

06/04/2020, 4:31 PM
That works !
how do I apply the label to the imported resource ?
g

gorgeous-egg-16927

06/04/2020, 5:13 PM
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

famous-bear-66383

06/05/2020, 8:07 AM
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

gorgeous-egg-16927

06/05/2020, 3:25 PM
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

famous-bear-66383

06/05/2020, 7:42 PM
Thanks for the clarifications : )
👍 1
4 Views