Home > database >  how to add annotations to kubernetes node using patch_file
how to add annotations to kubernetes node using patch_file

Time:08-16

I want to start learning to deploy longhorn to my exixting on-perm kubernetes

As in https://longhorn.io/docs/1.3.1/advanced-resources/default-disk-and-node-config/#launch-longhorn-with-multiple-disks , I need to add some annotations to the node

I try to use 'merge' as stated in https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment

Here is my patch file (lhpatch.yaml)

metadata:
  annotations:
    node.longhorn.io:
      default-disks-config:
      - path: /mnt/lh01
        allowSheduling: true
      - path: /mnt/lh02
        allowSheduling: true

Apply it:

kubectl patch node k8s-worker-1 --type merge --patch-file /home/bino/k0s-sriwijaya/longhorn/lhpatch.yaml

But I got error (at the last line of results):

json: cannot unmarshal object into Go struct field ObjectMeta.metadata.annotations of type string

Kindly please tell me how to fix my lhpatch.yaml

Sincerely

-bino-

CodePudding user response:

You should use:

metadata:
  annotations:
    node.longhorn.io:
      default-disks-config:
      - path: /mnt/lh01
        allowSheduling: 'true'
      - path: /mnt/lh02
        allowSheduling: 'true'

Since in annotations you can't refer to boolean types, and instead you should pass with string: string.

CodePudding user response:

my fault.

annotation only accept 'string'. My yaml have array in it.

So I think the right yaml is:

metadata:
  annotations:
    node.longhorn.io/default-disks-config: '[{"name": "lh01", "path": "/mnt/lh01", "allowScheduling": true}, {"name": "lh02", "path": "/mnt/lh02", "allowScheduling": true}]'

  • Related