3

I can add labels to a pod as described here

But no luck to create annotations likewise

 $ KUBE_TOKEN=$(</var/run/secrets/kubernetes.io/serviceaccount/token) 

 $ cat > patch.json <<EOF
        ]
         {
         "op": "add", "path": "/metadata/annotations/test", "value": "world"
         }
        ]
        EOF

$  curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" --request PATCH --data "$(cat patch.json)" -H "Content-Type:application/json-patch+json" https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/$POD_NAMESPACE/pods/$POD_NAME

the response is:

    {
      "kind": "Status",
      "apiVersion": "v1",
      "metadata": {

      },
      "status": "Failure",
      "message": "jsonpatch add operation does not apply: doc is missing path: /metadata/annotations/test",
      "code": 500
    }
mosquitos
  • 53
  • 8

2 Answers2

-1

The error is related to non-existing path.

    [
     {
     "op": "add", "path": "/metadata/annotations/", "value": { "test" : "world" }
     }
    ]

Check out https://www.rfc-editor.org/rfc/rfc6902#section-4.1

Community
  • 1
  • 1
-2

AFAIR, you cannot add new annotations on existing resources. You can only update existing ones.

iocanel
  • 570
  • 2
  • 2