Docker placement constraints test for blank / any label

Viewed 238

It is legal, and documented syntax, to add a label to a docker node:

docker node update node_x --label-add "label"

and this will add a label that when queried, will show as an empty string:

$ docker node inspect docker-desktop --format '{{json .Spec.Labels}}'
{"label":""}

But, there is seemingly no valid way to make a placement constraint that can be satisfied by this label.

A different take on the problem is the need to check that a label is some value that is not blank.

For example I might want to give two nodes a label:

docker node update node_x --label-add "fruit=apple"
docker node update node_y --label-add "fruit=orange"

But, my attempts to check, as a placement constraint, for the existence of a blank label, fail. And, likewise, while I can check that a node is, (or is not) a specific fruit, I can't successfully test that it is [any] fruit.

version: "3.9"
services:
  test:
    image: alpine
    deploy:
      placement:
        constraints:
        - node.labels.label # == or != expected
        - node.labels.label=="" # "" unexpected / '' unexpected.
        - node.labels.fruit!="" # "" unexpected / '' unexpected.

So, have I missed something? Is there some way to check if a label is set, without checking for a specific value. And is there any way to check for labels that are set, but to a blank value?

0 Answers
Related