moby / moby

The Moby Project - a collaborative project for the container ecosystem to assemble container-based systems
https://mobyproject.org/
Apache License 2.0
68.72k stars 18.67k forks source link

Filtering nodes doesn't return a result #27231

Open sebgie opened 8 years ago

sebgie commented 8 years ago

Description

Hi, I have started to use 1.12 with it's new features lately. I have a 4 node cluster (1 manager, 3 workers with swarm mode) and try to put workloads on dedicated machines. While doing that I came accross either a bug or something that is missing from documentation?

I have added a label to one of my nodes and then try to execute docker node ls with a filter as described here: https://docs.docker.com/engine/reference/commandline/node_ls/#filtering. Unfortunately I don't get the expected response?

Steps to reproduce the issue:

# docker node update --label-add test dev-swarm-04
dev-swarm-04

# docker node inspect dev-swarm-04
[
    {
        "ID": "7p470z31yf2u27t7wx48og9b0",
        "Version": {
            "Index": 8545
        },
        "CreatedAt": "2016-10-05T13:42:10.303870096Z",
        "UpdatedAt": "2016-10-08T12:15:32.624496559Z",
        "Spec": {
            "Labels": {
                "test": ""
            },
            "Role": "worker",
            "Availability": "active"
        },
        "Description": {
            "Hostname": "dev-swarm-04",
            "Platform": {
                "Architecture": "x86_64",
                "OS": "linux"
            },
            "Resources": {
                "NanoCPUs": 4000000000,
                "MemoryBytes": 8371408896
            },
            "Engine": {
                "EngineVersion": "1.12.1",
                "Plugins": [
                    {
                        "Type": "Network",
                        "Name": "bridge"
                    },
                    {
                        "Type": "Network",
                        "Name": "host"
                    },
                    {
                        "Type": "Network",
                        "Name": "null"
                    },
                    {
                        "Type": "Network",
                        "Name": "overlay"
                    },
                    {
                        "Type": "Volume",
                        "Name": "local"
                    }
                ]
            }
        },
        "Status": {
            "State": "ready"
        }
    }
]

# docker node ls -f label=test
ID  HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS

Describe the results you received: No nodes found.

Describe the results you expected: One node (dev-swarm-04) found.

Additional information you deem important (e.g. issue happens only occasionally): Additonally I couldn't find any documentation how I would use a value with my label.

# docker node ls -f label=test=value? # docker node ls -f label=test:value? # docker node ls -f label.test=value?

Using the label as a constraint to create a service works flawlessly :+1:. Thanks for your help :).

Output of docker version:

Client:
 Version:      1.12.1
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   23cf638
 Built:        Thu Aug 18 05:33:38 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.1
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   23cf638
 Built:        Thu Aug 18 05:33:38 2016
 OS/Arch:      linux/amd64

Output of docker info:

Containers: 16
 Running: 3
 Paused: 0
 Stopped: 13
Images: 204
Server Version: 1.12.1
Storage Driver: devicemapper
 Pool Name: docker-253:1-916657-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 10.74 GB
 Backing Filesystem: xfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 11.68 GB
 Data Space Total: 107.4 GB
 Data Space Available: 69.87 GB
 Metadata Space Used: 19.42 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.128 GB
 Thin Pool Minimum Free Space: 10.74 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Deferred Deletion Enabled: false
 Deferred Deleted Device Count: 0
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.110 (2015-10-30)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: overlay bridge host null
Swarm: active
 NodeID: 5uzh00gzxmquexfcmurnq6ypm
 Is Manager: true
 ClusterID: 7vryc5c1s75o0jkttokhyo6dc
 Managers: 1
 Nodes: 4
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
 Node Address: 10.133.13.82
Runtimes: runc
Default Runtime: runc
Security Options: apparmor seccomp
Kernel Version: 4.4.0-36-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 31.42 GiB
Name: dev-swarm-01
ID: 3FQW:TNXG:PUD2:FW4B:FU4Y:YS6E:NYCR:RGET:6SKY:LCOF:FW2G:UOE6
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: sebgieghost
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Insecure Registries:
 127.0.0.0/8

Additional environment details (AWS, VirtualBox, physical, etc.): Ubuntu 16.04

aluzzardi commented 8 years ago

Hey @sebgie,

The confusion comes from the fact that we have two set of labels:

Label filtering in docker node ls is looking at engine labels rather than node labels.

We should probably revert to node label filtering rather than engine filtering

/cc @aaronlehmann @dperny @nishanttotla

allencloud commented 8 years ago

Hi, @aluzzardi I think currently the way how docker deals the label is very important for users. I put forward a PR https://github.com/docker/docker/pull/28192 to include more description on docker node ls -f "label=a"

ghost commented 7 years ago

Any update on this? This ticket is labeled with the 1.13.0 milestone, but that has already gone out.

allencloud commented 7 years ago

Yeah, as @aluzzardi mentioned. Currently swarmkit still takes engine labels as node filtering. I think we should support both. Open a pr https://github.com/docker/swarmkit/pull/2062 to make it. PTAL

cirocosta commented 7 years ago

I was really feeling that I was crazy given that I couldn't get the list filtered haha. Nice to know about this issue and that there's already a PR that solves it.

In the mean time, I'm counting the number of nodes with a given label like this:

 docker node ls
ID                           HOSTNAME                                     STATUS  AVAILABILITY  MANAGER STATUS
88bd4sz9irxh1f5cylfeeft1c    ip-172-31-25-51.us-west-2.compute.internal   Ready   Active        
aa7c1vcg9a13hbdmjizyrcr9s    ip-172-31-13-77.us-west-2.compute.internal   Ready   Active        
e4rzm599p27hzrtrcaahpi1dd    ip-172-31-25-8.us-west-2.compute.internal    Ready   Active        
guc2m14qt53y9z769p6zlgh6k    ip-172-31-41-228.us-west-2.compute.internal  Ready   Active        
ibl03o334qrdmk7r0liwuyhhm    ip-172-31-44-53.us-west-2.compute.internal   Ready   Active        
motlc6ulkijxk1cnlk7x13bdr *  ip-172-31-35-137.us-west-2.compute.internal  Ready   Active        Leader

~ $ docker node update --label-add type=infra 88bd4sz9irxh1f5cylfeeft1c
88bd4sz9irxh1f5cylfeeft1c
~ $ docker node update --label-add type=test e4rzm599p27hzrtrcaahpi1dd
e4rzm599p27hzrtrcaahpi1dd

~ $ nodes=$(for node in $(docker node ls -q); do docker node inspect $node; done)
~ $ echo $nodes | jq '.[] | .Spec.Labels | select(has("type")) | .type'
"infra"
"test"

(github says that I unassigned @nishanttotla (????))

IvanBoyko commented 6 years ago

Still not implemented?

TheSchemm commented 6 years ago

Funny that I just came across your comment @IvanBoyko, I am trying to set up a multiplatform infrastructure and I was wondering why my node labels weren't working! It would have been nice to know!

Stephan-Walter commented 5 years ago

The issue is still present and quite annoying, since it is not mentioned within the documentation. So it would be really great to at least update the official documentation. This is problem is more than two years old...

olljanat commented 5 years ago

Current status looks to be that @allencloud have created PR docker/swarmkit#2062 about 1,5 years ago but it was not ever updated based on review so it was not merged and based on https://github.com/docker/swarmkit/pull/2062#issuecomment-302851163 it looks to be that he will not continue that work.

So it would be best that someone else who have need for this one will continue that work. I have couple of other PRs which with I'm working on so I cannot look this on near future and we actually don't have big need for this as our server provisioning sets engine labels for all servers by default. If you need help you can contact me on Slack.

@Stephan-Walter you can create PR which updates documentation https://github.com/docker/docker.github.io / https://github.com/docker/cli (I have not time to investigate now which one those documents currently exists).

ohperhaps commented 4 years ago

Any update?

custom20s commented 3 years ago

Every developer goes for Kubernetes. That's how we get this 4 years old issue.

olljanat commented 3 years ago

@custom20s honestly if you really need this feature then you should implement it. On nowadays DevOps world coding skill is coming more and more critical for Ops too and those are not able to do coding will be left behind.

Golang is quite simple to learn and I can help you getting started on Slack.

thaJeztah commented 3 years ago

Looks like this was implemented in https://github.com/moby/moby/pull/37650, but the documentation was not updated to mention the node.label filter;

$ docker node update --label-add test swarm-test-04
swarm-test-04

$ docker node update --label-add test2 swarm-test-02
swarm-test-02

$ docker node ls --filter node.label=test
ID                            HOSTNAME        STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
n41b2cijmhifxxvz56vwrs12q     swarm-test-04   Ready     Active                          20.10.0

$ docker node ls --filter node.label=test2
ID                            HOSTNAME        STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
2lm9w9kbepgvkzkkeyku40e65     swarm-test-02   Ready     Active         Reachable        20.10.0
thaJeztah commented 3 years ago

opened https://github.com/docker/cli/pull/2951 to update docs and completion scripts