Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

Docker placement constraints test for blank / any label

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"
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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...