Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volume filtering works differently and misses existing label #8341

Closed
afbjorklund opened this issue Nov 14, 2020 · 5 comments · Fixed by #8345
Closed

Volume filtering works differently and misses existing label #8341

afbjorklund opened this issue Nov 14, 2020 · 5 comments · Fixed by #8345
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@afbjorklund
Copy link
Contributor

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

Volume filtering works differently in podman, when compared to docker.

Steps to reproduce the issue:

  1. minikube start --driver podman

  2. sudo -n podman volume ls --filter label=name.minikube.sigs.k8s.io=minikube

Describe the results you received:

Describe the results you expected:

DRIVER      VOLUME NAME
local       minikube

Additional information you deem important (e.g. issue happens only occasionally):

The --filter doesn't work with label:

minikube start --driver podman

$ sudo -n podman volume ls --filter label=name.minikube.sigs.k8s.io=minikube
$ sudo -n podman volume ls 
DRIVER      VOLUME NAME
local       minikube
$ sudo -n podman volume inspect minikube
[
     {
          "Name": "minikube",
          "Driver": "local",
          "Mountpoint": "/var/lib/containers/storage/volumes/minikube/_data",
          "CreatedAt": "2020-11-14T15:13:11.855745076+01:00",
          "Labels": {
               "created_by.minikube.sigs.k8s.io": "true",
               "name.minikube.sigs.k8s.io": "minikube"
          },
          "Scope": "local",
          "Options": {
               
          },
          "UID": 0,
          "GID": 0,
          "Anonymous": false
     }
]

It works OK with the docker driver.

minikube start --driver docker

$ docker volume ls --filter label=name.minikube.sigs.k8s.io=minikube
DRIVER              VOLUME NAME
local               minikube
$ docker volume inspect minikube
[
    {
        "CreatedAt": "2020-11-14T15:22:40+01:00",
        "Driver": "local",
        "Labels": {
            "created_by.minikube.sigs.k8s.io": "true",
            "name.minikube.sigs.k8s.io": "minikube"
        },
        "Mountpoint": "/var/lib/docker/volumes/minikube/_data",
        "Name": "minikube",
        "Options": {},
        "Scope": "local"
    }
]

Output of podman version:

Version:      2.1.1
API Version:  2.0.0
Go Version:   go1.15.2
Built:        Thu Jan  1 01:00:00 1970
OS/Arch:      linux/amd64

Output of podman info --debug:

(paste your output here)

Package info (e.g. output of rpm -q podman or apt list podman):

(paste your output here)

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide?

No

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

Ubuntu 20.04

@afbjorklund
Copy link
Contributor Author

There is some bug in the filter construction, that butchers the options.

        for _, f := range cliOpts.Filter {
                filterSplit := strings.Split(f, "=")
                if len(filterSplit) < 2 {
                        return errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
                }
                lsOpts.Filter[filterSplit[0]] = append(lsOpts.Filter[filterSplit[0]], filterSplit[1:]...)
        }

cliOpts.Filter [label=name.minikube.sigs.k8s.io=minikube]
lsOpts.Filter map[label:[name.minikube.sigs.k8s.io minikube]]

The bug is in GenerateVolumeFilters, in the loop construct.

So instead of checking key=value, it checks the key twice instead:

label name.minikube.sigs.k8s.io
label minikube

The filter switch needs to come before the value loop.

        for filter, v := range filters {
                for _, val := range v {
                        switch filter {

Otherwise it won't work for these label=key=value filters ?

map[label:[name.minikube.sigs.k8s.io minikube]]

It looks for a '=' character, but it has already been lost.

                        case "label":
                                filterArray := strings.SplitN(val, "=", 2)

@afbjorklund
Copy link
Contributor Author

I think it was GenerateVolumeFilters that was right, when having multiple filters.

So it was the command line flag parser that was too greedy, splitting every '='

@afbjorklund
Copy link
Contributor Author

afbjorklund commented Nov 14, 2020

It also seems that the logic in Volumes() filtering is broken.

Currently it does an OR of the criteria, instead of an AND...

        if len(filters) == 0 {
                return vols, nil
        }

        volsFiltered := make([]*Volume, 0, len(vols))
        for _, vol := range vols {
                include := false
                for _, filter := range filters {
                        include = include || filter(vol)
                }

                if include {
                        volsFiltered = append(volsFiltered, vol)
                }
        }

        return volsFiltered, nil

So as long as the label matches, it will include every name:

podman volume ls --filter name=foo,label=blue

But that's a different bug than this one, just found while testing...

@Luap99
Copy link
Member

Luap99 commented Nov 14, 2020

So as long as the label matches, it will include every name:

I think this is not a bug and expected. see: #8232

@afbjorklund
Copy link
Contributor Author

afbjorklund commented Nov 14, 2020

Okay, then it was just the example in the docs that was silly (not updated)...

EXAMPLES
              $ podman volume ls

              $ podman volume ls --format json

              $ podman volume ls --format "{{.Driver}} {{.Scope}}"

              $ podman volume ls --filter name=foo,label=blue

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants